main.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "yc11xx_wdt.h"
  4. #include "ycdef.h"
  5. #include "yc11xx_uart.h"
  6. #include "yc11xx_gpio.h"
  7. void LED_Run(void)
  8. {
  9. static uint32_t times = 0;
  10. times++;
  11. if(times>0x5000)
  12. {
  13. times = 0;
  14. GPIO_CONFIG(2) = (GPIO_CONFIG(2)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
  15. }
  16. }
  17. void delay(uint32_t t)
  18. {
  19. while(t-- > 0)
  20. {
  21. }
  22. }
  23. #define IO_TXA 8
  24. #define IO_RXA 9
  25. #define IO_TXB 6
  26. #define IO_RXB 14
  27. #define UARTBUFSIZE 128
  28. void UartxInit(USART_TypeDef UARTx)
  29. {
  30. USART_InitTypeDef USART_InitStruct ;
  31. USART_InitStruct.USART_BaudRate = UARTE_BAUDRATE_BAUDRATE_Baud115200;
  32. USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  33. USART_InitStruct.USART_WordLength = USART_WordLength_8b;
  34. USART_InitStruct.USART_StopBits = USART_StopBits_1;
  35. USART_InitStruct.USART_Mode =USART_Mode_duplex;
  36. USART_InitStruct.USART_Parity = USART_Parity_Even ;
  37. USART_InitStruct.USART_RXLen = UARTBUFSIZE;
  38. USART_InitStruct.USART_TXLen = UARTBUFSIZE;
  39. if(UARTA == UARTx){
  40. GPIO_SetGpioMultFunction(IO_TXA,GPCFG_UART_TXD);
  41. GPIO_SetGpioMultFunction(IO_RXA,GPCFG_UART_RXD);
  42. }else if (UARTB == UARTx){
  43. GPIO_SetGpioMultFunction(IO_TXB,GPCFG_UARTB_TXD);
  44. GPIO_SetGpioMultFunction(IO_RXB,GPCFG_UARTB_RXD);
  45. }
  46. USART_Init(UARTx,&USART_InitStruct);
  47. }
  48. int main(void)
  49. {
  50. //GPIO_CONFIG(20) = GPCFG_JTAG_SWCLK;
  51. //GPIO_CONFIG(21) = GPCFG_JTAG_SWDAT;
  52. UartxInit(UARTB);
  53. int i = 0x40000;
  54. while(i--);
  55. USART_SendData(UARTB,0xAA);
  56. USART_SendData(UARTB,0xA5);
  57. i=3;
  58. while(i--)
  59. {
  60. GPIO_CONFIG(23) = GPCFG_OUTPUT_HIGH;
  61. delay(1000000);
  62. GPIO_CONFIG(23) = GPCFG_OUTPUT_LOW;
  63. delay(1000000);
  64. }
  65. USART_SendData(UARTB,*((volatile byte*)(0x10008043)));
  66. WDT_Enable();
  67. // uint8_t config = *((volatile byte*)(0x10008043));
  68. // config |= (1 << 2);
  69. // *((volatile byte*)(0x10008043)) = config;
  70. // *((volatile byte*)(0x10008004)) = 0x2;
  71. USART_SendData(UARTB,*((volatile byte*)(0x10008043)));
  72. while(1)
  73. {
  74. // WDT_Kick();
  75. GPIO_CONFIG(23) = GPCFG_OUTPUT_HIGH;
  76. delay(100000);
  77. GPIO_CONFIG(23) = GPCFG_OUTPUT_LOW;
  78. delay(100000);
  79. // WDT_Disable();
  80. }
  81. }