#include "reg51.h"
#define uint unsinged int
#define uchar unsigned char
unsigned char code d[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //共阴0~9字形码
unsigned char timer=0,second=0,key=0,c=0;
/*void delay(int s)
{ uchar i,j;
for(i=0;i<s;i++) //延时函数
for(j=114;j>0;j--);
} */
delay()
{uchar i,j;for(i=0;i<10;i++)for(j=0;j<150;j++);} //void delay(void) {unsigned char i; for(i=0;i<200;i++) }
show ()
{
P2=0x01;P0=~d[second/10]; delay(); //w1=1;w2=0;w3=0;
P2=0x02;P0=~d[second%10]; delay(); //w1=0;w2=1;w3=0;
P2=0x08;P0=~d[c%10]; delay(); } //w1=0;w2=0;w3=1; delay();
void main( )
{
TMOD=0x01;
ET0=1;
EA=1;
second=0;
//show ();
while(1)
//判断按键操作
{if((P3&0x08)==0x00) //判断按键是否按下
{key++;
switch(key)
{case 1:TH0=0xee;TL0=0x00;TR0=1;break;
case 2:TR0=0;break;
case 3:key=0;second=0;break;} // show();
while((P3&0x08)==0x00);}//按键消抖
}
}
void int_T0( ) interrupt 1 using 0 //
{TH0=0xee;TL0=0x00;
timer++;
if(timer==200)
{timer=0;second++;show();} //
if(second==59)
{TR0=1;second=0;c++;}
if(c==3)TR0=0;
}
|