求一个单片机程序

以16进制发送一个0-65536之间的任一数,当单片机收到后在数码管上动态显示出来,波特率自定,要c语言的,拜托;

#include<reg52.h>
#define UCHAR unsigned char
#define UINT unsigned int
sbit dula = P2^6;
sbit wela = P2^7;
/*0 1 2 3 4 5 6
*7 8 9 A b C d
*E F H L P U .
*/
UCHAR code table[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d,
0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x37, 0x5e,
0x79, 0x71, 0x76, 0x38, 0x73, 0x3e, 0x80,
0x00};
bit flag;

void main()
{
void display(UCHAR first, UCHAR second, UCHAR third, UCHAR fourth, UCHAR fifth);
void init();
char times;
UINT temp;
UCHAR first, second, third, fourth, fifth;
init();
while(1)
{
if(flag)
{
flag = 0;
if(++times == 1)
temp = SBUF * 256;
/*//读入两次数据时才把temp值显示出来
*因为一次只能收1个字节的数据*/
else if(times == 2)
{
temp += SBUF;
times = 0;
first = temp % 10;
second = temp % 100 / 10;
third = temp % 1000 / 100;
fourth = temp % 10000 / 1000;
fifth = temp / 10000;
display(fifth, fourth,third,second,first);
}
}
}
}
void init()
{
TMOD = 0x20;
TH1 = 0XFD;
TL1 = 0XFD;
SM0 = 0;
SM1 = 1;
EA = 1;
TR1 = 1;
ES = 1;
REN = 1;
wela = 1;
P0 = 0xff;
wela = 0;
}
void delay(UINT ms)
{
UINT x, y;
for(x = ms; x; x--)
for(y = 197; y; y--)
;
}
void port() interrupt 4
{
RI = 0;
flag = 1;
}
void display(UCHAR first, UCHAR second, UCHAR third, UCHAR fourth, UCHAR fifth)
{
char i;

while(!flag)
{
for(i = 1; i <= 5; i++)
{
P0 = 0xff;
wela = 1;
switch(i)
{
case 1: P0 = 0xfe;break;
case 2: P0 = 0xfd;break;
case 3: P0 = 0xfb;break;
case 4: P0 = 0xf7;break;
case 5: P0 = 0xef;break;
}
wela = 0;
dula = 1;
switch(i)
{
case 1: P0 = table[first];break;
case 2: P0 = table[second];break;
case 3: P0 = table[third];break;
case 4: P0 = table[fourth];break;
case 5: P0 = table[fifth];break;
}
dula = 0;
delay(1);
}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-03-04
int receiveData = receive();
display(receiveData);就可以了啊。具体怎么接收和显示就得看你的硬件了。

参考资料:sername

相似回答