main.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-03 WCH first version
  9. * 2022-04-05 Blta modify some formats
  10. */
  11. #include <rtthread.h>
  12. #include <board.h>
  13. /* Global typedef */
  14. /* Global define */
  15. /* LED0(PA1) usd pin device */
  16. #define LED0_PIN 15
  17. /* Global Variable */
  18. /* LED1 initialization */
  19. void LED1_BLINK_INIT(void)
  20. {
  21. GPIO_InitTypeDef GPIO_InitStructure = {0};
  22. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  23. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  24. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  25. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  26. GPIO_Init(GPIOA, &GPIO_InitStructure);
  27. }
  28. /* main thread */
  29. int main(void)
  30. {
  31. rt_kprintf("\r\n MCU: CH32V103C8T6\r\n");
  32. rt_kprintf(" SysClk: %dHz\r\n", SystemCoreClock);
  33. rt_kprintf(" www.wch.cn\r\n");
  34. LED1_BLINK_INIT();
  35. GPIO_ResetBits(GPIOA, GPIO_Pin_0);
  36. while(1)
  37. {
  38. GPIO_SetBits(GPIOA, GPIO_Pin_0);
  39. rt_thread_mdelay(500);
  40. GPIO_ResetBits(GPIOA, GPIO_Pin_0);
  41. rt_thread_mdelay(500);
  42. }
  43. }
  44. /* led cmd */
  45. int led(void)
  46. {
  47. rt_uint8_t count;
  48. rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
  49. for(count = 0; count < 10; count++)
  50. {
  51. rt_pin_write(LED0_PIN, PIN_LOW);
  52. rt_kprintf("led on, count : %d\r\n", count);
  53. rt_thread_mdelay(500);
  54. rt_pin_write(LED0_PIN, PIN_HIGH);
  55. rt_kprintf("led off\r\n");
  56. rt_thread_mdelay(500);
  57. }
  58. return 0;
  59. }
  60. MSH_CMD_EXPORT(led, RT - Thread first led sample by using I / O driver);