#include #include "yc11xx.h" #include "yc11xx_uart.h" #include "yc11xx_gpio.h" #include "system.h" void LED_Run(void) { static uint32_t times = 0; times++; if(times>0x50000) { times = 0; GPIO_CONFIG(2) = (GPIO_CONFIG(2)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH; } } #define IO_TXA 19 #define IO_RXA 23 #define IO_TXB 6 #define IO_RXB 14 #define UARTBUFSIZE 128 void UartxInit(USART_TypeDef UARTx) { USART_InitTypeDef USART_InitStruct ; USART_InitStruct.USART_BaudRate = UARTE_BAUDRATE_BAUDRATE_Baud115200; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_Mode =USART_Mode_duplex; USART_InitStruct.USART_Parity = USART_Parity_Even ; USART_InitStruct.USART_RXLen = UARTBUFSIZE; USART_InitStruct.USART_TXLen = UARTBUFSIZE; if(UARTA == UARTx){ GPIO_SetGpioMultFunction(IO_TXA,GPCFG_UART_TXD); GPIO_SetGpioMultFunction(IO_RXA,GPCFG_UART_RXD); }else if (UARTB == UARTx){ GPIO_SetGpioMultFunction(IO_TXB,GPCFG_UARTB_TXD); GPIO_SetGpioMultFunction(IO_RXB,GPCFG_UARTB_RXD); } USART_Init(UARTx,&USART_InitStruct); } int main(void) { int i = 100000; uint8_t UrataReData=0,UratbReData=0; UartxInit(UARTB); UartxInit(UARTA); // printport_init(); while(i--); // MyPrintf("This is uart send and reveice demo\n"); for(i=0;i<100;i++) { USART_SendData(UARTB,i); USART_SendData(UARTA,i); // MyPrintf("\r\n%d\r\n",i); } while(1) { if(USART_GetRxCount(UARTB)>0) { UratbReData=USART_ReceiveData(UARTB); USART_SendData(UARTB,UratbReData); // MyPrintf("\r\nUratbReData=%x\r\n",UratbReData); } if(USART_GetRxCount(UARTA)>0) { UrataReData=USART_ReceiveData(UARTA); USART_SendData(UARTA,UrataReData); } } }