找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1182|回复: 0
打印 上一主题 下一主题
收起左侧

一个51单片机头文件defType.h 定义了T0,T1, INT0,INT1的一下操作

[复制链接]
跳转到指定楼层
楼主
该头文件定义了T0,T1, INT0,INT1的一下操作,方便使用

单片机头文件源程序如下:
  1. #include "intrins.h"

  2. //#define MAIN_Fosc        22118400L        //定义主时钟
  3. #define MAIN_Fosc   6000000L        //定义主时钟
  4. //#define MAIN_Fosc   11059200L        //定义主时钟
  5. //#define MAIN_Fosc   5529600L        //定义主时钟
  6. //#define MAIN_Fosc   24000000L        //定义主时钟
  7. #define MAIN_Fosc_KHz    6000  //晶振频率,khz
  8. #define MAIN_Fosc_MHz    6  //晶振频率,

  9. /**********************************/
  10. typedef unsigned char        u8;
  11. typedef unsigned int        u16;
  12. typedef unsigned long        u32;

  13. typedef unsigned char        uchar;
  14. typedef unsigned int        uint;
  15. typedef unsigned long        ulong;

  16. typedef  char bool ;
  17. #define        TRUE        1
  18. #define        FALSE        0

  19. #define        ENABLE                1
  20. #define        DISABLE                0
  21. //==================
  22. #define NO_MATTER   0
  23. #define        LOW                0       
  24. #define        HIGH        1       


  25. void delay(uchar n)
  26. {
  27.    uchar i=n;
  28.    while(i--);
  29. }


  30. // 防抖按键函数
  31. //p        是一个按键位,如p1_1
  32. //exec 是执行语句
  33. #define KeyPress(p,exec) if(p== 0)   \
  34.    { \
  35.      delay(200);  \
  36.      if(p== 0) \
  37.       exec;\
  38.           while(p== 0); \
  39.    }
  40. //=====================

  41. //t0 t1
  42. #define        T0_13bit        TMOD &= 0xfc
  43. #define        T0_16bit        TMOD |= 0x01//16位
  44. #define        T0_8bitAutoReload        TMOD |= 0x02//8位自动重装
  45. #define        T0_IsTimer        TMOD &= 0xfb        //时器0用做定时器
  46. #define        T0_IsCounter        TMOD |= 0x04        //时器0用做计数器

  47. #define T0_Run        TR0 = 1                        //允许定时器0计数
  48. #define T0_Stop        TR0 = 0                        //禁止定时器0计数
  49. #define T0_Enable        ET0 = 1                                //允许T1中断.
  50. #define T0_Disable        ET0 = 0                                //禁止T1中断.
  51. #define        T0_Load(n) TH0=(65536-n)/256;TL0=(65536-n)%256 //only for 16bit mode

  52. #define        T1_13bit        TMOD &= 0xcf
  53. #define        T1_16bit        TMOD |= 0x10//16位
  54. #define        T1_8bitAutoReload        TMOD |= 0x20//8位自动重装
  55. #define        T1_IsTimer        TMOD &= 0xbf        //时器0用做定时器
  56. #define        T1_IsCounter        TMOD |= 0x40        //时器0用做定时器

  57. #define T1_Run        TR1 = 1                        //允许定时器0计数
  58. #define T1_Stop        TR1 = 0                        //禁止定时器0计数
  59. #define T1_Enable        ET1 = 1                                //允许T1中断.
  60. #define T1_Disable        ET1 = 0                                //禁止T1中断.
  61. #define        T1_Load(n) TH1=(65536-n)/256;TL1=(65536-n)%256 //for 16bit mode

  62. #define EnableAllInt  EA= 1
  63. #define DisableAllInt  EA= 0

  64. //INT0 INT1
  65. #define INT0_Enable  EX0= 1
  66. #define INT1_Enable  EX1= 1
  67. #define INT0_Disable  EX0= 0
  68. #define INT1_Disable  EX1= 0

  69. /*   interrupt number */
  70. #define        INT0_INTERRUPT         interrupt 0
  71. #define        T0_INTERRUPT     interrupt        1
  72. #define        INT1_INTERRUPT         interrupt 2
  73. #define        T1_INTERRUPT         interrupt    3
  74. #define        UART1_INTERRUPT        interrupt 4
  75. #define        ADC_INTERRUPT        interrupt         5
  76. #define        LVD_INTERRUPT        interrupt         6
  77. #define        PCA_INTERRUPT        interrupt         7
  78. #define        ART2_INTERRUPT        interrupt 8
  79. #define        SPI_INTERRUPT        interrupt         9
  80. #define        INT2_INTERRUPT        interrupt 10
  81. #define        INT3_INTERRUPT        interrupt 11
  82. #define        TIMER2_INTERRUPT        interrupt 12
  83. #define        INT4_INTERRUPT        interrupt 16
  84. #define        UART3_INTERRUPT        interrupt 17
  85. #define        UART4_INTERRUPT        interrupt 18
  86. #define        TIMER3_INTERRUPT        interrupt 19
  87. #define        TIMER4_INTERRUPT        interrupt 20

  88. /***********************************/
  89. #define NOP  _nop_()
  90. #define NOP2 _nop_();_nop_()
  91. #define NOP3 _nop_();_nop_();_nop_()
  92. #define NOP4 _nop_();_nop_();_nop_();_nop_()
  93. #define NOP6 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
  94. #define NOP8 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
  95. #define NOP10 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
  96. #define NOP12 NOP6;NOP6
  97. #define NOP14 NOP8;NOP6
  98. #define NOP16 NOP8;NOP8
  99. #define NOP18 NOP8;NOP10
  100. #define NOP20 NOP10;NOP10
  101. #define NOP22 NOP10;NOP10;NOP2
  102. #define NOP24 NOP10;NOP10;NOP4
  103. #define NOP26 NOP10;NOP10;NOP6
  104. #define NOP28 NOP10;NOP10;NOP8
  105. #define NOP30 NOP10;NOP10;NOP10
  106. #define NOP32 NOP10;NOP10;NOP10;NOP2
  107. #define NOP34 NOP10;NOP10;NOP10;NOP4
  108. #define NOP36 NOP10;NOP10;NOP10;NOP6
  109. #define NOP38 NOP10;NOP10;NOP10;NOP8
  110. #define NOP40 NOP10;NOP10;NOP10;NOP10
  111. #define NOP42 NOP10;NOP10;NOP10;NOP10;NOP2
  112. #define NOP44 NOP10;NOP10;NOP10;NOP10;NOP4
  113. #define NOP46 NOP10;NOP10;NOP10;NOP10;NOP6
  114. #define NOP48 NOP10;NOP10;NOP10;NOP10;NOP8
  115. #define NOP50 NOP10;NOP10;NOP10;NOP10;NOP10
  116. #define NOP52 NOP10;NOP10;NOP10;NOP10;NOP10;NOP2
  117. #define NOP54 NOP10;NOP10;NOP10;NOP10;NOP10;NOP4
  118. #define NOP56 NOP10;NOP10;NOP10;NOP10;NOP10;NOP6
  119. #define NOP58 NOP10;NOP10;NOP10;NOP10;NOP10;NOP8
  120. #define NOP60 NOP10;NOP10;NOP10;NOP10;NOP10;NOP10
复制代码

以上代码打包下载: defType.rar (1.18 KB, 下载次数: 4)

评分

参与人数 1黑币 +40 收起 理由
admin + 40 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表