这是我最近写的利用32外部中断和霍尔传感器写的电机测速源程序,程序运行错误 求帮助
- #include "exti.h"
- #include "stm32f10x.h"
- #include "delay.h"
- #include "led.h"
- #include "sys.h"
- u16 k1 = 0;
- u8 k2 = 0;
- void EXTIX_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //初始化IO口
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_1;
- GPIO_Init(GPIOF,&GPIO_InitStructure);
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOF, ENABLE); //开启IO口复用时钟
-
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOF,GPIO_PinSource2); // GPIOB2 映射到 中断线2
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOF,GPIO_PinSource1); // GPIOB1 映射到 中断线1
-
- EXTI_InitStructure.EXTI_Line = EXTI_Line2; //中断线2
- EXTI_InitStructure.EXTI_LineCmd = ENABLE; //外部中断使能
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //模式中断
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿
- EXTI_Init(&EXTI_InitStructure); //设定参数初始化 外部中断
-
- EXTI_InitStructure.EXTI_Line = EXTI_Line1; //中断线1
- EXTI_InitStructure.EXTI_LineCmd = ENABLE; //外部中断使能
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //模式中断
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿
- EXTI_Init(&EXTI_InitStructure); //设定参数初始化 外部中断
-
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //通道 外部中断2
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占优先级
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //响应优先级
- NVIC_Init(&NVIC_InitStructure);
-
- NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //通道 外部中断1
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占优先级
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级
- NVIC_Init(&NVIC_InitStructure);
-
- }
- void EXTI2_IRQHandler(void) //外部中断服务函数
- {
- // k2++;
- // if(k2 >= 13)
- // {
- // k2 = 0;
- k1++;
- // }
-
-
- EXTI_ClearITPendingBit(EXTI_Line2); //清除中断标志位
- }
- void EXTI1_IRQHandler(void) //外部中断服务函数
- {
- k1 = 0;
-
- EXTI_ClearITPendingBit(EXTI_Line1); //清除中断标志位
- }
复制代码 全部资料51hei下载地址:(管理提醒:多人回帖说代码有问题,大家不要下载)
外部中断(电机测速).7z
(182.49 KB, 下载次数: 125)
|