uart.lst 10 KB

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