单片机倒计时程序试运行
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp,bai,shi,ge,num;
sbit p12=P1^2;
sbit p11=P1^1;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
void main()
{
temp=60;
num=0;
P1=0xff;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
shi=temp/10;
ge=temp%10;
P2=table[shi];
P1=0xbf;
delay(2);
P2=table[ge];
P1=0x7f;
delay(2);
}
}
void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
if(num==20)
{
num=0;
temp--;
if(temp==0)
{
temp=60;
p12=~p12;
p11=~p11;
delay(900);
}
}
}
楼主最近还看过