#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code S[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar n1,n2,n;
sbit led=P1^0;
delay(uint i)//延时1毫秒
{
uchar t;
while(i--)
{
for(t=0;t<115;t++);
}
}
timer0()//定时器初始化
{
TMOD=0x11;
TH0 = 0xdc;
TL0 = 0x00;
TH1 = 0x4c;
TL1 = 0x00;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=1;
}
led0()//led灯闪烁
{
if(n1==20)
{
n1=0;
led=~led;
}
}
smg()//数码管显示
{
if(n2==20)
{
n2=0;
n++;
if(n==60)//60秒计时
n=0;
P2=0xbf;//个位
P0=S[n/10];
//delay(5);
P2=0x7f;//十位
P0=S[n%10];
delay(5);
}
}
main()
{
timer0();
while(1)
{
led0();
smg();
}
}
void t0() interrupt 1
{
TH0 = 0xdc;
TL0 = 0x00;
n1++;
}
t1() interrupt 3
{
TH1 = 0x4c;
TL1 = 0x00;
n2++;
}
一周热门 更多>