单片机10秒倒计时的炸弹。。。。。bomb!!!!!!

  #include <reg52.h>


sbit LATCH_bit = P2^3;
sbit LATCH_seg = P2^2;
sbit SPK=P0^2;
unsigned int LED[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90/*,0x88,0x83,0xc6,0xa1,0x86,0x8e*/};
void delay(int n);
void DelayMs(unsigned char t);
void DelayUs2x(unsigned char t);//函数声明 
unsigned char misec_10;
unsigned char sec;


void main()
{  
    unsigned int i;
TMOD = 0x01;
TH0 = 0xd8;
TL0 = 0xf0;
    EA = 1;
ET0 = 1;
TR0 = 1;
misec_10 = 0;
sec = 10;
    while(1)
{


         P1 = 0xfb;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[misec_10/10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);


P1 = 0xf7;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[misec_10%10];

LATCH_seg = 1;
LATCH_seg = 0;
delay(200);


    P1 = 0xfe;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[sec/10];
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);


P1 = 0xfd;
LATCH_bit = 1;
LATCH_bit = 0;
P1 = ~LED[sec%10];
P1 += 0x80;
LATCH_seg = 1;
LATCH_seg = 0;
delay(200);




if(misec_10 == 0)
{
    misec_10 = 99;
sec--;


    DelayUs2x(200); 
DelayUs2x(200); 
SPK=!SPK; 


if(sec == 255)
{
    sec = 10;
for(i=0;i<500;i++)
     {
     DelayMs(1);  
 SPK=!SPK;
 }
 delay(3000);
}
}
}
}


void delay(int n)
{
while(n--);
}


void TSR_T0(void) interrupt 1
{
TH0 = 0xd8;
TL0 = 0xf0; //0xd8f0 == 55536
misec_10--;
}


void DelayMs(unsigned char t)
{
     
 while(t--)
 {
     //大致延时1mS
     DelayUs2x(245);
DelayUs2x(245);
 }
}


void DelayUs2x(unsigned char t)
{   
 while(--t);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值