#include<reg52.h>
sbit S4=P3^3;
sbit S5=P3^2;
sbit buzzle=P0^6;
unsigned int miao=0;
unsigned int fen=0;
unsigned int shi=0;
unsigned char smgduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
0xbf,0x7f};
void HC138(unsigned int a)
{
switch(a)
{
case 4:P2=(P2&0X1F)|0X80;break;
case 5:P2=(P2&0X1F)|0XA0;break;
case 6:P2=(P2&0X1F)|0XC0;break;
case 7:P2=(P2&0X1F)|0XE0;break;
}
}
void delay(unsigned int t)
{
while(t--);
}
void Initimer0()
{
TMOD=0X01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
ET0=1;
EA=1;
TR0=1;
}
void shumaguan(unsigned int b,unsigned int d)
{
HC138(6);
P0=0X01<<b;
HC138(7);
P0=d;
}
void duanxuan()
{
shumaguan(smgduan[miao%10],7);
delay(500);
shumaguan(smgduan[miao/10],6);
delay(500);
shumaguan(smgduan[16],5);
delay(500);
shumaguan(smgduan[fen%10],4);
delay(500);
shumaguan(smgduan[fen/10],3);
delay(500);
shumaguan(smgduan[16],2);
delay(500);
shumaguan(smgduan[shi%10],1);
delay(500);
shumaguan(smgduan[shi/10],0);
delay(500);
}
void Key_Scan()
{
if(S4==0)
{
delay(100);
if(S4==0)
{
TR0=~TR0;
}
}
if(S5==0)
{
delay(100);
if(S5==0)
{
miao=0;
fen=0;
shi=0;
}
}
}
void Interrupt() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
miao++;
if(miao==60)
{
fen++;
miao=0;
}
else if(fen==60)
{
shi++;
fen=0;
}
}
void main()
{
/*HC138(5);
P2=0XA0;buzzle=0;*/
Initimer0();
while(1)
{
duanxuan();
Key_Scan();
}
}
楼主,能帮我看一下这个程序哪有问题吗?
|