/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Website: http://www.nuvoton.com
// E-Mail : MicroC-8bit@nuvoton.com
// Date : Jan/21/2019
//***********************************************************************************************************
/***********************************************************************************************************
// File Function: ML51 UART0 receive and transmit loop test
/***********************************************************************************************************/
#include "ML51.H"
unsigned char uart_receive_data;
bit receiveFlag,bufOverFlag;
/*************************************************************
// UART interrupt subroutine.
/**************************************************************/
void Serial_ISR (void) interrupt 4
{
if (RI)
{
receiveFlag = 1;
uart_receive_data = SBUF;
clr_SCON_RI; // Clear RI (Receive Interrupt).
}
if (TI)
{
clr_SCON_TI; // Clear TI (Transmit Interrupt).
}
}
void main(void)
{
/* Initial UART0 */
MFP_P31_UART0_TXD;
P31_PUSHPULL_MODE;
MFP_P30_UART0_RXD;
P30_INPUT_MODE;
UART_Open(24000000,UART0_Timer3,115200); /*condition is: Fsys, UART0 or UART1 , Baudrate */
ENABLE_UART0_PRINTF;
ENABLE_UART0_INTERRUPT; /* Enable UART0 interrupt */
ENABLE_GLOBAL_INTERRUPT; /* Global interrupt enable */
/* while receive data from RXD, send this data to TXD */
while(1)
{
if (receiveFlag)
{
receiveFlag = 0;
clr_IE_ES;
UART_Send_Data(UART0,uart_receive_data);
set_IE_ES;
}
}
}
|