C51 COMPILER V9.02   UART                                                                  12/12/2025 17:30:15 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 Uart2_Initial(unsigned long int baudrate)
  19          {
  20   1              unsigned int value_temp;
  21   1      
  22   1              uart2_send.head=0;
  23   1              uart2_send.tail=0;
  24   1              uart2_rev.head=0;
  25   1              uart2_rev.tail=0;
  26   1              uart2_tx_flag=0;
  27   1      
  28   1              GPIO_Init(P60F,P60_UART2_RX_SETTING);
  29   1              GPIO_Init(P61F,P61_UART2_TX_SETTING);
  30   1      
  31   1              value_temp = 0x400 - FOSC/(baudrate*32);
  32   1              S2RELH = (unsigned char)(value_temp>>8);
  33   1              S2RELL = (unsigned char)(value_temp);
  34   1              
  35   1              S2CON = 0xD0;
  36   1              INT3EN =        1;      
  37   1      }
  38          void Uart2_PutChar(unsigned char bdat)
  39          {
  40   1              unsigned char free_space;
  41   1              unsigned char tail_tmp;
  42   1              while(1)
  43   1              {               
  44   2                      tail_tmp = uart2_send.tail;
  45   2                      if(uart2_send.head < tail_tmp)
  46   2                      {
  47   3                              free_space = tail_tmp - uart2_send.head;
  48   3                      }
  49   2                      else
  50   2                      {
  51   3                              free_space = UART2_TX_BUF_SIZE + tail_tmp - uart2_send.head;
  52   3                      }               
C51 COMPILER V9.02   UART                                                                  12/12/2025 17:30:15 PAGE 2   

  53   2                      if(free_space > 1)
  54   2                      {
  55   3                              INT3EN = 0; 
  56   3                              uart2_send.head++;
  57   3                              uart2_send.head %= UART2_TX_BUF_SIZE;
  58   3                              uart2_tx_buf[uart2_send.head] = bdat;                   
  59   3                              if(!uart2_tx_flag)
  60   3                              {
  61   4                                      INT3EN = 1;
  62   4                                      uart2_send.tail++;
  63   4                                      uart2_send.tail %= UART2_TX_BUF_SIZE;                   
  64   4                                      S2BUF = uart2_tx_buf[uart2_send.tail];                          
  65   4                                      uart2_tx_flag = 1;              
  66   4                              }
  67   3                              else
  68   3                              {
  69   4                                      INT3EN = 1;     
  70   4                              }                       
  71   3                              break;
  72   3                      }
  73   2              }
  74   1      }
  75          void UART2_ISR (void) interrupt 8       
  76          {
  77   1              if(S2CON & 0x01)
  78   1              {
  79   2                      S2CON = (S2CON&0xFC)|0x01;              
  80   2                      uart2_rev.head++;
  81   2                      uart2_rev.head %= UART2_RX_BUF_SIZE;
  82   2                      uart2_rx_buf[uart2_rev.head]=S2BUF;
  83   2              }
  84   1              if(S2CON & 0x02)
  85   1              {
  86   2                      S2CON = (S2CON&0xFC)|0x02;      
  87   2                      if(uart2_send.head!=uart2_send.tail)
  88   2                      {
  89   3                              uart2_send.tail++;
  90   3                              uart2_send.tail %= UART2_TX_BUF_SIZE;
  91   3                              S2BUF=uart2_tx_buf[uart2_send.tail];                            
  92   3                      }
  93   2                      else
  94   2                      {
  95   3                              uart2_tx_flag=0;
  96   3                      }               
  97   2              }
  98   1      }
  99          
 100          void UartPutStr(char *str)
 101          {
 102   1              while(*str)
 103   1              {       
 104   2                      Uart2_PutChar(*str++);
 105   2              }
 106   1      }
 107          
 108          void uart_printf(char *fmt,...) 
 109          {
 110   1          va_list ap;
 111   1          char xdata string[256];
 112   1          va_start(ap,fmt);
 113   1          vsprintf(string,fmt,ap);
 114   1          UartPutStr(string);
C51 COMPILER V9.02   UART                                                                  12/12/2025 17:30:15 PAGE 3   

 115   1          va_end(ap);
 116   1      }
 117          
 118          /*********************************************************************************************************
             -************/
 119          #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)
