TA的每日心情 | 奋斗 2023-12-3 18:51 |
---|
签到天数: 772 天 连续签到: 1 天 [LV.10]以坛为家III
|
固件库有按键中断的例程序,我打开看了下,怎么会是PF7,我看了下小红板的管脚分配如下:
是每PC12,于是我就把工程里自带的模板考到子目录里:
然后设置如下:在C/C++把编译路径换到我现在的路径下边:
然后再把包括的文件统统移除,并按现在的路径加载一下,这样就相当于自己的模板了。
再然后查一下总线分配看看PC12分配在哪个总线上,看了下周PF7在一个总线,那就改吧!
改完的程序如下:
中断程序:- void EXTI4_15_IRQHandler(void)
- {
- if(EXTI_GetIntBitState(EXTI_LINE12) != RESET)
- {
- GPIO_WriteBit(GPIOC, GPIO_PIN_10,
- (BitState)((1-GPIO_ReadOutputBit(GPIOC, GPIO_PIN_10))));
-
- EXTI_ClearIntBitState(EXTI_LINE12);
- }
- }
复制代码 主程序:- #include "gd32f1x0.h"
- /* Private variables ---------------------------------------------------------*/
- GPIO_InitPara GPIO_InitStructure;
- EXTI_InitPara EXTI_InitStructure;
- NVIC_InitPara NVIC_InitStructure;
- /* Private function prototypes -----------------------------------------------*/
- void NVIC_Config(void);
- void EXTI_Config(void);
- /* Private functions ---------------------------------------------------------*/
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- int main(void)
- {
- RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC, ENABLE);
-
- /* Configure the LED1 GPIO */
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
- GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
- GPIO_Init( GPIOC, &GPIO_InitStructure );
- /* Turn on LED1 */
- GPIO_SetBits(GPIOC, GPIO_PIN_10);
-
- /* Configure the EXTI line12 */
- EXTI_DeInit(&EXTI_InitStructure);
- EXTI_Config();
-
- while(1)
- {
- }
- }
- /**
- * @brief Configure NVIC and Vector Table base location.
- * @param None
- * @retval None
- */
- void NVIC_Config(void)
- {
- /* 1 bits for pre-emption priority and 3 bits for subpriority */
- NVIC_PRIGroup_Enable(NVIC_PRIGROUP_1);
- /* Enable and set EXTI4_15 Interrupt to the highest priority */
- NVIC_InitStructure.NVIC_IRQ = EXTI4_15_IRQn;
- NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;
- NVIC_InitStructure.NVIC_IRQSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- /**
- * @brief Configure the selected EXTI line.
- * @param None
- * @retval None
- */
- void EXTI_Config(void)
- {
- /* Enable GPIOF clock */
- RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC, ENABLE);
-
- NVIC_Config();
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_MODE_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- /* Enable SYSCFG clock */
- RCC_APB2PeriphClock_Enable(RCC_APB2PERIPH_CFG, ENABLE);
-
- /* Connect EXTI12 Line to PF12 pin */
- SYSCFG_EXTILine_Config(EXTI_SOURCE_GPIOC, EXTI_SOURCE_PIN12);
- /* Configure EXTI7 line */
- EXTI_InitStructure.EXTI_LINE = EXTI_LINE12;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LINEEnable = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- }
- /******************* (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
复制代码 改完后运行,则按一下LED0取反一下。程序成功。
|
|