用数码管的前两位显示十进制数,按下K1键数值加一,按下K2键减一,按下K3键数值归0,按下k4键数值自动停止加1,利用定时器功能。求大神帮我看一下,我觉得程序有没有问题,编译之后问题很多,但是我就是找不到哪里有问题。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit wel=P1^2;
sbit dul=P1^1;
sbit key1=P1^4;
sbit key2=P1^5;
sbit key3=P1^6;
sbit key4=P1^7;
uchar code table[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,
0x88,0x83,0xc6,0xa1,0x84,
0x8e
}
uchar num,num2;
void delay(uint);
void display(uchar);
void init();
void keyscan();
void display()
{
uchar shi,ge;
shi=num/10;
ge=num%10;
dul=1;
P0=table[shi];
dul=0;
wel=1;
P0=0x01;
wel=0;
delay(5);
dul=1;
P0=table[ge];
dul=0;
wel=1;
P0=0x02;
wel=0;
delay(5);
}
void delay(uint num1)
{
uint i,j;
for(i=num1;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x01;
TH1=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
num++;
if(num==60)
{
num=0;
while(!key1);
}
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
num++;
if(num==0)
{
num=60;
num--;
while(!key2);
}
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
num=0;
while(!key3);
}
}
if(key4==0)
{
delay(10);
if(key4==0)
{
while(!key3);
TR0=~TR0;
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num);
}
}
void T0time()interrupt 1
{
TH1=(65536-45872)/256;
TL0=(65536-45872)%256;
num2++;
if(num2==20)
{
num2=0;
if(num==60)
num=0;
}
} |