#include
#define uchar unsigned char
#define uint unsigned int
sbit K1=P3^7;
uchar i,second_count, key_flag_idx;
bit key_state;
uchar dsy_code[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delayms(uint ms)
{
uchar i;
while(ms–) for(i=0;i<120;i++);
}
void key_event_handle()
{
if(key_state==0)
{
key_flag_idx=(key_flag_idx+1)%3;
switch(key_flag_idx)
{
case 1:IE=0x82;TR0=1;break;
case 2:IE=0x00;TR0=0;break;
case 0:P0=0x3f;P2=0x3f;i=0;second_count=0;
}
}
}
int main(void)
{
P0=0x3f;
P2=0x3f;
i=0;
second_count=0;
key_flag_idx=0;
key_state=1;
TMOD=0x01; //定时器0方法1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
while(1)
{
if(key_state!=K1)
{
delayms(10);
key_state=K1;
key_event_handle();
}
}
}
void display_refresh() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(++i==2) //50ms*2=0.1s 0.1s改写一次
{
i=0;
second_count++;
P0=dsy_code[second_count/10];
P2=dsy_code[second_count%10];
if(second_count==100) second_count=0;
}
}