单片机stc89c52rc控制LCD1602不能显示怎么办?
#include<reg52.h>sbitrs=P2^0;sbitrw=P2^1;sbiten=P2^2;#defineDataP1voidDelay(unsignedc...
#include <reg52.h>
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
#define Data P1
void Delay(unsigned char H,unsigned char L);
void LCDWriteCom(unsigned char com,bit busy);
void LCDWriteData(unsigned char dat,bit busy);
void ReadBusy(void);
void LCDInit();
//以上为声明部分
void ReadBusy(void){
rs=0;
rw=1;
en=0;
en=1;
while(Data&0x80);
en=0;
}
void LCDInit(){
Delay((65536-15000)/256,(65536-15000)%256);
LCDWriteCom(0x38,0);
Delay(0xec,0x78);
LCDWriteCom(0x38,0);
Delay(0xec,0x78);
LCDWriteCom(0x38,0);
LCDWriteCom(0x38,1);
LCDWriteCom(0x08,1);
LCDWriteCom(0x06,1);
LCDWriteCom(0x01,1);
LCDWriteCom(0x0c,1);
}
void Delay(unsigned char H,unsigned char L){
TR0=1;
TH0=H;
TL0=L;
TF0=0;
while(!TF0);
TR0=0;
}
void LCDWriteDat(unsigned char dat,bit busy){
if(busy)
ReadBusy();
rs=1;
rw=0;
Data=dat;
Delay(0xec, 0x78); //延时5ms
en=1; //保证数据接收到了
en=0;
}
void LCDWriteCom(unsigned char com,bit busy){
if(busy)
ReadBusy();
rs=0;
rw=0;
Data=com;
Delay(0xec,0x78); //延时5ms
en=1;
en=0;
}
void main(void){
TMOD=0x00;//0000 0000 开定时器
TR0=1; //开定时器
LCDInit();
LCDWriteCom(0x80,1);
LCDWriteDat('Y',1);
TR0=0;
while(1);
}
谢了,就是全白屏,说明进去数据了。 展开
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
#define Data P1
void Delay(unsigned char H,unsigned char L);
void LCDWriteCom(unsigned char com,bit busy);
void LCDWriteData(unsigned char dat,bit busy);
void ReadBusy(void);
void LCDInit();
//以上为声明部分
void ReadBusy(void){
rs=0;
rw=1;
en=0;
en=1;
while(Data&0x80);
en=0;
}
void LCDInit(){
Delay((65536-15000)/256,(65536-15000)%256);
LCDWriteCom(0x38,0);
Delay(0xec,0x78);
LCDWriteCom(0x38,0);
Delay(0xec,0x78);
LCDWriteCom(0x38,0);
LCDWriteCom(0x38,1);
LCDWriteCom(0x08,1);
LCDWriteCom(0x06,1);
LCDWriteCom(0x01,1);
LCDWriteCom(0x0c,1);
}
void Delay(unsigned char H,unsigned char L){
TR0=1;
TH0=H;
TL0=L;
TF0=0;
while(!TF0);
TR0=0;
}
void LCDWriteDat(unsigned char dat,bit busy){
if(busy)
ReadBusy();
rs=1;
rw=0;
Data=dat;
Delay(0xec, 0x78); //延时5ms
en=1; //保证数据接收到了
en=0;
}
void LCDWriteCom(unsigned char com,bit busy){
if(busy)
ReadBusy();
rs=0;
rw=0;
Data=com;
Delay(0xec,0x78); //延时5ms
en=1;
en=0;
}
void main(void){
TMOD=0x00;//0000 0000 开定时器
TR0=1; //开定时器
LCDInit();
LCDWriteCom(0x80,1);
LCDWriteDat('Y',1);
TR0=0;
while(1);
}
谢了,就是全白屏,说明进去数据了。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询