LCD 液晶顯示器顯示程式,程式開始初始化 LCD1602 模組,設定不閃動及不顯示游標。初始化後,將資料傳送到 Line 1 及 Line 2 顯示在液晶屏上,然後閃動 LED 燈。
▲ LCD1602 流程圖 |
//***** Includes ****** #include #include #include "xlcd\xlcd.h" // LCD header //***** Define ***** #define LED0 PORTAbits.RA0 // Define LED=PORTA RA0 //***** Program Start Here ***** void main(void) { char LCD_L1[]="** Welcome To **"; char LCD_L2[]=" Bug Workshop 1"; TRISA = 0b00000000; // Setup PORTA as Output // Configure LCD OpenXLCD( FOUR_BIT & LINES_5X7 ); while(BusyXLCD()); WriteCmdXLCD(BLINK_OFF & CURSOR_OFF ); while(BusyXLCD()); while(1) { SetDDRamAddr(0x00); // Set Line 1 Home Position putsXLCD(LCD_L1); // Display Text while(BusyXLCD()); // Check Buy? SetDDRamAddr(0x40); // Set Line 2 Home Position putsXLCD(LCD_L2); // Display Text LED0=0; // LED OFF Delay10KTCYx(240); // 10,000x240x1/12us = 200ms Delay10KTCYx(240); LED0=1; // LED ON Delay10KTCYx(240); // 10,000x240x1/12us = 200ms Delay10KTCYx(240); } } |
修改 xlcd.h:
/* Interface type 8-bit or 4-bit * For 8-bit operation uncomment the #define BIT8 */ //#define BIT4 /* When in 4-bit interface define if the data is in the upper * or lower nibble. For lower nibble, comment the #define UPPER */ #define UPPER /* DATA_PORT defines the port to which the LCD data lines are connected */ /* FOR PICDEM 2 PLUS - USE PORTD */ #define DATA_PORT PORTD #define TRIS_DATA_PORT TRISD /* CTRL_PORT defines the port where the control lines are connected. * These are just samples, change to match your application. */ /* FOR PICDEM 2 PLUS - USE PORTA */ #define RW_PIN PORTDbits.RD2 /* PORT for RW */ #define TRIS_RW DDRDbits.RD2 /* TRIS for RW */ #define RS_PIN PORTDbits.RD1 /* PORT for RS */ #define TRIS_RS DDRDbits.RD1 /* TRIS for RS */ #define E_PIN PORTDbits.RD3 /* PORT for E */ #define TRIS_E DDRDbits.RD3 /* TRIS for E */ |
▲LCD1602 啟動 |
▲LCD1602 顯示 Welcome To Bug Workshop 1 |
2011 年 02 月 22 日 天氣報告
氣溫:15.8 度 @ 23:00
相對濕度:百分之73%
天氣:天氣寒冷及多
沒有留言:
張貼留言