birdzhyli 發表于 2021-5-12 16:38
發送函數沒毛病,可以發送,只是你裝的0xD0是什么波特率?然后就是沒有接收處理函數
波特率是600 下面是接受程序
#include<reg51.h>
bit tt;
unsigned char rev;
unsigned char code dis[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void init()
{
PCON&=0x7F;
TMOD=0x20;
TH1=0xD0;
TL1=0xD0;
TR1=1;
SCON=0x50;
EA=1;
ES=1;
ET1=0;
}
void delay(unsigned int c)
{
unsigned char i,j;
for(i=0;i<c;i++) ;
for(j=0;j<110;j++);
}
void display(unsigned char x)
{
unsigned char shi,ge;
shi=x/10;
ge=x%10;
P0=dis[shi];
P2=0xbf;
delay(5);
P0=0;
P2=0xff;
P0=dis[ge];
P2=0x7f;
delay(5);
P0=0;
P2=0xff;
}
void main()
{
init();
while(1)
{
display(rev);
delay(5);
}
}
void receive() interrupt 4 //串口接收函數
{
rev=SBUF;
ES=0;
RI=0;
} |