这是我写的想显示0-65536之间的数;可是只有个位正确显示其他都不行: 还有上位机用十六进制发送程序内部要进行十进制的转化吗???谢谢
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit beep=P2^3;
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,
0x76,0x79,0x38,0x3f,0};
uchar flag;
int num;
void init();
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display();
void main()
{
init();
num=0;
while(1)
{
display();
if(flag==1)
{
//ES=0;
flag=0;
/*SBUF=b;
while(!
ti);
TI=0;
SBUF=s;
while(!TI);
TI=0;
SBUF=g;
while(!TI);
TI=0;
SBUF=a;
while(!TI);
TI=0;
ES=1;*/
}
}
}
void init()
{
TMOD=0x20;
TH1=0xfd;
TL1=0xfd;
TR1=1;
REN=1;
SM0=0;
SM1=1;
EA=1;
ES=1;
num=0;
P0=0xff;
}
void ser() interrupt 4
{
RI=0;
num=SBUF;
flag=1;
if(num==65535)
num=0;
}
void display()
{
uchar w,q,b,s,g;
w=num/10000;
q=num%10000/1000;
b=num%1000/100;
s=num%100/10;
g=num%10;
dula=1;
P0=table[w];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
dula=1;
P0=table[q];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[b];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[s];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(1);
dula=1;
P0=table[g];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(1);
}
一周热门 更多>