main.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "yc11xx_uart.h"
  4. #include "yc11xx_gpio.h"
  5. #include "system.h"
  6. void LED_Run(void)
  7. {
  8. static uint32_t times = 0;
  9. times++;
  10. if(times>0x50000)
  11. {
  12. times = 0;
  13. GPIO_CONFIG(2) = (GPIO_CONFIG(2)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
  14. }
  15. }
  16. #define IO_TXA 19
  17. #define IO_RXA 23
  18. #define IO_TXB 6
  19. #define IO_RXB 14
  20. #define UARTBUFSIZE 128
  21. void UartxInit(USART_TypeDef UARTx)
  22. {
  23. USART_InitTypeDef USART_InitStruct ;
  24. USART_InitStruct.USART_BaudRate = UARTE_BAUDRATE_BAUDRATE_Baud115200;
  25. USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  26. USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  27. USART_InitStruct.USART_StopBits = USART_StopBits_1;
  28. USART_InitStruct.USART_Mode =USART_Mode_duplex;
  29. USART_InitStruct.USART_Parity = USART_Parity_Even ;
  30. USART_InitStruct.USART_RXLen = UARTBUFSIZE;
  31. USART_InitStruct.USART_TXLen = UARTBUFSIZE;
  32. if(UARTA == UARTx){
  33. GPIO_SetGpioMultFunction(IO_TXA,GPCFG_UART_TXD);
  34. GPIO_SetGpioMultFunction(IO_RXA,GPCFG_UART_RXD);
  35. }else if (UARTB == UARTx){
  36. GPIO_SetGpioMultFunction(IO_TXB,GPCFG_UARTB_TXD);
  37. GPIO_SetGpioMultFunction(IO_RXB,GPCFG_UARTB_RXD);
  38. }
  39. USART_Init(UARTx,&USART_InitStruct);
  40. }
  41. int main(void)
  42. {
  43. int i = 100000;
  44. uint8_t UrataReData=0,UratbReData=0;
  45. UartxInit(UARTB);
  46. UartxInit(UARTA);
  47. // printport_init();
  48. while(i--);
  49. // MyPrintf("This is uart send and reveice demo\n");
  50. for(i=0;i<100;i++)
  51. {
  52. USART_SendData(UARTB,i);
  53. USART_SendData(UARTA,i);
  54. // MyPrintf("\r\n%d\r\n",i);
  55. }
  56. while(1)
  57. {
  58. if(USART_GetRxCount(UARTB)>0)
  59. {
  60. UratbReData=USART_ReceiveData(UARTB);
  61. USART_SendData(UARTB,UratbReData);
  62. // MyPrintf("\r\nUratbReData=%x\r\n",UratbReData);
  63. }
  64. if(USART_GetRxCount(UARTA)>0)
  65. {
  66. UrataReData=USART_ReceiveData(UARTA);
  67. USART_SendData(UARTA,UrataReData);
  68. }
  69. }
  70. }