#ifndef __DELAY_H
#define __DELAY_H
void SysTick_Init(void);
void delay_ms(unsigned int time);
void delay_us(unsigned int time);
#endif
#include "stm32f4xx.h"
unsigned int TimingDelay = 0;
void SysTick_Init()
{
if(SysTick_Config(SystemCoreClock/1000000))
{
while(1);
}
}
void delay_ms(unsigned int time)
{
TimingDelay=1000*time;
while(TimingDelay);
}
void delay_us(unsigned int time)
{
TimingDelay=time;
while(TimingDelay);
}
void SysTick_Handler()
{
if(TimingDelay)
{
TimingDelay--;
}
}
#include "stm32f4xx.h"
#include "delay.h"
#include "beep.h"
#include "key.h"
#include "led.h"
#include "exti.h"
#include "usart.h"
void EXTI4_IRQHandler()
{
delay_ms(10);
if(KEY0==0)
{
LED0_REV;
EXTI_ClearITPendingBit(EXTI_Line4);
}
}
void EXTI3_IRQHandler()
{
delay_ms(10);
if(KEY1==0)
{
LED1_REV;
EXTI_ClearITPendingBit(EXTI_Line3);
}
}
void EXTI2_IRQHandler()
{
delay_ms(10);
if(KEY2==0)
{
LED0_REV;
LED1_REV;
EXTI_ClearITPendingBit(EXTI_Line2);
}
}
void EXTI0_IRQHandler()
{
delay_ms(10);
if(KEY_UP==0)
{
BEEP_REV;
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void KEY_EXTI_Init()
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
KEY_Init();
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource4);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource3);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE,EXTI_PinSource2);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
EXTI_InitStructure.EXTI_Line=EXTI_Line4|EXTI_Line3|EXTI_Line2;
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_Line0;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=EXTI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStructure);
}
#include "stm32f4xx.h"
#include "delay.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "exti.h"
#include "usart.h"
int main()
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
SysTick_Init();
LED_Init();
BEEP_Init();
KEY_EXTI_Init();
My_USART1_Init();
while(1)
{ USART_SendData(USART1,65);
delay_ms(100);
}
}
delay延时函数是用滴答定时器中断方式实现的
程序一旦执行到void EXTI4_IRQHandler()
{
delay_ms(10);
if(KEY0==0)
{
LED0_REV;
EXTI_ClearITPendingBit(EXTI_Line4);
}
}中的延时函数时就卡住了,求解!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>