#include<reg52.h>
unsigned char code table[]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
unsigned int num,tt;unsigned char ALARM,ALA_SWITCH,ALA_SHI,ALA_FEN,SHI,FEN,num1,num2,num3,num4;
sbit K1=P1^0;sbit K2=P1^1;
sbit K3=P1^2;sbit K4=P1^3;
sbit GLED=P0^0;sbit RLED=P0^1;sbit CLOCK_ADJ=P0^2;
void delay(unsigned int a);
void display(unsigned char a,unsigned char b);
void readkey();
void main()
{
RLED=0;
ALARM=0;
ALA_SWITCH=0;
CLOCK_ADJ=1;
ALA_SHI=12;
ALA_FEN=0;
SHI=0;
FEN=0;
num=0;
tt=0;
TMOD=0x01;
EA=1;
ET0=1;
TR0=1;
TH0=(65536-50000)/256;
//50ms TL0=(65536-50000)%256;
while(1)
{
if(tt>=10)
{
RLED=!RLED;
tt=0;
num++;
if(num>=120)
{
num=0;
FEN++;
}
if(FEN>=60)
{
FEN=0;
SHI++;
}
if(SHI>=24) SHI=0;
}
if(ALA_SHI>=24)ALA_SHI=0; if(ALA_FEN>=60)ALA_FEN=0; if(SHI==ALA_SHI&&FEN==ALA_FEN)ALARM=1; else ALARM=0;
readkey(); if(CLOCK_ADJ==1)display(SHI,FEN); if(CLOCK_ADJ==0)display(ALA_SHI,ALA_FEN);
}
}
void delay(unsigned int a)
{ unsigned int x,y;
for(x=a;x>0;x--)
for(y=100;y>0;y--);}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++; if(ALARM==1&&ALA_SWITCH==1)GLED=!GLED; }
void display(unsigned char a,unsigned char b)
{
num1=a/10;
num2=a%10;
num3=b/10;
num4=b%10;
P3=0xFF;
P2=table[num1];
P3=0x0E;
delay(2);
P3=0xFF;
if(num%2==0)
P2=table[num2]|0x80;
else P2=table[num2];
P3=0X0D;
delay(2);
P3=0xFF;
P2=table[num3];
P3=0X0B;
delay(2);
P3=0xFF;
P2=table[num4];
P3=0X07;
delay(2);
}
void readkey(){
if(K1==0)
{ delay(5);
delay(5); if(K1==0)CLOCK_ADJ=!CLOCK_ADJ; while(!K1) ;
delay(5);
delay(5); }
if(K2==0)
{
delay(5);
delay(5);
if(K2==0)
{
if(CLOCK_ADJ==1)SHI++; if(CLOCK_ADJ==0)ALA_SHI++;
}
while(!K2);
delay(5);
delay(5);
}
if(K3==0)
{
delay(5);
delay(5);
if(K3==0)
if(CLOCK_ADJ==1)FEN++; if(CLOCK_ADJ==0)ALA_FEN++;
while(!K3) ;
delay(5);
delay(5); }
if(K4==0)
{
delay(5);
delay(5);
if(K4==0)
{
GLED=1;
ALA_SWITCH=!ALA_SWITCH;
}
while(!K4);
delay(5);
delay(5); } } |