关于串口多字节
通信,这个是2个字节的,只能读到前面的,按快的有时候会只读到后面的。。求原因啊
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wela=P2^3;
sbit dula=P2^2;
uchar num,flag,a,j=0;
uint temp=0;
uchar r_table[2];
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar code w_table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
void display(uchar num1);
void delay(uchar x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SM0=0;
SM1=1;
REN=1;
EA=1;
ES=1;
}
void main()
{
init();
//RI=1;
while(1)
{
if(flag==1)
{
ES=0;
temp=0;
for(j=0;j<2;j++)
{
SBUF=r_table[j];
//
ti=1;
while(!TI);
TI=0;
}
j=0;
ES=1;
flag=0;
}
display(a);
}
}
void display(uchar num1)
{
dula=1;
P0=table[num1/4096];
dula=0;
P0=0xff;
wela=1;
P0=w_table[0];
wela=0;
delay(2);
dula=1;
P0=table[num1%4096/256];
dula=0;
P0=0xff;
wela=1;
P0=w_table[1];
wela=0;
delay(2);
dula=1;
P0=table[num1%16/16];
dula=0;
P0=0xff;
wela=1;
P0=w_table[2];
wela=0;
delay(2);
dula=1;
P0=table[num1%16];
dula=0;
P0=0xff;
wela=1;
P0=w_table[3];
wela=0;
delay(2);
}
void sc() interrupt 4
{
RI=0;
for(j=0;j<2;j++)
{
r_table[j]=SBUF;
}
flag=1;
/* a=SBUF;
temp++;
a=a*256+SBUF;
flag=1;*/
}
发送数据与接收不符
一周热门 更多>