用例程改一下就可以了- /*------------------------------------------------------------------*/
- /* --- STC MCU Limited ---------------------------------------------*/
- /* --- STC89-90xx Series 16-bit Timer Demo -------------------------*/
- /* 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 = 0; //1000 times counter
- BYTE PushCnt = 0;
- /* define IO */
- sbit Fingerprint = P1^0;//自己改
- //-----------------------------------------------
- /* Timer0 interrupt routine */
- void tm0_isr() interrupt 1
- {
- TL0 = T1MS; //reload timer0 low byte
- TH0 = T1MS >> 8; //reload timer0 high byte
- if(!Fingerprint)
- {
- if (count++ >= 1000) //1ms * 1000 -> 1s
- {
- count = 0; //reset counter
- PushCnt++;
- if(PushCnt==1)Unlock1();
- if(PushCnt==2)Unlock2();
- if(PushCnt==3)Unlock3();
- if(PushCnt==4)Unlock4();
- }
- }else{
- count = 0;
- PushCnt = 0;
- }
- }
- //-----------------------------------------------
- /* 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
- Fingerprint = 1;
- while (1); //loop
- }
復制代碼
|