📄 timer.h
字号:
#ifndef __TIMER_H__
#define __TIMER_H__
#include "AT89S51.h"
#include <stdio.h>
#include <intrins.h>
#include "datatype.h"
/*///////////////////////////////////////////////////////////////////////////
//// TMOD
/ Timer1 / Timer0
/ (b7) (b6) (b5) (b4) / (b3) (b2) (b1) (b0)
/ Gate C/T M1 M0 / Gate C/T M1 M0
/ Gate = 1: INT and TR0=1, Timer active.
/ Gate = 0: TR0=1, Timer active.
/ C/T=1: as Counter.
/ C/T=0: as Timer.
/ M1/M0
/ 0 0 :Mode 0: as 13bit Timer/Counter.
/ 0 1 :Mode 1: as 16bit Timer/Counter.
/ 1 0 :Mode 2: as 8bit Timer/Counter, auto-reload.
/ 1 1 :Mode 3: as two 8bit Timer/Counter.
//////////////////////////////////////////////////////////////////////////*/
#define XTAL_KHz 11059.2
#define UART_9600 (256-(int)(1*XTAL_KHz*1000/384/9600))
#define UART_19200 (256-(int)(1*XTAL_KHz*1000/384/19200))
#define UART_38400 (256-(int)(1*XTAL_KHz*1000/384/38400))
#define TM0_M0_COUNT 5000
#define TM0_M0_TH ((8192-TM0_M0_COUNT)/32)
#define TM0_M0_TL ((8192-TM0_M0_COUNT)%32)
#define TM0_M1_COUNT 50000
#define TM0_M1_TH ((65536-TM0_M1_COUNT)/256)
#define TM0_M1_TL ((65536-TM0_M1_COUNT)%256)
#define TM0_M2_1s 4246//4225//5000
#define TM0_M2_COUNT 217
#define TM0_M2_TH (256-TM0_M2_COUNT)
#define TM0_M2_TL (256-TM0_M2_COUNT)
#define TM1_M0_COUNT 5000
#define TM1_M0_TH ((8192-TM1_M0_COUNT)/32)
#define TM1_M0_TL ((8192-TM1_M0_COUNT)%32)
#define TM1_M1_COUNT 50000
#define TM1_M1_TH ((65536-TM1_M1_COUNT)/256)
#define TM1_M1_TL ((65536-TM1_M1_COUNT)%256)
#define TM1_M2_1s 4900//5000
#define TM1_M2_COUNT 217
#define TM1_M2_TH (256-TM1_M2_COUNT)
#define TM1_M2_TL (256-TM1_M2_COUNT)
///////////////////////////////////////////////////////////////////////////
//Timer.c declaration
void fnTM_Timer0ISREn(void);
void fnTM_Timer0M2Start(void);
void fnTM_Counter1ISREn(void);
void fnTM_Counter1M1Start(void);
///////////////////////////////////////////////////////////////////////////
//Variable declaration
#endif//__TIMER_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -