HML_FwLib_STC89使用笔记(单片机课程补充资料)

举报
zhangrelay 发表于 2021/07/15 00:56:06 2021/07/15
【摘要】 HML_FwLib_STC89适用于Linux和Windows,并且可以直接全功能支持STC89C52RC等芯片全部功能,并非如keil4的<reg52.h>或sdcc中<8052.h>的基本功能。 先看一段示例,如下程序符合现在主流的编程规范: /**************************************************...

HML_FwLib_STC89适用于Linux和Windows,并且可以直接全功能支持STC89C52RC等芯片全部功能,并非如keil4的<reg52.h>或sdcc中<8052.h>的基本功能。

先看一段示例,如下程序符合现在主流的编程规范:


  
  1. /*****************************************************************************
  2. * 头文件 *
  3. *****************************************************************************/
  4. #include "hml/hml.h"
  5. /*****************************************************************************
  6. * 初始化 *
  7. *****************************************************************************/
  8. void sys_init(void)
  9. {
  10. UART_configTypeDef uc;
  11. uc.baudrate = 9600;
  12. uc.baudGenerator = PERIPH_TIM_2;
  13. uc.interruptState = DISABLE;
  14. uc.interruptPriority = UTIL_interruptPriority_0;
  15. uc.mode = UART_mode_1;
  16. uc.multiBaudrate = DISABLE;
  17. uc.receiveState = ENABLE;
  18. UART_config(&uc);
  19. enableAllInterrupts();
  20. }
  21. /*****************************************************************************
  22. * 主函数 *
  23. *****************************************************************************/
  24. void main(void)
  25. {
  26. sys_init();
  27. while(true)
  28. {
  29. /* send per 1000ms */
  30. sleep(1000);
  31. UART_sendString("Welcome to Changshu Institute of Technology.\r\n");
  32. /* send per 1000ms */
  33. sleep(1000);
  34. UART_sendString("Let us start the MCU learning journey together.\r\n");
  35. }
  36. }

编译和下载:

  • make -j
  • stcgal -P stc89 output.ihx
  • 或者(stcgal -P stc89 output.hex)与上面一条指令效果相同

程序功能每间隔1s,发送:

  1. Welcome to Changshu Institute of Technology.
  2. Let us start the MCU learning journey together.

使用串口工具看看效果吧:


在usr直接使用make -j编译即可使用,生成ihx和hex均可下载:

先编译:

再下载:

支持stc89系列芯片如下:


  
  1. #define MCU_MODEL_GENERIC 0x01
  2. #define MCU_MODEL_STC89C51RC 0x02
  3. #define MCU_MODEL_STC89LE51RC 0x03
  4. #define MCU_MODEL_STC89C52RC 0x04
  5. #define MCU_MODEL_STC89LE52RC 0x05
  6. #define MCU_MODEL_STC89C53RC 0x06
  7. #define MCU_MODEL_STC89LE53RC 0x07
  8. #define MCU_MODEL_STC89C54RDP 0x08
  9. #define MCU_MODEL_STC89LE54RDP 0x09
  10. #define MCU_MODEL_STC89C58RDP 0x0A
  11. #define MCU_MODEL_STC89LE58RDP 0x0B
  12. #define MCU_MODEL_STC89C510RDP 0x0C
  13. #define MCU_MODEL_STC89LE510RDP 0x0D
  14. #define MCU_MODEL_STC89C512RDP 0x0E
  15. #define MCU_MODEL_STC89LE512RDP 0x0F
  16. #define MCU_MODEL_STC89C514RDP 0x10
  17. #define MCU_MODEL_STC89LE514RDP 0x11
  18. #define MCU_MODEL_STC89C516RDP 0x12
  19. #define MCU_MODEL_STC89LE516RDP 0x13

默认为STC89C51RC,11.0592Mhz,12。


  
  1. /**
  2. * \brief configure clock frequency of MCU
  3. */
  4. #ifndef __CONF_FRE_CLKIN
  5. #warning no specified clock frequency, HML will fill it with 11.0592MHz
  6. #define __CONF_FRE_CLKIN 11059200UL
  7. #endif
  8. /**
  9. * \brief configure prescaler of MCU
  10. *
  11. * \note in order to switch 6T/12T mode successfully, user must also do related
  12. * operations via select option inside official <stc-isp> software and restart
  13. * MCU. Otherwise, user can't observe expected phenomenon.
  14. */
  15. #ifndef __CONF_MCU_PRESCALER
  16. #warning no specified MCU prescaler, HML will fill it with 12(12T mode)
  17. #define __CONF_MCU_PRESCALER 12
  18. #endif
  19. /**
  20. * \brief configure module of MCU
  21. */
  22. #ifndef __CONF_MCU_MODEL
  23. #warning no specified MCU model, HML will fill it with STC89C52RC
  24. #define __CONF_MCU_MODEL MCU_MODEL_STC89C52RC
  25. #endif

