Files
moyuhai 02f1638ef2 V1.0
2026-06-12 09:12:35 +08:00

177 lines
6.4 KiB
Plaintext

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 <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 #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<sizeof(BR_TAB)/4;i++)
{
if(baudrate == BR_TAB[i])
{
value_temp = 0x10000 - BR_SET_TAB[i][0];
UDCKS = 0x80 | BR_SET_TAB[i][1];
break;
}
}
if(i == sizeof(BR_TAB)/4) return; //如果所设置的波特率不在表格中,可自行添加。
T2CON = 0x24;
T2CH = (unsigned char)(value_temp>>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)