51单片机倒计时 c语言,51单片机60秒倒计时报警

/*------------------------------------------------------------------*/

/* --- STC MCU Limited ---------------------------------------------*/

/* --- STC89-90xx Series 16-bit Timer Demo -------------------------*/

/* --- Mobile: (86)13922805190 -------------------------------------*/

/* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/

/* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/

/* --- Web: www.STCMCU.com -----------------------------------------*/

/* --- Web: www.GXWMCU.com -----------------------------------------*/

/* If you want to use the program or the program referenced in the  */

/* article, please specify in which data and procedures from STC    */

/*------------------------------------------------------------------*/

#include "reg51.h"

typedef unsigned char BYTE;

typedef unsigned int WORD;

//-----------------------------------------------

/* define constants */

#define FOSC 11059200L

#define T1MS (65536-FOSC/12/1000)   //1ms timer calculation method in 12T mode

/* define SFR */

sbit TEST_LED = P1^0;               //work LED, flash once per second

/* define variables */

WORD count;                         //1000 times counter

//-----------------------------------------------

/* Timer0 interrupt routine */

void tm0_isr() interrupt 1 using 1

{

TL0 = T1MS;                     //reload timer0 low byte

TH0 = T1MS >> 8;                //reload timer0 high byte

if (count-- == 0)               //1ms * 1000 -> 1s

{

count = 1000;               //reset counter

TEST_LED = ! TEST_LED;      //work LED flash

}

}

//-----------------------------------------------

/* main program */

void main()

{

TMOD = 0x01;                    //set timer0 as mode1 (16-bit)

TL0 = T1MS;                     //initial timer0 low byte

TH0 = T1MS >> 8;                //initial timer0 high byte

TR0 = 1;                        //timer0 start running

ET0 = 1;                        //enable timer0 interrupt

EA = 1;                         //open global interrupt switch

count = 0;                      //initial counter

while (1);                      //loop

}

这是stc官网上的例程,里面有一秒了,至于怎么倒计时,你自己应该可以搞定吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值