#include<reg52.h> // 单片机0000~9999秒表
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar bai,shi;
uint a1,a2;
sbit D1=P3^0;
sbit D2=P3^1;
sbit D3=P3^2;
sbit D4=P3^3;
sbit key=P3^5;
sbit key1=P3^7;
bit j ;
uint y ;
void main()
{
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
EA=1;
ET0=1;
TR0=1;
bai=0;
shi=0;
while(1)
{
if(key==0)
{
j=0;
}
if(key1==0)
{
j=1; a2=0;
}
}
}
void timer0()interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
a1++;
y++;
if(a1==100) // 100
{
a1=0;
if(j==1) a2++;
if(a2>=10000) a2=0; // 10000
}
D1 = 1; D2 = 1; D3 = 1; D4 = 1;
if(y==1)
{
P1=table[a2%10000/1000]; // 10000
D4=0;
}
if(y==2)
{
P1=table[a2%1000/100]; // 1000
D3=0;
}
if(y==3)
{
P1=table[a2%100/10]; // 100
D2=0;
}
if(y==4)
{
P1=table[a2%10]; // 10
D1=0;
y=0;
}
}
|