Để mình coi lại xem nhé.Mai lên Hà nội mua con lcd mới vậy.Làm đủ mọi cách mà không thấy động tĩnh gì cả chỉ hiển thị vài ký tự linh tinh.
Nhưng dù sao cũng cảm ơn các bác nhé.
Nhưng dù sao cũng cảm ơn các bác nhé.
bit ký hiệu ý nghĩa +1:0 P0.0 00 GPIO Port 0.0 00 01 TXD (UART0) 10 PWM1 11 Reserved
bit ký hiệu ý nghĩa +1:0 P0.0 00 GPIO Port 0.0 00 01 TXD (UART0) 10 PWM1 11 Reserved
/*------------------------------ CHUONG TRINH GIAO TIEP LCD------------------------------- */ // Cac chan dung cho giao tiep LCD //P0.0 - P0.7 = D0 - D7 //P0.8 = LCD_EN //P0.9 = LCD_RS //P0.10 = LCD_RW /* Include file */ #include <LPC214x.h> /* Define LCD PinIO Mask */ #define LCD_EN 0x00000100 // P0.8(0000 0000 0000 0000 0000 000x 0000 0000) #define LCD_RS 0x00000200 // P0.9(0000 0000 0000 0000 0000 00x0 0000 0000) #define LCD_RW 0x00000400 // P0.10(0000 0000 0000 0000 0000 0x00 0000 0000) #define LCD_BUS 0x000000ff // P0.0-P0.7(0000 0000 0000 0000 0000 0000 xxxx xxxx) #define lcd_en_set() IOSET0 = LCD_EN // EN = 1 (Enable) #define lcd_en_clr() IOCLR0 = LCD_EN // EN = 0 (Disable) #define lcd_rs_set() IOSET0 = LCD_RS // RS = 1 (Select Instruction mode) #define lcd_rs_clr() IOCLR0 = LCD_RS // RS = 0 (Select Data mode) #define lcd_rw_set() IOSET0 = LCD_RW // RW = 1 (Read) #define lcd_rw_clr() IOCLR0 = LCD_RW // RW = 0 (Write) /* Chon chieu cac IO pins giao tiep LCD*/ #define lcd_dir_write() IODIR0 |= 0x000007ff //(0000 0000 0000 0000 0000 0xxx xxxx xxxx) #define lcd_dir_read() IODIR0 &= 0xffffff00 //(0000 0000 0000 0000 0000 0000 xxxx xxxx) /* Define cac thao tac co ban voi LCD */ #define lcd_clear() lcd_write_control(0x01) // Clear Display #define lcd_cursor_home() lcd_write_control(0x02) // Set Cursor = 0 #define lcd_display_on() lcd_write_control(0x0E) // LCD Display Enable #define lcd_display_off() lcd_write_control(0x08) // LCD Display Disable #define lcd_display_blink() lcd_write_control(0x0F) // Set Cursor = Blink #define lcd_cursor_on() lcd_write_control(0x0E) // Enable LCD Cursor #define lcd_cursor_off() lcd_write_control(0x0C) // Disable LCD Cursor #define lcd_cursor_left() lcd_write_control(0x10) // Shift Left Cursor #define lcd_cursor_right() lcd_write_control(0x14) // Shift Right Cursor #define lcd_display_sleft() lcd_write_control(0x18) // Shift Left Display #define lcd_display_sright() lcd_write_control(0x1C) // Shift Right Display /* prototype */ void lcd_init(void); // Initial LCD void lcd_write_control(unsigned char); // Write Instuction to LCD void lcd_write_ascii(unsigned char); // Write LCD Display(ASCII) void goto_vitri(unsigned char); // Set Position Cursor LCD void lcd_hienthi(unsigned char*); // Print Display to LCD char busy_lcd(void); // Read Busy LCD Status void enable_lcd(void); // Enable Pulse void delay(unsigned long int); // Delay Function /* Chuong trinh chinh */ int main(void) { lcd_init(); // Initial LCD // Loop Print Message to LCD16 x 2 // while(1) // Loop Continue { goto_vitri(0x80); // Set Cursor Line-1 lcd_hienthi("ngay 15/06/09"); // Display LCD Line-1 goto_vitri(0xC0); // Set Cursor = Line-2 lcd_hienthi("Chuong trinh LCD"); // Display LCD Line-2 delay(5000000); // Display Delay lcd_clear(); goto_vitri(0x80); // Set Cursor Line-1 lcd_hienthi("LPC2148-NXP"); // Display LCD Line-1 goto_vitri(0xC0); // Set Cursor = Line-2 lcd_hienthi("EASY ARM!!!"); // Display LCD Line-2 delay(5000000); // Display Delay lcd_clear(); goto_vitri(0x80); // Set Cursor Line-1 lcd_hienthi("Tac gia viet:"); // Display LCD Line-1 goto_vitri(0xC0); // Set Cursor = Line-2 lcd_hienthi("killer_hung yen"); // Display LCD Line-2 delay(5000000); // Display Delay lcd_clear(); } } /******************************************************/ /* Initial LCD : 8bit,2-line display,5x7 dot charater */ /******************************************************/ void lcd_init() { //unsigned int i; // bien delay PINSEL0 = 0x00000000; // GPIO cho cac pin P0.0 den P0.15(chon cac chan o Pinsel 0) IODIR0 = 0x000007ff; // P0.0-P0.10 la output(gan cac chan p0.0-p0.10 lam dau ra) delay(100000); // Power-On Delay (15 mS) /* Check LCD*/ IOSET0 = 0x000007ff; // Reset all pins IOCLR0 = 0x00000030; // D5:D4 = 11 (0000 0000 0000 0000 0000 0000 0011 0000) enable_lcd(); // Xung enable cho LCD delay(100000); // Delay 4.1ms IOCLR0 = 0x000007ff; // Reset all pins IOSET0 = 0x00000030; // D5:D4 = 11 enable_lcd(); while(busy_lcd()); // Xung enable cho LCD delay(100000); // Delay 100 ms IOCLR0 = 0x000007ff; IOSET0 = 0x00000030; enable_lcd(); while(busy_lcd()); //Wait LCD Execute complete IOCLR0 = 0x000007ff; IOSET0 = 0x00000030; enable_lcd(); while(busy_lcd()); //Wait LCD Execute complete /* Config cho LCD */ //lcd_write_control(0x30); lcd_write_control(0x38); // Function Set (DL=1 8-Bit,N=1 2 Line,F=0 5X7) lcd_write_control(0x0C); // Display on/off Control (Entry Display,Cursor off,Cursor not Blink) //lcd_write_control(0x06); // Entry Mode Set (I/D=1 Increment,S=0 Cursor Shift) //lcd_write_control(0x01); // Clear Display (Clear Display,Set DD RAM Address=0) delay(100000); // Wait Command Ready } /************************/ /* thiet lap vi tri nhap nhay cua control*/ /************************/ void goto_vitri(unsigned char i) { i |= 0x80; // Set DD-RAM Address Command lcd_write_control(i); } /******************************/ /* Write construction to LCD */ /******************************/ void lcd_write_control(unsigned char val) { //unsigned int i; lcd_rs_clr(); lcd_rw_clr(); // RS = 0 = Instruction Select IOCLR0 = LCD_BUS; // Reset Data pins RS=0 IOSET0 = (val & LCD_BUS); // write value enable_lcd(); // Xung enable LCD while(busy_lcd()); // Wait LCD Execute Complete delay(100000); // Wait Command Ready } /*********************************/ /* Write ascii character to LCD */ /********************************/ void lcd_write_ascii(unsigned char val) { unsigned int i; lcd_rs_set(); lcd_rw_clr(); // RS = 1 = Data Select IOCLR0 = LCD_BUS; // Reset Data pins IOSET0 = (val & LCD_BUS); // write value enable_lcd(); // Xung enable LCD while(busy_lcd()); // Wait LCD Execute Complete delay(100000); // Wait Command Ready } /************************************/ /* Print Display Data(ASCII) to LCD */ /************************************/ void lcd_hienthi(unsigned char* str) { int i; for (i=0;i<=16 && str[i]!=0;i++) { // 16 Character Print lcd_write_ascii(str[i]); } // Print Byte to LCD } /******************/ /* Wait LCD Ready */ /******************/ /*char busy_lcd(void) { unsigned long busy_status; // Busy Status Read unsigned int i; // Delay Count lcd_dir_read(); // LCD Data Bus = Read lcd_rs_clr(); // Instruction Select lcd_rw_set(); // Read Direction lcd_en_set(); // Start Read Busy for (i=0;i<100;i++); // Delay Before Read busy_status = (IOPIN0 & 0x00000080); // D7 la busy flag if(busy_status == 0x00800000) // Read & Check Busy Flag { lcd_en_clr(); // Disable Read lcd_rw_clr(); // Default = Write Direction lcd_dir_write(); // LCD Data Bus = Write return 1; // LCD Busy Status } else { lcd_en_clr(); // Disable Read lcd_rw_clr(); // Default = Write Direction lcd_dir_write(); // LCD Data Bus = Write return 0; // LCD Ready Status } }*/ /***********************/ /* Enable Pulse to LCD */ /***********************/ void enable_lcd(void) // Enable Pulse { //unsigned int i; // Delay Count lcd_en_set(); // Enable ON (EN=1) delay(100000); lcd_en_clr(); // Enable OFF(EN=0) } /***********************/ /* Delay Time Function */ /* 1-4294967296 */ /***********************/ void delay(unsigned long int count1) { while(count1 > 0) {count1--;} // Loop Decrease Counter }
Comment