C51 COMPILER V9.60.0.0 UART 03/28/2026 16:50:46 PAGE 1 C51 COMPILER V9.60.0.0, COMPILATION OF MODULE UART OBJECT MODULE PLACED IN .\hex\uart.obj COMPILER INVOKED BY: C:\keil5\C51\BIN\C51.EXE Library\Sources\uart.c OMF2 OPTIMIZE(9,SIZE) BROWSE DEBUG PRINT(.\lst\uart -.lst) TABS(2) OBJECT(.\hex\uart.obj) line level source 1 #ifndef _UART_C_ 2 #define _UART_C_ 3 #include "ca51f5_config.h" 4 #include "../../includes/ca51f5sfr.h" 5 #include "../../includes/ca51f5xsfr.h" 6 #include "../../includes/gpiodef_f5.h" 7 #include "../../includes/system.h" 8 9 #include "../../Library/includes/uart.h" 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 /********************************************************************************************************* -************/ 17 /********************************************************************************************************* -************/ 18 #ifdef UART0_EN /********************************************************************************************************* -************ 注意:以下波特率配置参数前提条件是系统时钟为16MHz,如果修改系统时钟频率,波特率配置参数须另行计算。 ********************************************************************************************************** -*************/ void Uart0_Initial(unsigned long int baudrate) { code unsigned long int BR_TAB[]= { 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, }; code unsigned int BR_SET_TAB[][2]= { {416,31}, {208,31}, {104,31}, {52,31}, {26,31}, {13,31}, {10,27}, {5,27}, }; unsigned int value_temp; unsigned char i; uart0_send.head = 0; uart0_send.tail = 0; C51 COMPILER V9.60.0.0 UART 03/28/2026 16:50:46 PAGE 2 uart0_rev.head = 0; uart0_rev.tail = 0; uart0_tx_flag = 0; GPIO_Init(P31F,P31_UART0_RX_SETTING); GPIO_Init(P30F,P30_UART0_TX_SETTING); for(i=0;i>8); T2CL = (unsigned char)(value_temp); TH2 = (unsigned char)(value_temp>>8); TL2 = (unsigned char)(value_temp);; TR2 = 1; S0CON = 0x50; ES0 = 1; } void Uart0_PutChar(unsigned char bdat) { unsigned char free_space; unsigned char tail_tmp; while(1) { tail_tmp = uart0_send.tail; if(uart0_send.head < tail_tmp) { free_space = tail_tmp - uart0_send.head; } else { free_space = UART0_TX_BUF_SIZE + tail_tmp - uart0_send.head; } if(free_space > 1) { ES0 = 0; uart0_send.head++; uart0_send.head %= UART0_TX_BUF_SIZE; uart0_tx_buf[uart0_send.head] = bdat; if(!uart0_tx_flag) { ES0 = 1; uart0_send.tail++; uart0_send.tail %= UART0_TX_BUF_SIZE; S0BUF=uart0_tx_buf[uart0_send.tail]; uart0_tx_flag = 1; } else { ES0 = 1; } break; C51 COMPILER V9.60.0.0 UART 03/28/2026 16:50:46 PAGE 3 } } } void UART0_RX_ISR (void) { RI0 = 0; uart0_rev.head++; uart0_rev.head %= UART0_RX_BUF_SIZE; uart0_rx_buf[uart0_rev.head]=S0BUF; } void UART0_TX_ISR (void) { TI0 = 0; if(uart0_send.head!=uart0_send.tail) { uart0_send.tail++; uart0_send.tail %= UART0_TX_BUF_SIZE; S0BUF=uart0_tx_buf[uart0_send.tail]; } else { uart0_tx_flag=0; } } #endif 138 /********************************************************************************************************* -************/ 139 #endif MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = ---- ---- CONSTANT SIZE = ---- ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = ---- ---- 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)