这是我写的将串口接收的信息 发到1602LCD上不过显示有问题
tinghei SC, Microsoft YaHei, arial, 宋体, sans-serif, tahoma">#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcden = P3^4;
sbit lcdrs = P3^5;
sbit lcdrw = P3^6;
sbit dula = P2^6; //关闭数码管 避免因为USB供电不足 导致显示问题
sbit wela = P2^7;
uint flag;
uchar receive,temp;
void wr_com(uchar com);
void wr_data(uchar dat);
void init();
void delay(uint z);
void main()
{
init();
while(1)
{
if(flag==1)
{
flag=0;
wr_data(receive);
ES = 0;
while(!RI);
TI = 0;
ES = 1;
}
}
}
void init()
{
//关闭数码管
dula = 0;
wela = 0;
//LCD 使能初始化
lcden = 0;
wr_com(0x38); //显示模式设置
wr_com(0x0f); //显示光标设置(闪烁/不闪)
wr_com(0x06); //光标 整屏设置
wr_com(0x01); //清零
wr_com(0x80); //数据指针初始化
//串口初始化
REN = 1;
SM1 = 1;
TR1 = 1; //定时器打开
TMOD = 0X20; //定时器1 工作方式2
TH1 = 0xfd; //9600 波特率
TL1 = 0xfd;
EA = 1; //总中断打开
ES = 1; //串行口中断打开
}
void wr_com(uchar com)
{
lcdrs = 0;
lcdrw = 0;
P0 = com;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void wr_data(uchar dat)
{
lcdrs = 1;
P0 = dat;
delay(5);
lcden = 1;
delay(5);
lcden = 0;
}
void delay(uint z)
{
uint x;
uchar y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
void ser() interrupt 4
{
if(RI){
RI = 0;
receive = SBUF;
flag = 1;
}
}
-
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
如果显示1个字符0~f
write_com(0x80+0);
write_date(table1[receive]);
如果显示3个字符0~255
write_com(0x80+0);
write_date(table1[receive/100]);//百
write_com(0x80+1);
write_date(table1[receive%100/10]);//十
write_com(0x80+2);
write_date(table1[receive%10]);//个
一周热门 更多>