#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
#define PIN0 P0
#define PIN1 P1
#define PIN3 P3
sbit start=P2^7;
sbit reset=P2^6;
sbit add=P2^5;
sbit reduse=P2^4;
uint second=0;
uint num=0;
uint num1=0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f};
uchar code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
uchar code table2[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void Delayms(uint x){
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<123;j++);
}
void Display(uint w,uint a,uint b,uint c,uint d){
PIN3=table2[w];
Delayms(1);
PIN0=table[a];
PIN1=0x7f;
Delayms(1);
PIN0=table[b];
PIN1=0xbf;
Delayms(1);
PIN0=table1[c];
PIN1=0xdf;
Delayms(1);
PIN0=table[d];
PIN1=0xef;
Delayms(1);
}
void InitTimer0(){
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=0;
}
void main()
{
uint ms100=0;
uint s,s1,min,min1,minute=0;
InitTimer0();
while(1)
{
if(add==0){
Delayms(20);
if(add==0){
minute++;
while(!add);
}
}
if(reduse==0){
Delayms(20);
if(reduse==0){
minute--;
while(!reduse);
}
}
if(start==0){
Delayms(20);
{
if(start==0){
TR0=!TR0;
while(!start);
}
}
}
if(reset==0){
Delayms(20);
if(reset==0)
{
num=0;
num1=0;
ms100=0;
second=0;
minute=0;
while(!reset);
}
}
if(num1>=2)
{
num1=0;
ms100++;
if(ms100>=10)
{
ms100=0;
num1=0;
}
}
if(num>=20)
{
num=0;
second++;
if(second>=60)
{
second=0;
minute++;
if(minute>=60)
{
TR0=!TR0;
num1=0;
num=0;
ms100=0;
second=0;
minute=0;
}
}
}
s=second%10;
s1=second/10;
min=minute%10;
min1=minute/10;
Display(ms100,s,s1,min,min1);
}
}
void TIMER0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
num1++;
}
|