急求大神指导,一个模块可以正常工作,配置两个只能工作第一个配置的模块,这是为什么呢 以下是外部中断的配置:
#include "wave.h"
#include "sys.h"
#include "delay.h"
#include "led.h"
#include "timer.h"
u8 a=0;
float Distance;
void Wave_SRD_Init(void)
{
GPIO_InitTypeDef GPIO_InitSture;
EXTI_InitTypeDef EXTI_InitSture;
NVIC_InitTypeDef NVIC_InitSture;
//如果外部中断的话则一定使能AFIO复用功能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOE,ENABLE);
//配置IO端口
GPIO_InitSture.GPIO_Mode=GPIO_Mode_Out_PP; //推挽输出模式
GPIO_InitSture.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_4; //将PE6于Trig相连
GPIO_InitSture.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitSture);
GPIO_InitSture.GPIO_Mode=GPIO_Mode_IPD; //下拉输入
GPIO_InitSture.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_3; //将PE3于Echo相连
GPIO_InitSture.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitSture);
//中断和1端口映射一起
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource1);
//外部中断配置
EXTI_InitSture.EXTI_Line=EXTI_Line1;
EXTI_InitSture.EXTI_LineCmd=ENABLE;
EXTI_InitSture.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitSture.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitSture);
//中断和3端口映射一起
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource3);
//外部中断配置
EXTI_InitSture.EXTI_Line=EXTI_Line3;
EXTI_InitSture.EXTI_LineCmd=ENABLE;
EXTI_InitSture.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitSture.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitSture);
//中断优先级管理
NVIC_InitSture.NVIC_IRQChannel=EXTI3_IRQn;
NVIC_InitSture.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitSture.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitSture.NVIC_IRQChannelSubPriority=2;
NVIC_Init(&NVIC_InitSture);
NVIC_InitSture.NVIC_IRQChannel=EXTI1_IRQn;
NVIC_InitSture.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitSture.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitSture.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_InitSture);
}
void EXTI3_IRQHandler(void)
{
delay_us(10);
if((EXTI_GetITStatus(EXTI_Line3)!=RESET))
{
TIM_SetCounter(TIM3,0);
TIM_Cmd(TIM3,ENABLE);
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)); //等待低电平
TIM_Cmd(TIM3,DISABLE);
Distance=TIM_GetCounter(TIM3)*340/200.0;
if((Distance>10)&&(Distance<100))
{
a=1;
LED0=!LED0;
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
}
void EXTI1_IRQHandler(void)
{
delay_us(10);
if((EXTI_GetITStatus(EXTI_Line1)!=RESET))
{
TIM_SetCounter(TIM3,0);
TIM_Cmd(TIM3,ENABLE);
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_1)); //等待低电平
TIM_Cmd(TIM3,DISABLE);
Distance=TIM_GetCounter(TIM3)*340/200.0;
if((Distance>10)&&(Distance<100))
{
a=2;
LED1=!LED1;
}
EXTI_ClearITPendingBit(EXTI_Line1);
}
}
void Wave_SRD3_Strat(void)
{
GPIO_SetBits(GPIOE,GPIO_Pin_6); //将pin6设置为高电平
delay_us(20); //持续大于10us触发,触发超声波模块工作
GPIO_ResetBits(GPIOE,GPIO_Pin_6);
}
void Wave_SRD1_Strat(void)
{
GPIO_SetBits(GPIOE,GPIO_Pin_4); //将pin4设置为高电平
delay_us(20); //持续大于10us触发,触发超声波模块工作
GPIO_ResetBits(GPIOE,GPIO_Pin_4);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
不对,再测试了下,不管怎样配置,只有三号引脚有用
一周热门 更多>