各位大哥,S1为按键,在实验板上,按键达到10以上后,十位没有显示,但有隐约的1显示,不知程序是否出现了问题,请大哥们帮忙看下,程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit s1=P3^4;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar num,bai,shi,ge;
void init();
void display(uchar bai,uchar shi,uchar ge);
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
init();
while(1)
{
if(s1==0)
{
delay(2);
if(s1==0)
{
num++;
if(num==100)
num=0;
bai=num/100;
shi=num%100/10;
ge=num%10;
while(!s1);
delay(2);
while(!s1);
}
display(bai,shi,ge);
}
}
}
void init()
{
num=0;
bai=0;
shi=0;
ge=0;
dula=1;
P0=0;
dula=0;
wela=0;
}
void display(uchar bai,uchar shi,uchar ge)
{
bai=num/100;
shi=num%100/10;
ge=num%10;
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(1);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(1);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(1);
}
}
|