uart.lst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. C51 COMPILER V9.60.7.0 UART 11/21/2025 17:21:11 PAGE 1
  2. C51 COMPILER V9.60.7.0, COMPILATION OF MODULE UART
  3. OBJECT MODULE PLACED IN .\Objects\uart.obj
  4. COMPILER INVOKED BY: d:\Keil_v5\C51\BIN\C51.EXE ..\..\..\..\driver\src\uart.c OBJECTADVANCED OPTIMIZE(9,SPEED) BROWSE OR
  5. -DER NOAREGS MODC2 INCDIR(..\..\..\..\driver\inc;..\..\..\..\mcu;..\..\..\..\middleware\log;..\..\..\..\middleware\delay;
  6. -..\..\..\..\middleware\rf_basis) DEBUG PRINT(.\Listings\uart.lst) TABS(2) OBJECT(.\Objects\uart.obj)
  7. line level source
  8. 1 /**
  9. 2 ************************************************************************
  10. 3 * @file uart.c
  11. 4 * @author Panchip Team
  12. 5 * @version V0.5
  13. 6 * @date 2024-04-28
  14. 7 * @brief This file provides all the uart firmware functions.
  15. 8 * @note
  16. 9 * Copyright (C) 2024 Panchip Technology Corp. All rights reserved.
  17. 10 ****************************************************************************
  18. 11 */
  19. 12
  20. 13 #include "uart.h"
  21. 14
  22. 15 /** @addtogroup PAN262x_Std_Driver
  23. 16 * @{
  24. 17 */
  25. 18
  26. 19 /** @defgroup UART
  27. 20 * @brief UART driver modules
  28. 21 * @{
  29. 22 */
  30. 23
  31. 24 /** @defgroup UART_Private_Functions
  32. 25 * @{
  33. 26 */
  34. 27
  35. 28 /**
  36. 29 * @brief Initializes the UART0 peripheral according to the specified parameters.
  37. 30 * @param DataBits: data bits
  38. 31 * @arg: LENGTH_8
  39. 32 * @arg: LENGTH_9
  40. 33 * @param RxIRQEn: which can be 1 to enable receive or 0 to disable receive.
  41. 34 * @arg: ENABLE_RX
  42. 35 * @arg: DISABLE_RX
  43. 36 * @param Parity: which can be 1 to enable parity check or 0 to disable parity check.
  44. 37 * @arg: ENABLE_PAR
  45. 38 * @arg: DISABLE_PAR
  46. 39 * @param BaudRate: baudrate of uart
  47. 40 * @arg: BAUD_1200
  48. 41 * @arg: BAUD_2400
  49. 42 * @arg: BAUD_4800
  50. 43 * @arg: BAUD_9600
  51. 44 * @arg: BAUD_14400
  52. 45 * @arg: BAUD_19200
  53. 46 * @arg: BAUD_38400
  54. 47 * @arg: BAUD_115200(Note:TIMER1 will be used by uart)
  55. 48 * @retval None
  56. 49 */
  57. 50 void UART_Init(u8 DataBits, u8 RxIRQEn, u8 Parity, u8 BaudRate)
  58. 51 {
  59. 52 1 S0CON = (DataBits | RxIRQEn | Parity);
  60. 53 1 switch (BaudRate)
  61. C51 COMPILER V9.60.7.0 UART 11/21/2025 17:21:11 PAGE 2
  62. 54 1 {
  63. 55 2 case BAUD_1200:
  64. 56 2 ADCON = BAUD_RCH;
  65. 57 2 PCON |= BAUD_SMOD;
  66. 58 2 S0RELH = 0x02;
  67. 59 2 S0RELL = 0x5F;
  68. 60 2 break;
  69. 61 2 case BAUD_2400:
  70. 62 2 ADCON = BAUD_RCH;
  71. 63 2 PCON |= BAUD_SMOD;
  72. 64 2 S0RELH = 0x03;
  73. 65 2 S0RELL = 0x30;
  74. 66 2 break;
  75. 67 2 case BAUD_4800:
  76. 68 2 ADCON = BAUD_RCH;
  77. 69 2 PCON |= BAUD_SMOD;
  78. 70 2 S0RELH = 0x03;
  79. 71 2 S0RELL = 0x98;
  80. 72 2 break;
  81. 73 2 case BAUD_9600:
  82. 74 2 ADCON = BAUD_RCH;
  83. 75 2 PCON |= BAUD_SMOD;
  84. 76 2 S0RELH = 0x03;
  85. 77 2 S0RELL = 0xCC;
  86. 78 2 break;
  87. 79 2 case BAUD_14400:
  88. 80 2 TMOD = TIMER1_MODE_2;
  89. 81 2 TH1 = 0xF7;
  90. 82 2 TL1 = 0xF7;
  91. 83 2 TCON |= TIMER1_STR;
  92. 84 2 ADCON = BAUD_TIMER1 | TIMER1_DIV_3;
  93. 85 2 PCON |= BAUD_SMOD;
  94. 86 2 break;
  95. 87 2 case BAUD_19200:
  96. 88 2 ADCON = BAUD_RCH;
  97. 89 2 PCON |= BAUD_SMOD;
  98. 90 2 S0RELH = 0x03;
  99. 91 2 S0RELL = 0xE6;
  100. 92 2 break;
  101. 93 2 case BAUD_38400:
  102. 94 2 ADCON = BAUD_RCH;
  103. 95 2 PCON |= BAUD_SMOD;
  104. 96 2 S0RELH = 0x03;
  105. 97 2 S0RELL = 0xF3;
  106. 98 2 break;
  107. 99 2 case BAUD_115200:
  108. 100 2 TMOD = TIMER1_MODE_2;
  109. 101 2 TH1 = 0xFD;
  110. 102 2 TL1 = 0xFD;
  111. 103 2 TCON |= TIMER1_STR;
  112. 104 2 ADCON = BAUD_TIMER1 | TIMER1_DIV_3;
  113. 105 2 PCON |= BAUD_SMOD;
  114. 106 2 break;
  115. 107 2 default:
  116. 108 2 break;
  117. 109 2 }
  118. 110 1 }
  119. 111
  120. 112 /**
  121. 113 * @brief This function enable UART interrupt
  122. 114 * @param None
  123. 115 * @retval None
  124. C51 COMPILER V9.60.7.0 UART 11/21/2025 17:21:11 PAGE 3
  125. 116 */
  126. 117 void UART_EnableIRQ(void)
  127. 118 {
  128. 119 1 EUART = TRUE;
  129. 120 1 }
  130. 121
  131. 122 /**
  132. 123 * @brief This function disenable UART interrupt
  133. 124 * @param None
  134. 125 * @retval None
  135. 126 */
  136. 127 void UART_DisableIRQ(void)
  137. 128 {
  138. 129 1 EUART = FALSE;
  139. 130 1 }
  140. 131
  141. 132 /**
  142. 133 * @brief This function send one byte by UART
  143. 134 * @param uDat
  144. 135 * @retval None
  145. 136 */
  146. 137 void UART_SendOneByte(u8 Byte)
  147. 138 {
  148. 139 1 S0BUF = Byte;
  149. 140 1 while (!S0CON_TI0);
  150. 141 1 S0CON_TI0 = 0;
  151. 142 1 }
  152. 143
  153. 144 /**
  154. 145 * @brief This function send one char UART
  155. 146 * @param c: charicter
  156. 147 * @retval None
  157. 148 */
  158. 149 char UART_PutChar(char c)
  159. 150 {
  160. 151 1 UART_SendOneByte(c);
  161. 152 1 return c;
  162. 153 1 }
  163. 154
  164. 155 /**
  165. 156 * @brief This function send string by UART
  166. 157 * @param upStr
  167. 158 * @retval None
  168. 159 */
  169. 160 void UART_SendString(u8 *String)
  170. 161 {
  171. 162 1 while (*String)
  172. 163 1 {
  173. 164 2 UART_SendOneByte(*String++);
  174. 165 2 }
  175. 166 1 }
  176. 167
  177. 168 /**
  178. 169 * @brief This function send buffer by UART
  179. 170 * @param buffer: buffer address
  180. 171 * @param len: buffer length
  181. 172 * @return Length of data sent
  182. 173 */
  183. 174 int UART_sendBuf(u8 *buffer, int len)
  184. 175 {
  185. 176 1 int i = 0;
  186. 177 1
  187. C51 COMPILER V9.60.7.0 UART 11/21/2025 17:21:11 PAGE 4
  188. 178 1 while (i < len)
  189. 179 1 {
  190. 180 2 UART_SendOneByte(buffer[i++]);
  191. 181 2 }
  192. 182 1
  193. 183 1 return len;
  194. 184 1 }
  195. 185
  196. 186 /**
  197. 187 * @brief This function parity for parity checking the number of processing.
  198. 188 * @param num
  199. 189 * @retval true or false
  200. 190 */
  201. 191 bool UART_ParityCheck(u8 num)
  202. 192 {
  203. 193 1 bool check = FALSE;
  204. 194 1
  205. 195 1 while (num)
  206. 196 1 {
  207. 197 2 check = !check;
  208. 198 2 num = num & (num - 1);
  209. 199 2 }
  210. 200 1
  211. 201 1 if (check)
  212. 202 1 S0CON |= TB80;
  213. 203 1 else
  214. 204 1 S0CON &= ~TB80;
  215. 205 1
  216. 206 1 return check;
  217. 207 1 }
  218. 208
  219. 209 /**
  220. 210 * @brief This function parity for odd checking the number of processing.
  221. 211 * @param num
  222. 212 * @retval true or false
  223. 213 */
  224. 214 bool UART_OddCheck(u8 num)
  225. 215 {
  226. 216 1 bool check = FALSE;
  227. 217 1
  228. 218 1 while (num)
  229. 219 1 {
  230. 220 2 check = !check;
  231. 221 2 num = num & (num - 1);
  232. 222 2 }
  233. 223 1
  234. 224 1 if (check)
  235. 225 1 S0CON &= ~TB80;
  236. 226 1 else
  237. 227 1 S0CON |= TB80;
  238. 228 1
  239. 229 1 return check;
  240. 230 1 }
  241. 231
  242. 232 /**
  243. 233 * @brief This function send one char UART
  244. 234 * @param c
  245. 235 * @retval None
  246. 236 */
  247. 237 char putchar(char c)
  248. 238 {
  249. 239 1 S0BUF = c;
  250. C51 COMPILER V9.60.7.0 UART 11/21/2025 17:21:11 PAGE 5
  251. 240 1 while (!S0CON_TI0);
  252. 241 1 S0CON_TI0 = 0;
  253. 242 1 return c;
  254. 243 1 }
  255. 244 /**
  256. 245 * @}
  257. 246 */
  258. 247
  259. 248 /**
  260. 249 * @}
  261. 250 */
  262. 251
  263. 252 /**
  264. 253 * @}
  265. 254 */
  266. MODULE INFORMATION: STATIC OVERLAYABLE
  267. CODE SIZE = 406 ----
  268. CONSTANT SIZE = ---- ----
  269. XDATA SIZE = ---- ----
  270. PDATA SIZE = ---- ----
  271. DATA SIZE = ---- 12
  272. IDATA SIZE = ---- ----
  273. BIT SIZE = ---- ----
  274. EDATA SIZE = ---- ----
  275. HDATA SIZE = ---- ----
  276. XDATA CONST SIZE = ---- ----
  277. FAR CONST SIZE = ---- ----
  278. END OF MODULE INFORMATION.
  279. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)