使用该模块需要在while运行前,需要进行1602初始化
1602.c
#include<1602.h>
void Delay1ms() //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void Delay5ms() //@11.0592MHz
{
unsigned char i, j;
i = 54;
j = 199;
do
{
while (--j);
} while (--i);
}
unsigned char Judg_LCD(void)//判断LCD忙/闲
{ //result忙闲标志,最高位D7为标志位,1忙0闲
unsigned char result;
Data = 0xff;//先置高电平,防止误判
RS = 0;
Delay5ms();
RW = 1;//RS=0,RW = 1;忙标志和地址计数器写出
LCDEN = 1;//使能信号开
Delay5ms();
result = Data & 0x80;//
LCDEN = 0;//使能信号关
return result;
}
void Wr_LCD(unsigned char m)//写入命令函数
{
while(Judg_LCD()==1);
RS = 0;
Delay1ms();
RW = 0; //RS = RW =0;命令寄存器写入
LCDEN = 1;
Delay1ms();
Data = m;//写入数据
Delay1ms();
LCDEN = 0;
}
void Write_LCD(unsigned char Datval)/