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