TRƯỜNG ĐẠI HỌC CẦN THƠ TRƯỜNG BÁCH KHOA BÁO CÁO ĐỒ ÁN KỸ THUẬT VI XỬ LÝ ĐỀ TÀI : XXXXX GIẢNG VIÊN HƯỚNG DẪN: SINH VIÊN THỰC HIỆN: Cần Thơ, ngày xx tháng xx Năm 2023 3.1 Sơ đồ khối: Lựa chọn linh kiện : Bộ xử lí trung tâm: MSP430G2553 (3.3V) LCD 16x2 Cảm biến nhiệt độ ngõ analog LM35 (5V) Module cảm biến khí gas ngõ digital MQ2 (5V) Biến trở 10kΩ Led đơn Điện trở: 220Ω, 4,7kΩ Nút nhấn 3.2 Sơ đồ nguyên lí: 3.3 Lưu đồ thuật toán: 3.4 Code chương trình: #include "msp430g2553.h" #include "intrinsics.h" #include "string.h" #include "stdio.h" #include "UART.h" // -union reg { struct bit { unsigned char b0:1; unsigned char b1:1; unsigned char b2:1; unsigned char b3:1; unsigned char b4:1; unsigned char b5:1; unsigned char b6:1; unsigned char b7:1; }_BIT; unsigned char _BYTE; }; union reg* P2_DIR=(union reg*)0x2a; //khai bao dia chi o nho union reg* P2_OUT=(union reg*)0x29; union reg* P2_SEL=(union reg*)0x2e; union reg* P2_IN=(union reg*)0x28; union reg* P1_SEL=(union reg*)0x26; union reg* P1_DIR=(union reg*)0x22; //khai bao dia chi o nho union reg* P1_OUT=(union reg*)0x21; union reg* P1_IN=(union reg*)0x20; // =========================================================== =========================================================== // =========================================================== =================== //DINH NGHIA LCD: #define MCLK_F // frequency of Master Clock in MHz / ****************************************************************** ********** * HARD DEFINITIONS ****************************************************************** ************/ /* Display ON/OFF Control definitions */ #define DON 0x0F /* Display on */ #define DOFF 0x0B /* Display off */ #define CURSOR_ON 0x0F /* Cursor on */ #define CURSOR_OFF 0x0D /* Cursor off */ #define BLINK_ON 0x0F /* Cursor Blink */ #define BLINK_OFF 0x0E /* Cursor No Blink */ /* Cursor or Display Shift definitions */ #define SHIFT_CUR_LEFT 0x04 /* Cursor shifts to the left */ #define SHIFT_CUR_RIGHT 0x05 /* Cursor shifts to the right */ #define SHIFT_DISP_LEFT 0x06 /* Display shifts to the left */ #define SHIFT_DISP_RIGHT 0x07 /* Display shifts to the right */ /* Function Set definitions */ #define FOUR_BIT 0x2C /* 4-bit Interface */ #define EIGHT_BIT 0x3C /* 8-bit Interface */ #define LINE_5X7 0x30 /* 5x7 characters, single line */ #define LINE_5X10 0x34 /* 5x10 characters */ #define LINES_5X7 0x38 /* 5x7 characters, multiple line */ // =========================================================== === // Your YM1602C 16x2 must be supplied with a voltage between 4.5V-5.5V // However, signal pins can understand 3.3V logic level from MSP430 as '1' // Check your hardware connecting and map it to these definitions below // Map: LCD PIN Output_Port _ out/dir -> Output_Pin #define LCD_RS P2_OUT -> _BIT.b0 #define LCD_RS_DIR P2_DIR -> _BIT.b0 #define LCD_EN P2_OUT -> _BIT.b1 #define LCD_EN_DIR P2_DIR -> _BIT.b1 // This driver just help you to "write" LCD, not to read LCD "status" // So that, you must pull your pin LCD_RW to GND (0V) #define LCD_DATA_4 P2_OUT -> _BIT.b2 #define LCD_DATA_4_DIR P2_DIR -> _BIT.b2 #define LCD_DATA_5 P2_OUT -> _BIT.b3 #define LCD_DATA_5_DIR P2_DIR -> _BIT.b3 #define LCD_DATA_6 P2_OUT -> _BIT.b4 #define LCD_DATA_6_DIR P2_DIR -> _BIT.b4 #define LCD_DATA_7 P2_OUT -> _BIT.b5 #define LCD_DATA_7_DIR P2_DIR-> _BIT.b5 //==================================================== /*or another PINS MAPPING TABLE: #define LCD_RS P2_out -> _bit.b1 #define LCD_RS_DIR P2_dir -> _bit.b1 #define LCD_EN P2_out -> _bit.b2 #define LCD_EN_DIR P2_dir -> _bit.b2 #define LCD_DATA_4 P2_out -> _bit.b4 #define LCD_DATA_4_DIR P2_dir -> _bit.b4 #define LCD_DATA_5 P2_out -> _bit.b5 #define LCD_DATA_5_DIR P2_dir -> _bit.b5 #define LCD_DATA_6 P1_out -> _bit.b6 #define LCD_DATA_6_DIR P1_dir -> _bit.b6 #define LCD_DATA_7 P1_out -> _bit.b7 #define LCD_DATA_7_DIR P1_dir -> _bit.b7 */ /****************************************************************** ********** * MODULE PRIVATE FUNCTIONS: * void lcd_delay_us (unsigned long t); * void lcd_delay_ms (unsigned long t); * void lcd_put_byte(unsigned char rs, unsigned char data); * ****************************************************************** ************/ // =========================================================== =================== //CHUONG TRINH DELAY: void delay_ms(unsigned int ms){ while(ms ){ delay_cycles(1000); } } unsigned int value; //================================ void lcd_delay_us (unsigned long t) { int i; for (i = 0; i