发送端:#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define LEN 4
unsigned char inbuf1[LEN];
uchar i,c1,c2;
bit flag=0;
sbit K=P1^6;
void init()
{
SCON=0x50; //0101方式1 允许中断接收,波特率不变
PCON=0x00; //开总中断,开串口中断
TMOD=0x20; //定时器1方式2
TH1=0xfd; //串口工作方式1
TL1=0xfd;
TR1= 1;
IE=0x90;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void sent(uchar date)
{
SBUF=date;
while(
ti==0);
TI=0;
}
void table(uchar *dat )
{
while(*dat !=' ')
{
sent(*dat);
dat++;
delay(5);
}
}
void main()
{
init();
for(;;)
{
if(K==0)
{
while(K==0);
{
table("…………");
}
}
}
delay(50);
while(1)
{
/*i=0;
{
while(table
!=' ')
sent(table);
i++;
delay(10);
}
delay(100); */
}
}
void serial () interrupt 4 using 3
{
if(RI)
{
unsigned char ch;
RI = 0;
ch=SBUF;
if(ch>32)
{
c2=0;
inbuf1[c2]=ch;
c1= ch-32;
}
else
{
c2++;
inbuf1[c2]=ch;
c1 ^= ch;
if( (c2==(LEN-1)) && (!c1) )
{
flag=1; //如果串口接收的数据达到LEN个,且校验没错,
//就置位取数标志
}
}
}
}
接收端:#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar table1[32];
uchar num;
sbit RS=P2^5;
sbit RW=P2^6;
sbit EN=P2^7;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
SCON=0x50; //0101方式1 允许中断接收,波特率不变
PCON=0x00; //开总中断,开串口中断
TMOD=0x20; //定时器1方式2
TH1=0xfd; //串口工作方式1
TL1=0xfd;
TR1=1;
EA=1;
ES=1;
}
void write_com(uchar com)
{
EN=0;
RS=0;
RW=0;
P0=com;
delay(5);
EN=1;
delay(5);
EN=0;
}
void write_data(uchar date)
{
EN=0;
RS=1;
RW=0;
P0=date;
delay(5);
EN=1;
delay(5);
EN=0;
}
void lcdinit()
{
// en=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void lcd(void)
{ delay(100);
write_com(0x83);
for(num=0;num<16;num++)
{
write_data(table1[num]);
delay(10);
}
write_com(0x80+0x43);
for(num=0;num<16;num++)
{
write_data(table1[num+16]);
delay(10);
}
}
void main()
{
init();
lcdinit();
while(1)
{
delay(100);
lcd();
}
}
void ser() interrupt 4
{
while(RI==1)
{
if (num==32){num=0;}
//ES=0;
//RI=0;
//for(num=0;num<=32;num++)
//{
table1[num]=SBUF;
RI=0;
num++;
ES=1;
//}ES=1;
}
}
大家帮看看,这个程序有点问题,用proteus仿真时,每次显示的位置都不同,谁能帮改下,谢谢了
一周热门 更多>