📄 lcm.h
字号:
#define Lcd1602CmdPort XBYTE[0x0000] //E=1 RS=0 RW=0
#define Lcd1602WdataPort XBYTE[0x0100] //E =1 RS=1 RW=0
#define Lcd1602StatusPort XBYTE[0x0200] //E=1 RS=0 RW=1
#define Busy 0x80 // 忙判别位
void LcdWriteCommand(unsigned char CMD,unsigned char AttribC);
void LcdWriteData(char dataW)reentrant;
void LcdReset(void);
void DispOneChar(unsigned char x,unsigned char y,unsigned char Wdata)reentrant;
void Delay400Ms(void);
void Delay5Ms(void);
void LcdWriteCommand(unsigned char CMD,unsigned char AttribC)
{
if(AttribC)
{
while(Lcd1602StatusPort & Busy);
}
Lcd1602CmdPort = CMD;
}
void LcdWriteData( char dataW )reentrant
{
while( Lcd1602StatusPort & Busy ); // 检测忙信号
Lcd1602WdataPort = dataW;
}
void Delay5Ms(void) //短延时
{
unsigned int i = 5552;
while(i--)_nop_();
}
void Delay400Ms(void) //长延时
{
unsigned char i = 5;
unsigned int j;
while(i--)
{
j=7269;
while(j--)
{
_nop_();
}
};
}
void LocateXY(char posx,char posy)reentrant
{
unsigned char temp;
temp = posx & 0x0f;
posy &= 0x01;
if ( posy )temp |= 0x40;
temp |= 0x80;
LcdWriteCommand(temp,0);
}
void DispOneChar(unsigned char x,unsigned char y,unsigned char Wdata)reentrant
{
LocateXY(x, y); // 定位显示地址
LcdWriteData(Wdata); // 写字符
}
void LcdReset( void )
{
LcdWriteCommand( 0x38, 0); // 显示模式设置(不检测忙信号)
Delay5Ms();
LcdWriteCommand( 0x38, 0); // 共三次
Delay5Ms();
LcdWriteCommand( 0x38, 0);
Delay5Ms();
LcdWriteCommand( 0x38, 1); // 显示模式设置(以后均检测忙信号)
LcdWriteCommand( 0x08, 1); // 显示关闭
LcdWriteCommand( 0x01, 1); // 显示清屏
LcdWriteCommand( 0x06, 1); // 显示光标移动设置
LcdWriteCommand( 0x0c, 1); // 显示开及光标设置
}
void printx(unsigned char x,unsigned char y,unsigned char *ptr)reentrant
{
LocateXY(x, y); // 定位显示地址
while(*ptr++!='\0')
{
LcdWriteData(*(ptr-1));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -