[KungFu32位 MCU] KF32A156操作IO口

[复制链接]
1490|0
 楼主| wwppd 发表于 2022-10-26 22:22 | 显示全部楼层 |阅读模式


KF32A156迷你EVB上的LED0每500ms闪烁一次
  1. void BoardGpioInit(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_InitStructure;
  4.        
  5.         /* Configure PD12 LED1 output */
  6.         GPIO_InitStructure.m_Mode = GPIO_MODE_OUT;
  7.         GPIO_InitStructure.m_OpenDrain = GPIO_POD_PP;
  8.         GPIO_InitStructure.m_PullDown = GPIO_NOPULL;
  9.         GPIO_InitStructure.m_PullUp = GPIO_NOPULL;
  10.         GPIO_InitStructure.m_Speed = GPIO_LOW_SPEED;
  11.         GPIO_InitStructure.m_Pin = GPIO_PIN_MASK_12;
  12.         GPIO_Configuration(GPIOD_SFR , &GPIO_InitStructure);
  13.        
  14.         /* Configure PH3 LED2 output */
  15.         GPIO_InitStructure.m_Pin = GPIO_PIN_MASK_3;
  16.         GPIO_Configuration(GPIOH_SFR , &GPIO_InitStructure);
  17.        
  18.         /* Configure PD7 user key input */
  19.         GPIO_InitStructure.m_Mode = GPIO_MODE_IN;
  20.         GPIO_InitStructure.m_Pin = GPIO_PIN_MASK_7;
  21.         GPIO_Configuration(GPIOD_SFR , &GPIO_InitStructure);
  22. }

  23. /*******************************************************************************
  24. **                                             Main Functions                                                     **
  25. *******************************************************************************/
  26. /**
  27. *  [url=home.php?mod=space&uid=247401]@brief[/url] :Main program
  28. *  @param in :None
  29. *  @param out :None
  30. *  @retval :None
  31. */
  32. int main()
  33. {
  34.         /* Initialize the system clock is 120M*/
  35.         SystemInit(120);
  36.         /* Setup SysTick Timer as delay function, and input frequency is 120M */
  37.         systick_delay_init(120);
  38.         /* Initialize the user IOs */
  39.         BoardGpioInit();
  40.         while(1)
  41.         {
  42.                 /* Toggle LED1 */
  43.                 if (++TimingDelay >= 10)
  44.                 {
  45.                         TimingDelay = 0;
  46.                         GPIO_Toggle_Output_Data_Config(GPIOD_SFR, GPIO_PIN_MASK_12);
  47.                 }
  48.                 /* Turn ON/OFF the dedicate LED2 by user key */
  49.                 if (GPIO_Read_Input_Data_Bit(GPIOD_SFR, GPIO_PIN_MASK_7) == Bit_RESET)
  50.                 {
  51.                         GPIO_Set_Output_Data_Bits(GPIOH_SFR, GPIO_PIN_MASK_3, Bit_SET);
  52.                 }
  53.                 else
  54.                 {
  55.                         GPIO_Set_Output_Data_Bits(GPIOH_SFR, GPIO_PIN_MASK_3, Bit_RESET);
  56.                 }
  57.                 systick_delay_ms(50);
  58.         }               
  59. }


您需要登录后才可以回帖 登录 | 注册

本版积分规则

55

主题

3099

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部