向SBUF存入>8位二进制数

[复制链接]
查看11 | 回复1 | 2011-2-9 16:25:33 | 显示全部楼层 |阅读模式
C51程序如下略显拖沓,我想用串口调试助手发送一个>255的数字,但是最大只显示255,如何修改?如何让程序更简洁?
#include
#define uchar unsigned char
#define uint unsigned int
uchar Flag;
uint t,k,b,a;
uchar code table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};
void display(uint,uint,uint,uint,uint) ;
void delayms(uchar xms)
{
uint i,j;
for(i=xms;i>0;i--)

for(j=110;j>0;j--);
}
void canshu()
{
TMOD=0x20;
TH1=0xf4;
TL1=0xf4;
TR1=1;

SCON=0x50;
EA=1;
ES=1;
}
void display(uint wan,uint qian,uint bai,uint shi,uint ge)
{
wan=a/10000;
t=a%10000;
qian=t/1000;
k=a%1000;
bai=k/100;
b=a%100;
shi=b/10;
ge=a%10;

P1=0x00;
P2=table[wan];
delayms(5);

P1=0x01;
P2=table[qian];
delayms(5);
P1=0x02;
P2=table[bai];
delayms(5);
P1=0x03;
P2=table[shi];
delayms(5);
P1=0x04;
P2=table[ge];
delayms(5);
}
void main()
{
canshu();
while(1)
{
if(Flag==1)
{
ES=0;
Flag=0;
ES=1;
}
display();
}
}
void chuan()interrupt 4
{
a=SBUF;
RI=0;
Flag=1;
}

回复

使用道具 举报

千问 | 2011-2-9 16:25:33 | 显示全部楼层
SBUF是一个字节的寄存器,当然不会超过255了。修改 void chuan() interrupt 4 这个接收程序如下即可接收2字节数(0 - 65535):void chuan() interrupt 4{static uchar s = 0;if(RI){
RI = 0;
if(s)
{
a |= SBUF;
s = 0;
Flag = 1;
}
else
{
a = SBUF;
a = a<<8 ;
s ++;
}}}如果想1字节、2字
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行