GPIO直接支持0-4:


  
  1. typedef enum
  2. {
  3. PERIPH_GPIO_0 = 0x0,
  4. PERIPH_GPIO_1 = 0x1,
  5. PERIPH_GPIO_2 = 0x2,
  6. PERIPH_GPIO_3 = 0x3,
  7. PERIPH_GPIO_4 = 0x4
  8. } PERIPH_GPIO;

全面的寄存器信息:


  
  1. /* BYTE Register */
  2. __sfr __at (0x8E) AUXR ;
  3. __sfr __at (0xA2) AUXR1 ;
  4. __sfr __at (0xA9) SADDR1 ;
  5. __sfr __at (0xB7) IPH ;
  6. __sfr __at (0xC0) XICON ;
  7. __sfr __at (0xC8) T2CON ;
  8. __sfr __at (0xC9) T2MOD ;
  9. __sfr __at (0xCA) RCAP2L ;
  10. __sfr __at (0xCB) RCAP2H ;
  11. __sfr __at (0xCC) TL2 ;
  12. __sfr __at (0xCD) TH2 ;
  13. __sfr __at (0xE1) WDT_CONTR ;
  14. __sfr __at (0xE2) ISP_DATA ;
  15. __sfr __at (0xE3) ISP_ADDRH ;
  16. __sfr __at (0xE4) ISP_ADDRL ;
  17. __sfr __at (0xE5) ISP_CMD ;
  18. __sfr __at (0xE6) ISP_TRIG ;
  19. __sfr __at (0xE7) ISP_CONTR ;
  20. __sfr __at (0xE8) P4 ;
  21. /* BIT Register */
  22. /* IE */
  23. __sbit __at (0xAD) ET2 ;
  24. /* IP */
  25. __sbit __at (0xBD) PT2 ;
  26. /* P1 */
  27. __sbit __at (0x90) T2 ; /* AFIO */
  28. __sbit __at (0x91) T2EX ; /* AFIO */
  29. /* P4 */
  30. __sbit __at (0xE8) P4_0 ;
  31. __sbit __at (0xE9) P4_1 ;
  32. __sbit __at (0xEA) P4_2 ;
  33. __sbit __at (0xEB) P4_3 ;
  34. __sbit __at (0xEA) INT3 ;
  35. __sbit __at (0xEB) INT2 ;
  36. /* T2CON */
  37. __sbit __at (0xC8) CPRL2 ;
  38. __sbit __at (0xC9) T2_CT ;
  39. __sbit __at (0xCA) TR2 ;
  40. __sbit __at (0xCB) EXEN2 ;
  41. __sbit __at (0xCC) TCLK ;
  42. __sbit __at (0xCD) RCLK ;
  43. __sbit __at (0xCE) EXF2 ;
  44. __sbit __at (0xCF) TF2 ;
  45. /* XICON */
  46. __sbit __at (0xC0) IT2 ;
  47. __sbit __at (0xC1) IE2 ;
  48. __sbit __at (0xC2) EX2 ;
  49. __sbit __at (0xC3) PX2 ;
  50. __sbit __at (0xC4) IT3 ;
  51. __sbit __at (0xC5) IE3 ;
  52. __sbit __at (0xC6) EX3 ;
  53. __sbit __at (0xC7) PX3 ;
  54. /* BIT number for bits that are not directly accessible */
  55. /* AUXR bits */
  56. #define BIT_NUM_ALEOFF 0
  57. #define BIT_NUM_EXTRAM 1
  58. /* AUXR1 bits */
  59. #define BIT_NUM_DPS 0
  60. #define BIT_NUM_GF2 3
  61. /* IPH bits */
  62. #define BIT_NUM_PX0H 0
  63. #define BIT_NUM_PT0H 1
  64. #define BIT_NUM_PX1H 2
  65. #define BIT_NUM_PT1H 3
  66. #define BIT_NUM_PSH 4
  67. #define BIT_NUM_PT2H 5
  68. #define BIT_NUM_PX2H 6
  69. #define BIT_NUM_PX3H 7
  70. /* ISP_CMD bits */
  71. #define BIT_NUM_MS0 0
  72. #define BIT_NUM_MS1 1
  73. #define BIT_NUM_MS2 2
  74. /* ISP_CONTR bits */
  75. #define BIT_NUM_WT0 0
  76. #define BIT_NUM_WT1 1
  77. #define BIT_NUM_WT2 2
  78. #define BIT_NUM_SWRST 5
  79. #define BIT_NUM_SWBS 6
  80. #define BIT_NUM_ISPEN 7
  81. /* PCON bits */
  82. #define BIT_NUM_IDL 0
  83. #define BIT_NUM_PD 1
  84. #define BIT_NUM_GF0 2
  85. #define BIT_NUM_GF1 3
  86. #define BIT_NUM_POF 4
  87. #define BIT_NUM_SMOD0 6
  88. #define BIT_NUM_SMOD 7
  89. /* T2MOD bits */
  90. #define BIT_NUM_DCEN 0
  91. #define BIT_NUM_T2OE 1
  92. /* TMOD bits */
  93. #define BIT_NUM_T0_M0 0
  94. #define BIT_NUM_T0_M1 1
  95. #define BIT_NUM_T0_CT 2
  96. #define BIT_NUM_T0_GATE 3
  97. #define BIT_NUM_T1_M0 4
  98. #define BIT_NUM_T1_M1 5
  99. #define BIT_NUM_T1_CT 6
  100. #define BIT_NUM_T1_GATE 7
  101. /* WDT_CONTR bits */
  102. #define BIT_NUM_PS0 0
  103. #define BIT_NUM_PS1 1
  104. #define BIT_NUM_PS2 2
  105. #define BIT_NUM_IDLE_WDT 3
  106. #define BIT_NUM_CLR_WDT 4
  107. #define BIT_NUM_EN_WDT 5
  108. /* BIT definitions for bits that are not directly accessible */
  109. /* AUXR bits */
  110. #define ALEOFF BIT_MASK(BIT_NUM_ALEOFF)
  111. #define EXTRAM BIT_MASK(BIT_NUM_EXTRAM)
  112. /* AUXR1 bits */
  113. #define DPS BIT_MASK(BIT_NUM_DPS) /* DPTR register select bit */
  114. #define GF2 BIT_MASK(BIT_NUM_GF2)
  115. /* IPH bits */
  116. #define PX0H BIT_MASK(BIT_NUM_PX0H)
  117. #define PT0H BIT_MASK(BIT_NUM_PT0H)
  118. #define PX1H BIT_MASK(BIT_NUM_PX1H)
  119. #define PT1H BIT_MASK(BIT_NUM_PT1H)
  120. #define PSH BIT_MASK(BIT_NUM_PSH)
  121. #define PT2H BIT_MASK(BIT_NUM_PT2H)
  122. #define PX2H BIT_MASK(BIT_NUM_PX2H)
  123. #define PX3H BIT_MASK(BIT_NUM_PX3H)
  124. /* ISP_CMD bits */
  125. #define MS0 BIT_MASK(BIT_NUM_MS0)
  126. #define MS1 BIT_MASK(BIT_NUM_MS1)
  127. #define MS2 BIT_MASK(BIT_NUM_MS2)
  128. /* ISP_CONTR bits */
  129. #define WT0 BIT_MASK(BIT_NUM_WT0)
  130. #define WT1 BIT_MASK(BIT_NUM_WT1)
  131. #define WT2 BIT_MASK(BIT_NUM_WT2)
  132. #define SWRST BIT_MASK(BIT_NUM_SWRST)
  133. #define SWBS BIT_MASK(BIT_NUM_SWBS)
  134. #define ISPEN BIT_MASK(BIT_NUM_ISPEN)
  135. /* PCON bits */
  136. #define POF BIT_MASK(BIT_NUM_POF)
  137. #define SMOD0 BIT_MASK(BIT_NUM_SMOD0)
  138. /* T2MOD bits */
  139. #define DCEN BIT_MASK(BIT_NUM_DCEN)
  140. #define T2OE BIT_MASK(BIT_NUM_T2OE)
  141. /* WDT_CONTR bits */
  142. #define PS0 BIT_MASK(BIT_NUM_PS0)
  143. #define PS1 BIT_MASK(BIT_NUM_PS1)
  144. #define PS2 BIT_MASK(BIT_NUM_PS2)
  145. #define IDLE_WDT BIT_MASK(BIT_NUM_IDLE_WDT)
  146. #define CLR_WDT BIT_MASK(BIT_NUM_CLR_WDT)
  147. #define EN_WDT BIT_MASK(BIT_NUM_EN_WDT)
  148. /* Interrupt numbers: address = (number * 8) + 3 */
  149. #define TF2_VECTOR 5 /* 0x2b timer 2 */
  150. #define IE2_VECTOR 6 /* 0x33 external interrupt 2 */
  151. #define IE3_VECTOR 7 /* 0x3B external interrupt 3 */
  152. #endif

更多详细内容,参考HML_FwLib_STC89源码。


 

文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。

原文链接:zhangrelay.blog.csdn.net/article/details/109196577

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。