1.功能
倒计时器的设计与制作
2.程序
#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
uchar counter=0;
uchar i=9;
uchar code SEG[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void timer0(void) interrupt 1 using 0
{
TH0=-50000/256;
TL0=-50000%256;
counter++;
if(counter ==40)
{
counter=0;
if(i==16)
i=0;
else
i++;
P0=SEG[i];
}
}
void main(void)
{
P0=SEG[0];
P2=0xef;
TMOD=0X01;
TH0=-50000/256;
TL0=-50000%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{;}
}
3.小结
´本电路实现了0-16正计时,每2s进一位,逢16归0,数码管上第123位显示。