标题:
一个51单片机头文件defType.h 定义了T0,T1, INT0,INT1的一下操作
[打印本页]
作者:
himanzj
时间:
2021-11-6 13:35
标题:
一个51单片机头文件defType.h 定义了T0,T1, INT0,INT1的一下操作
该头文件定义了T0,T1, INT0,INT1的一下操作,方便使用
单片机头文件源程序如下:
#include "intrins.h"
//#define MAIN_Fosc 22118400L //定义主时钟
#define MAIN_Fosc 6000000L //定义主时钟
//#define MAIN_Fosc 11059200L //定义主时钟
//#define MAIN_Fosc 5529600L //定义主时钟
//#define MAIN_Fosc 24000000L //定义主时钟
#define MAIN_Fosc_KHz 6000 //晶振频率,khz
#define MAIN_Fosc_MHz 6 //晶振频率,
/**********************************/
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef char bool ;
#define TRUE 1
#define FALSE 0
#define ENABLE 1
#define DISABLE 0
//==================
#define NO_MATTER 0
#define LOW 0
#define HIGH 1
void delay(uchar n)
{
uchar i=n;
while(i--);
}
// 防抖按键函数
//p 是一个按键位,如p1_1
//exec 是执行语句
#define KeyPress(p,exec) if(p== 0) \
{ \
delay(200); \
if(p== 0) \
exec;\
while(p== 0); \
}
//=====================
//t0 t1
#define T0_13bit TMOD &= 0xfc
#define T0_16bit TMOD |= 0x01//16位
#define T0_8bitAutoReload TMOD |= 0x02//8位自动重装
#define T0_IsTimer TMOD &= 0xfb //时器0用做定时器
#define T0_IsCounter TMOD |= 0x04 //时器0用做计数器
#define T0_Run TR0 = 1 //允许定时器0计数
#define T0_Stop TR0 = 0 //禁止定时器0计数
#define T0_Enable ET0 = 1 //允许T1中断.
#define T0_Disable ET0 = 0 //禁止T1中断.
#define T0_Load(n) TH0=(65536-n)/256;TL0=(65536-n)%256 //only for 16bit mode
#define T1_13bit TMOD &= 0xcf
#define T1_16bit TMOD |= 0x10//16位
#define T1_8bitAutoReload TMOD |= 0x20//8位自动重装
#define T1_IsTimer TMOD &= 0xbf //时器0用做定时器
#define T1_IsCounter TMOD |= 0x40 //时器0用做定时器
#define T1_Run TR1 = 1 //允许定时器0计数
#define T1_Stop TR1 = 0 //禁止定时器0计数
#define T1_Enable ET1 = 1 //允许T1中断.
#define T1_Disable ET1 = 0 //禁止T1中断.
#define T1_Load(n) TH1=(65536-n)/256;TL1=(65536-n)%256 //for 16bit mode
#define EnableAllInt EA= 1
#define DisableAllInt EA= 0
//INT0 INT1
#define INT0_Enable EX0= 1
#define INT1_Enable EX1= 1
#define INT0_Disable EX0= 0
#define INT1_Disable EX1= 0
/* interrupt number */
#define INT0_INTERRUPT interrupt 0
#define T0_INTERRUPT interrupt 1
#define INT1_INTERRUPT interrupt 2
#define T1_INTERRUPT interrupt 3
#define UART1_INTERRUPT interrupt 4
#define ADC_INTERRUPT interrupt 5
#define LVD_INTERRUPT interrupt 6
#define PCA_INTERRUPT interrupt 7
#define ART2_INTERRUPT interrupt 8
#define SPI_INTERRUPT interrupt 9
#define INT2_INTERRUPT interrupt 10
#define INT3_INTERRUPT interrupt 11
#define TIMER2_INTERRUPT interrupt 12
#define INT4_INTERRUPT interrupt 16
#define UART3_INTERRUPT interrupt 17
#define UART4_INTERRUPT interrupt 18
#define TIMER3_INTERRUPT interrupt 19
#define TIMER4_INTERRUPT interrupt 20
/***********************************/
#define NOP _nop_()
#define NOP2 _nop_();_nop_()
#define NOP3 _nop_();_nop_();_nop_()
#define NOP4 _nop_();_nop_();_nop_();_nop_()
#define NOP6 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
#define NOP8 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
#define NOP10 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
#define NOP12 NOP6;NOP6
#define NOP14 NOP8;NOP6
#define NOP16 NOP8;NOP8
#define NOP18 NOP8;NOP10
#define NOP20 NOP10;NOP10
#define NOP22 NOP10;NOP10;NOP2
#define NOP24 NOP10;NOP10;NOP4
#define NOP26 NOP10;NOP10;NOP6
#define NOP28 NOP10;NOP10;NOP8
#define NOP30 NOP10;NOP10;NOP10
#define NOP32 NOP10;NOP10;NOP10;NOP2
#define NOP34 NOP10;NOP10;NOP10;NOP4
#define NOP36 NOP10;NOP10;NOP10;NOP6
#define NOP38 NOP10;NOP10;NOP10;NOP8
#define NOP40 NOP10;NOP10;NOP10;NOP10
#define NOP42 NOP10;NOP10;NOP10;NOP10;NOP2
#define NOP44 NOP10;NOP10;NOP10;NOP10;NOP4
#define NOP46 NOP10;NOP10;NOP10;NOP10;NOP6
#define NOP48 NOP10;NOP10;NOP10;NOP10;NOP8
#define NOP50 NOP10;NOP10;NOP10;NOP10;NOP10
#define NOP52 NOP10;NOP10;NOP10;NOP10;NOP10;NOP2
#define NOP54 NOP10;NOP10;NOP10;NOP10;NOP10;NOP4
#define NOP56 NOP10;NOP10;NOP10;NOP10;NOP10;NOP6
#define NOP58 NOP10;NOP10;NOP10;NOP10;NOP10;NOP8
#define NOP60 NOP10;NOP10;NOP10;NOP10;NOP10;NOP10
复制代码
51hei.png
(2.18 KB, 下载次数: 62)
下载附件
2021-11-6 16:25 上传
以上代码打包下载:
defType.rar
(1.18 KB, 下载次数: 4)
2021-11-6 13:34 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1