c8051f350串口通信(4)
发布时间:2021-06-07
发布时间:2021-06-07
串口通信
void UART0_Init (void)
{
SCON0 = 0x10; //REN0=1允许接收 S0MODE=0串口工作方式0 (波特率可编程的8位UART)
CKCON = 0x08; //定时器3高字节使用系统时钟0x80 定时器2高字节使用系统时钟0x20 0x04
TMOD = 0x20; //自动重装载的8位计数器/定时器
// TCON = 0x40; //
TH1 = 0x2b;
TR1 = 1; //定时器1工作
}
//-----------------------------------------------------------------------------
// 时钟1中断串口中断
//-----------------------------------------------------------------------------
void UART0_ISR (void) interrupt 4
{
if (RI0 == 1)
{
if( UART_Buffer_Size == 0) // If new word is entered
{
UART_Input_First = 0;
}
RI0 = 0; // Clear interrupt flag
Byte = SBUF0; // Read a character from UART
if (UART_Buffer_Size < UART_BUFFERSIZE)
{
UART_Buffer[UART_Input_First] = Byte; // Store in array
UART_Buffer_Size++; // Update array's size
UART_Input_First++; // Update counter
}
}