【单片机】CH32V103v8t6 - PA5-外部中断测试程序
main.c文件内容
/* *@Note 外部中断线例程: EXTI_Line5(PA5) PA5设置上拉输入,下降沿触发中断。 */ #include "debug.h" /******************************************************************************* * Function Name : EXTI5_INT_INIT * Description : Initializes EXTI0 collection. * Input : None * Return : None *******************************************************************************/ void EXTI5_INT_INIT(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOA, &GPIO_InitStructure); /* GPIOA ----> EXTI_Line5 */ GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource5); EXTI_InitStructure.EXTI_Line=EXTI_Line5; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Return : None *******************************************************************************/ int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); Delay_Init(); USART_Printf_Init(115200); printf("SystemClk:%d\r\n",SystemCoreClock); printf("EXTI0 Test\r\n"); EXTI5_INT_INIT(); while(1) { Delay_Ms(1000); printf("Run at main\r\n"); } }
ch32v10x_it.c内容
/********************************** (C) COPYRIGHT ******************************* * File Name : ch32v10x_it.c * Author : WCH * Version : V1.0.0 * Date : 2020/04/30 * Description : Main Interrupt Service Routines. *******************************************************************************/ #include "ch32v10x_it.h" void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void EXTI9_5_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); /******************************************************************************* * Function Name : NMI_Handler * Description : This function handles NMI exception. * Input : None * Return : None *******************************************************************************/ void NMI_Handler(void) { } /******************************************************************************* * Function Name : HardFault_Handler * Description : This function handles Hard Fault exception. * Input : None * Return : None *******************************************************************************/ void HardFault_Handler(void) { while (1) { } } /******************************************************************************* * Function Name : EXTI5_IRQHandler * Description : This function handles EXTI0 Handler. * Input : None * Return : None *******************************************************************************/ void EXTI9_5_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line5)!=RESET) { printf("Run at EXTI5\r\n"); EXTI_ClearITPendingBit(EXTI_Line5); /* Clear Flag */ } }
工程文件下载地址:https://download.csdn.net/download/qq_18187161/22441602