各位前辈,小弟刚刚接触51单片机,用的郭天祥老师的教学板,但是在【写串口通信以16进制发送一个0-65536之间的任一数,当单片机收到后在数码管上动态显示出来】这个程序时,出现了问题,每次打开串口,用串口调试器发送数据只能发送16个字节,也就是 发送俩次后,再用串口调试工具发送就发送不过去,板子上的发送灯都不闪一下~~~
程序如下,去前辈指点迷津!
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
unsigned char flag;
unsigned char b=0;
uint temp;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={ //数码显示器初值数组
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init(){
TMOD = 0x20;
TH1 = 0XFD;
TL1 = 0XFD;
SM0 = 0;
SM1 = 1;
EA = 1;
TR1 = 1;
ES = 1;
REN = 1;
}
void display(uint c)
{
uchar A1,A2,A3,A4,A5;
A1=c/10000;
A2=c%10000/1000;
A3=c%1000/100;
A4=c%100/10;
A5=c%10;
dula=1;
P0=table[A1];
dula=0;
P0=0XFF;
wela=1;
P0=0xfe;
wela=0;
delayms(1);
dula=1;
P0=table[A2];
dula=0;
P0=0XFF;
wela=1;
P0=0xfd;
wela=0;
delayms(1);
dula=1;
P0=table[A3];
dula=0;
P0=0XFF;
wela=1;
P0=0xfb;
wela=0;
delayms(1);
dula=1;
P0=table[A4];
dula=0;
P0=0XFF;
wela=1;
P0=0xf7;
wela=0;
delayms(1);
dula=1;
P0=table[A5];
dula=0;
P0=0XFF;
wela=1;
P0=0xef;
wela=0;
delayms(1);
}
void main(){
init();
while(1){
if(flag==1)
{
flag=0;
if(b==0)
temp=SBUF*256;
if(b==1)
temp=temp+SBUF;
b++;
if(b==2) {
b=0;
ES = 0;
SBUF = temp;
while(!TI);
TI = 0;
ES = 1;
}
}
display(temp);
}
}
void ser() interrupt 4{
RI=0;
flag=1;
} |