C51 COMPILER V9.02   UART                                                                  12/12/2025 17:29:44 PAGE 1   


C51 COMPILER V9.02, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN .\output\uart.obj
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE source\uart.c OMF2 BROWSE DEBUG PRINT(.\lst\uart.lst) OBJECT(.\output\uart.
                    -obj)

line level    source

   1          #ifndef _UART_C_
   2          #define _UART_C_
   3          #include "include/ca51f_config.h"               
   4          #include "include/ca51f2sfr.h"
   5          #include "include/ca51f2xsfr.h"
   6          #include "include/gpiodef_f2.h"
   7          #include "include/system_clock.h"
   8          
   9          #include "include/uart.h"
  10          #include <intrins.h>
  11          #include <string.h>
  12          #include <stdarg.h>
  13          #include <stdlib.h>
  14          #include <stdio.h>
  15          #include <absacc.h>
  16          /*********************************************************************************************************
             -************/
  17          /*********************************************************************************************************
             -************/
  18          void Uart1_Initial(unsigned long int baudrate)
  19          {
  20   1              unsigned int value_temp;
  21   1      
  22   1              uart1_send.head=0;
  23   1              uart1_send.tail=0;
  24   1              uart1_rev.head=0;
  25   1              uart1_rev.tail=0;
  26   1              uart1_tx_flag=0;
  27   1      
  28   1              value_temp = 0x400 - FOSC/(baudrate*32);
  29   1      
  30   1      
  31   1              GPIO_Init(P67F,P67_UART1_RX_SETTING);
  32   1              GPIO_Init(P66F,P66_UART1_TX_SETTING);
  33   1      
  34   1      
  35   1              S1RELH = (unsigned char)(value_temp>>8);
  36   1              S1RELL = (unsigned char)(value_temp);
  37   1              
  38   1              S1CON = 0xD0;
  39   1              ES1 =   1;      
  40   1      }
  41          void Uart1_PutChar(unsigned char bdat)
  42          {
  43   1              unsigned char free_space;
  44   1              unsigned char tail_tmp;
  45   1              while(1)
  46   1              {               
  47   2                      tail_tmp = uart1_send.tail;
  48   2                      if(uart1_send.head < tail_tmp)
  49   2                      {
  50   3                              free_space = tail_tmp - uart1_send.head;
  51   3                      }
  52   2                      else
C51 COMPILER V9.02   UART                                                                  12/12/2025 17:29:44 PAGE 2   

  53   2                      {
  54   3                              free_space = UART1_TX_BUF_SIZE + tail_tmp - uart1_send.head;
  55   3                      }               
  56   2                      if(free_space > 1)
  57   2                      {
  58   3                              ES1 = 0; 
  59   3                              uart1_send.head++;
  60   3                              uart1_send.head %= UART1_TX_BUF_SIZE;
  61   3                              uart1_tx_buf[uart1_send.head] = bdat;
  62   3                              if(!uart1_tx_flag)
  63   3                              {
  64   4                                      ES1 = 1;
  65   4                                      uart1_send.tail++;
  66   4                                      uart1_send.tail %= UART1_TX_BUF_SIZE;           
  67   4                                      S1BUF = uart1_tx_buf[uart1_send.tail];                          
  68   4                                      uart1_tx_flag = 1;              
  69   4                              }
  70   3                              else
  71   3                              {
  72   4                                      ES1 = 1;        
  73   4                              }                       
  74   3                              break;
  75   3                      }
  76   2              }
  77   1      }
  78          void UART1_ISR (void) interrupt 6       
  79          {
  80   1              if(S1CON & 0x01)
  81   1              {
  82   2                      S1CON = (S1CON&0xFC)|0x01;                       
  83   2                      uart1_rev.head++;
  84   2                uart1_rev.head %= UART1_RX_BUF_SIZE;
  85   2                      uart1_rx_buf[uart1_rev.head]=S1BUF;
  86   2              }
  87   1              if(S1CON & 0x02)
  88   1              {
  89   2                      S1CON = (S1CON&0xFC)|0x02;                      
  90   2                      if(uart1_send.head!=uart1_send.tail)
  91   2                      {
  92   3                              uart1_send.tail++;
  93   3                              uart1_send.tail %= UART1_TX_BUF_SIZE;
  94   3                              S1BUF=uart1_tx_buf[uart1_send.tail];                            
  95   3                      }
  96   2                      else
  97   2                      {
  98   3                              uart1_tx_flag=0;
  99   3                      }               
 100   2              }
 101   1      }
 102          
 103          void UartPutStr(char *str)
 104          {
 105   1              while(*str)
 106   1              {       
 107   2                      Uart1_PutChar(*str++);
 108   2              }
 109   1      }
 110          void uart_printf(char *fmt,...) 
 111          {
 112   1          va_list ap;
 113   1          char xdata string[256];
 114   1          va_start(ap,fmt);
C51 COMPILER V9.02   UART                                                                  12/12/2025 17:29:44 PAGE 3   

 115   1          vsprintf(string,fmt,ap);
 116   1          UartPutStr(string);
 117   1          va_end(ap);
 118   1      }
 119          
 120          /*********************************************************************************************************
             -************/
 121          #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    403    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    124     256
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      28
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
