/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Website: http://www.nuvoton.com
// E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************
#include "ML51.h"
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] UART0 Transfer and receive with interrupt subroutine.
* @param None
* [url=home.php?mod=space&uid=266161]@return[/url] None
* [url=home.php?mod=space&uid=1543424]@Details[/url] Result stroage in XRAM UIDBuffer[0:8];
*/
unsigned char uart_receive_data,bufhead;
bit receiveFlag,bufOverFlag;
unsigned char my[10];
unsigned char i=0;
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)
{
MFP_P46_GPIO;
P46_PUSHPULL_MODE;
/**
For UART0 P0.5 asTXD output setting
* include uart.c in Common Setting for UART0
*/
MFP_P31_UART0_TXD; /* set P3.1 and P3.0 as Quasi mode for UART0 trasnfer */
MFP_P30_UART0_RXD;
P31_QUASI_MODE;
P30_QUASI_MODE;
UART_Open(24000000,UART0_Timer1,115200); // Open UART0 use timer1 as baudrate generate and baud rate = 115200
ENABLE_UART0_PRINTF;
#if 0
UART_Interrupt_Enable(UART0,Enable);
while(1);
#else
/**
UART0 loop test
UART0 TXD send data received by RXD pin. Connect TXD pin and RXD pin check result.
*/
do{
unsigned char temp;
temp = UART_Receive_Data(UART0);
UART_Send_Data(UART0,temp);
my[i++]=temp;
if(i>=10)
{
UART_Send_Data(UART0,'a');
for(i=0;i<10;i++)
UART_Send_Data(UART0,my[i]);
for(i=0;i<10;i++)
my[i]=0;
i=0;
}
}while(1);
#endif
}
|