菜鸟求帮忙,大家帮我看一下这程序哪里错了,谢谢啦~
时间:10-02
整理:3721RD
点击:
题目是这样的:
以16进制发送一个0-65536之间的任一数,当单片机收到后在数码管上动态显示出来,波特率自定。
我编的程序如下,但是数码管总是显示出一堆乱码,这是为什么?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x76,0x79,0x38,0x3f,0x00};
sbit dula=P2^0;
sbit wela=P2^1;
uchar num,wan,qian,bai,shi,ge;
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);
void delay(uint z);
void init();
void main()
{
init();
while(1)
{
}
}
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50;
EA=1;
ES=1;
}
void ser() interrupt 4
{
RI=0;
num=SBUF;
P1=SBUF;
wan=num%10000;
qian=num%10000/1000;
bai=num%10000%1000/100;
shi=num%10000%1000%100/10;
ge=num%10;
while(!RI)
display(wan,qian,bai,shi,ge);
}
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>1;x--)
for(y=110;y>0;y--);
}
以16进制发送一个0-65536之间的任一数,当单片机收到后在数码管上动态显示出来,波特率自定。
我编的程序如下,但是数码管总是显示出一堆乱码,这是为什么?
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x76,0x79,0x38,0x3f,0x00};
sbit dula=P2^0;
sbit wela=P2^1;
uchar num,wan,qian,bai,shi,ge;
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);
void delay(uint z);
void init();
void main()
{
init();
while(1)
{
}
}
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
SCON=0x50;
EA=1;
ES=1;
}
void ser() interrupt 4
{
RI=0;
num=SBUF;
P1=SBUF;
wan=num%10000;
qian=num%10000/1000;
bai=num%10000%1000/100;
shi=num%10000%1000%100/10;
ge=num%10;
while(!RI)
display(wan,qian,bai,shi,ge);
}
void display(uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>1;x--)
for(y=110;y>0;y--);
}