本帖最后由 taijing33 于 2018-7-17 10:50 编辑
void nvic_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
//3.??EXTI?
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
//GPIO_PinAFConfig(GPIOF,GPIO_PinSource1,GPIO_AF_1);
//GPIO_PinAFConfig(GPIOB,GPIO_PinSource8|GPIO_PinSource9,GPIO_AF_6);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF,EXTI_PinSource1);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF,EXTI_PinSource0);
// EXTI_ClearITPendingBit(EXTI_Line0);
// EXTI_ClearITPendingBit(EXTI_Line1);
EXTI_InitStructure.EXTI_Line = EXTI_PinSource0|EXTI_PinSource1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //EXTI_Trigger_Rising_Falling
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource8);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource9);
EXTI_ClearITPendingBit(EXTI_Line8);
EXTI_ClearITPendingBit(EXTI_Line9);
EXTI_InitStructure.EXTI_Line = EXTI_PinSource8|EXTI_PinSource9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //EXTI_Trigger_Rising_Falling
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//EXTI_GenerateSWInterrupt(EXTI_Line1);
/* ----------------USART1 IRQ Channel configuration----------------- */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 2;//0-3£ºÖ»ÓÐ4¸öÓÅÏȼ¶ 4¸ö¿É±à³ÌµÄÓÅÏȼ¶( ʹÓÃÁË2 λµÄÖжÏÓÅÏȼ¶)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* ----------------TIM3_IRQn Channel configuration----------------- */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;//0-3£ºÖ»ÓÐ4¸öÓÅÏȼ¶ 4¸ö¿É±à³ÌµÄÓÅÏȼ¶( ʹÓÃÁË2 λµÄÖжÏÓÅÏȼ¶)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* ----------------TIM6_IRQn Channel configuration----------------- */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;//0-3£ºÖ»ÓÐ4¸öÓÅÏȼ¶ 4¸ö¿É±à³ÌµÄÓÅÏȼ¶( ʹÓÃÁË2 λµÄÖжÏÓÅÏȼ¶)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 3;//0-3£ºÖ»ÓÐ4¸öÓÅÏȼ¶ 4¸ö¿É±à³ÌµÄÓÅÏȼ¶( ʹÓÃÁË2 λµÄÖжÏÓÅÏȼ¶)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI0_1_IRQHandler(void)
{
u8 a=1;
if((EXTI->PR & EXTI_Line1) != RESET) //EXTI9?????
{
a=1;EXTI_ClearITPendingBit(EXTI_Line1);//????
}
if((EXTI->PR & EXTI_Line0) != RESET) //EXTI9?????
{
a=1;EXTI_ClearITPendingBit(EXTI_Line0);//????
}
}
void EXTI4_15_IRQHandler(void)
{
if((EXTI->PR & EXTI_Line8) != RESET) //EXTI9?????
{
;
}
EXTI_ClearITPendingBit(EXTI_Line8);//????
if((EXTI->PR & EXTI_Line9) != RESET) //EXTI9?????
{
;
}
EXTI_ClearITPendingBit(EXTI_Line9);//????
}
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |GPIO_Pin_9; //¹Ü½ÅºÅ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ËÙ¶È
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //ÊäÈë Êä³ö ¸´Óà ģÄâ
// GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;//ÍÆÍìÊä³ö ¿ªÂ©Êä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//ÉÏÀ ÏÂÀ
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1; //¹Ü½ÅºÅ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ËÙ¶È
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //ÊäÈë Êä³ö ¸´Óà ģÄâ
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//ÍÆÍìÊä³ö ¿ªÂ©Êä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//ÉÏÀ ÏÂÀ
GPIO_Init(GPIOF, &GPIO_InitStructure);
上面是我单买,我需要PF0.PF1.Pb8.Pb9.能外部进入中断,但是现在只有pf0能进入中断,
另外程序能识别PF1.Pb8.Pb9.的电平变化,就是进步了PF1.Pb8.Pb9.的中断,。
谁能帮我解决,一下,红包200元吧,我也不知道给多少,整个程序在附件里。。。
另外:单片机使用的内部晶振,PF0和1是晶振接口,我也注意到了,
|