初中生
最后登录1970-1-1
在线时间 小时
注册时间2016-7-23
|
下面是我的LED 和定时器的配置是可以的 但是就是中断出错,不知道为什么,按键按下就是暂停了 而且只有一个按键有用,求大神指导一下是什么地方的问题,
#define LED1_ON GPIO_ResetBits(GPIOB,GPIO_Pin_0)
#define LED1_OFF GPIO_SetBits(GPIOB,GPIO_Pin_0)
#define LED2_ON GPIO_ResetBits(GPIOB,GPIO_Pin_1)
#define LED2_OFF GPIO_SetBits(GPIOB,GPIO_Pin_1)
//LED3õê¼»ˉoˉêy
//ÅäÖÃǶì×ÖD¶ÏNVIC
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//ÅäÖÃÖD¶Ï0
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//ÅäÖÃÖD¶ÏÔ′ 13
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//ÅäÖÃÖD¶Ï¿ú£¬éèÖÃÖD¶ÏóÅÏ輶
void EXTI_Pxy_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
//¿aÆôê±ÖóPA0
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
NVIC_Configuration();
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPD;
GPIO_Init(GPIOA,&GPIO_InitStructure);
//PA0ÖD¶ÏÏßéèÖÃ
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line=EXTI_Line0;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);
//PC13ÖD¶ÏÏßéèÖÃ
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line=EXTI_Line2;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
//¶¨ê±Æ÷Systick
static __IO u32 TimingDelay;
void SysTick_Init(void)
{
if(SysTick_Config(SystemCoreClock/100000))
{
while(1);
}
//1رն¨ê±Æ÷
SysTick->CTRL &=~SysTick_CTRL_ENABLE_Msk;
}
//USÑó3ùoˉêy
void us_delay(__IO u32 nTime)
{
TimingDelay=nTime;
SysTick->CTRL |=SysTick_CTRL_ENABLE_Msk;
while(TimingDelay!=0);
}
void TimingDelay_Decrement(void)
{
if(TimingDelay!=0x00)
{
TimingDelay--;
}
}
//Ö′DDÖD¶Ïoˉêy
void EXTI_INT_FUNCTION(void)
{
if(EXTI_GetITStatus(EXTI_Line0)!=RESET)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
// us_delay(100000);
// LED1_OFF;
// us_delay(500000);
//Çå3yÖD¶Ï±êÖ¾
EXTI_ClearITPendingBit(EXTI_Line0);
/* while(1)
{
LED1_ON;
us_delay(100000);
LED1_OFF;
us_delay(500000);
}
}
if(EXTI_GetITStatus(EXTI_Line2)!=RESET)
{
LED2_ON;
us_delay(100000);
LED2_OFF;
us_delay(100000);
//
EXTI_ClearITPendingBit(EXTI_Line2);
}
*/
}
}
/*
Ö÷oˉêy
*/
void EXTI_INT_FUNCTION();
int main(void)
{
GPIO_LED_Config();
__set_PRIMASK(0);
EXTI_Pxy_Config();
SysTick_Init();
while(1)
{
LED1_ON;
us_delay(100000);
LED1_OFF;
us_delay(100000);
LED2_ON;
us_delay(100000);
LED2_OFF;
us_delay(100000);
LED2_ON;
us_delay(100000);
LED2_OFF;
us_delay(100000);
}
}
|
|