#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar bai,shi,ge;
uint num,dishu,geshu;
sbit zhdu=P3^2;
sbit den1=P0^1;
sbit den2=P0^5;
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
void init();
uint yunsh(uchar bai,uchar shi,uchar ge);
void shuanfa();
void display(uchar bai,uchar shi,uchar ge);
void delay(uint z);
void main()
{
init();
while(1)
{
if(dishu==3)
{
dishu=0;
}
TR0=0;
shuanfa();
display(bai,shi,ge);
}
}
void init()
{
TMOD=0x01;
TH0=(65536)/256;
TL0=(65536)%256;
EA=1;
ET0=1;
EX0=1;
TR0=1;
IT0=1;
num=1;
}
void exter0() interrupt 0
{
den1=0;
dishu++;
zhdu=1;
}
void timer0() interrupt 1
{
den2=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void shuanfa()
{
geshu=360/num;
bai=geshu/100;
shi=geshu/10%10;
ge=geshu%10;
}
void display(uchar bai,uchar shi,uchar ge)
{
P2=0xff;
P2=table[bai];
P1=0xef;
delay(10);
P2=0xff;
P2=table[shi];
P1=0xdf;
delay(10);
P2=0xff;
P2=table[ge];
P1=0xbf;
delay(10);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
} |