#include "stm32f0xx.h" unsigned char flag=0; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Delay * @param None * @retval None */ void Delay(unsigned int ncount) { while(ncount--); } /** * @brief GPIO Initial * @param None * @retval None */ void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); } /** * @brief EXTI Initial * @param None * @retval None */ void EXTI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitStructure.EXTI_Line=EXTI_Line13; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_Init(&EXTI_InitStructure); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13); } /** * @brief GPIO Initial * @param None * @retval None */ void RCC_Configuration(void) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); } /** * @brief NVIC Initial * @param None * @retval None */ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel=EXTI4_15_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_InitStructure.NVIC_IRQChannelPriority=1; NVIC_Init(&NVIC_InitStructure); } /** * @brief Main program. * @param None * @retval None */ int main(void) { RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration(); EXTI_Configuration(); while (1); } /** * @brief IRQ * @param None * @retval None */ void EXTI4_15_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line13)==1) { Delay(0xff); if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)==0) while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)==0); GPIOA->ODR ^= GPIO_Pin_5; EXTI_ClearFlag(EXTI_Line13); } } 红色部分是M0和M3不同的部分: M3中这样配置:GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0|GPIO_PinSource1); M0用到l了SYSCFG,就要开启它的时钟 |
难道F0里面不需要配置?
另外好像没有了次占优先级的设置,这个应该是最主要的区别吧
独乐乐不如众乐乐!