/**
******************************************************************************
* @file main.c
* @author Alexander
* @version V1.0.0
* @date 04-January-2023
* @brief Main program body
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/** @addtogroup HK32F030Mxx_StdPeriph_Examples
* @{
*/
/** @addtogroup EXTI_Example
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Private function prototypes -----------------------------------------------*/
static void EXTI4_Config(void);
static void EXTI1_Config(void);
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (KEIL_startup_hk32f030m.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_hk32f030m.c file
*/
/* Initialize LEDs mounted on EVAL board */
HK_EVAL_LEDInit(LED1);
HK_EVAL_LEDInit(LED2);
HK_EVAL_LEDInit(LED3);
/* Configure PC4 in interrupt mode */
EXTI4_Config();
/* Configure PA1 in interrupt mode */
EXTI1_Config();
/* Delay(838709/5);Infinite loop */
while (1)
{
Delay(838709/5);
}
}
/**
* @brief Configure PC4 in interrupt mode
* @param None
* @retval None
*/
static void EXTI4_Config(void)
{
/* Enable GPIOC clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
/* Configure PC4 pin as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Connect EXTI4 Line to PA0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource4);
/* Configure EXTI4 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Configure PA1 in interrupt mode
* @param None
* @retval None
*/
static void EXTI1_Config(void)
{
/* Enable GPIOA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA1 pins as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Connect EXTI1 Line to PA1 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
/* Configure EXTI1 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
/* Toggle LED2 */
HK_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line1);
}
}
/**
* @brief This function handles External line 4 interrupt request.
* @param None
* @retval None
*/
void EXTI4_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4) != RESET)
{
/* Toggle LED1 */
HK_EVAL_LEDToggle(LED1);
/* Clear the EXTI line 4 pending bit */
EXTI_ClearITPendingBit(EXTI_Line4);
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**
* @}
*/
|