LCD1602显示键值程序:
#include
#define uchar unsigned char #define uint unsigned int
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
void delay(uchar x); //x*0.14MS void delay1(int ms); void beep();
sbit IRIN = P3^3; //紅外接收器數據線 sbit BEEP = P1^5; //蜂鳴器驅動線 sbit RELAY= P1^4; //繼電器驅動線
uchar IRCOM[7];
sbit LCD_RS = P2^3; sbit LCD_RW = P2^4; sbit LCD_EN = P2^5;
uchar code cdis1[ ] = {%uchar code cdis2[ ] = {\
/*******************************************************************/
/* */ /**/
/*lcd_busy爲1時,忙,等待。lcd-busy爲0時,閑,可寫指令與數據。 */
/* */
/*******************************************************************/
bit lcd_busy()
{ bit result; LCD_RS = 0; LCD_RW = 1;
檢
查
LCD
忙
狀
態
LCD_EN = 1; delayNOP();
result = (bit)(P0&0x01); LCD_EN = 0; return(result); }
/*******************************************************************/
/* */ /**/
寫
指
令
數
據
到
LCD
/*RS=L,RW=L,E=高脈衝,D0-D7=指令碼。 */
/* */
/*******************************************************************/
void lcd_wcmd(uchar cmd)
{ while(lcd_busy()); LCD_RS = 0; LCD_RW = 0; LCD_EN = 0; _nop_(); _nop_(); cmd
=
((cmd&0x01)<<7)|((cmd&0x02)<<5)|((cmd&0x04)<<3)|((cmd&0x08)<<1)|((cmd&0x10)>>1)|((cmd&0x20)>>3)|((cmd&0x40)>>5)|((cmd&0x80)>>7); P0 = cmd; delayNOP(); LCD_EN = 1; delayNOP(); LCD_EN = 0; }
/*******************************************************************/
/* */
相关推荐: