初次使用中断我本想设置两个按键。但是同样的中断函数,在PB4口可以,PB3口就不能使用。
程序如下:
#include "stm32f10x.h"
void RCC_Config(void);
//时钟配置函数
void GPIO_Config(void);
//I/O口配置函数
void EXIT_Config(void);
//中断选择配置
void NVIC_Config(void);
//中断优先级选择
void Delay (u32 nCount)
{
for(; nCount != 0; nCount--);
}
int main(void)
{
RCC_Config();
GPIO_Config();
EXIT_Config();
NVIC_Config();
while (1){
/*====LED1-ON=======*/
GPIO_SetBits(GPIOB , GPIO_Pin_6);
GPIO_ResetBits(GPIOB , GPIO_Pin_7);
GPIO_ResetBits(GPIOB , GPIO_Pin_8);
GPIO_ResetBits(GPIOB , GPIO_Pin_9);
Delay(0xfffff);
Delay(0xfffff);
Delay(0x5ffff);
/*====LED2-ON=======*/
GPIO_ResetBits(GPIOB , GPIO_Pin_6);
GPIO_SetBits(GPIOB , GPIO_Pin_7);
GPIO_ResetBits(GPIOE , GPIO_Pin_8);
GPIO_ResetBits(GPIOE , GPIO_Pin_9);
Delay(0xfffff);
Delay(0xfffff);
Delay(0x5ffff);
/*====LED3-ON=======*/
GPIO_ResetBits(GPIOB , GPIO_Pin_6);
GPIO_ResetBits(GPIOB , GPIO_Pin_7);
GPIO_SetBits(GPIOB , GPIO_Pin_8);
GPIO_ResetBits(GPIOB , GPIO_Pin_9);
Delay(0xfffff);
Delay(0xfffff);
Delay(0x5ffff);
/*====LED4-ON=======*/
GPIO_ResetBits(GPIOB , GPIO_Pin_6);
GPIO_ResetBits(GPIOB , GPIO_Pin_7);
GPIO_ResetBits(GPIOB , GPIO_Pin_8);
GPIO_SetBits(GPIOB , GPIO_Pin_9);
Delay(0xfffff);
Delay(0xfffff);
Delay(0x5ffff);
}
}
/*设置I/O口使能时钟,配置I/O模式*/
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*使能AFIO复用I/O口的时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);
/**
*
LED1 -> PB6
,
LED2 -> PB7 , LED3 -> PB8 , LED4 -> PB9
KEY1 ->PB1
KEY2 ->PB2
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 |GPIO_Pin_7 |GPIO_Pin_8 |GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void RCC_Config(void)
{
/*定义错误变量HSEStartUpStatus*/
ErrorStatus HSEStartUpStatus;
/* 这里是重置了RCC的设置,类似寄存器复位 */
RCC_DeInit();
/* 使能外部高速晶振 */
RCC_HSEConfig(RCC_HSE_ON);
/* 等待高速晶振稳定 */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (HSEStartUpStatus == SUCCESS)
{
/* HCLK = SYSCLK 设置高速总线时钟=系统时钟*/
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK 设置低速总线2时钟=高速总线时钟*/
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 设置低速总线1的时钟=高速时钟的二分频*/
RCC_PCLK1Config(RCC_HCLK_Div2);
/* ADCCLK = PCLK2/6 设置ADC外设时钟=低速总线2时钟的六分频*/
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* 利用锁相环讲外部8Mhz晶振9倍频到72Mhz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL 使能锁相环*/
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready 等待锁相环输出稳定*/
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as system clock source 将锁相环输出设置为系统时钟 */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source 等待校验成功*/
while (RCC_GetSYSCLKSource() != 0x08)
{}
}
}
void EXIT_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure; //定义结构
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource4);
EXTI_ClearITPendingBit(EXTI_Line4);
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //占先优先级、副优先级的资源分配
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
void EXTI4_IRQHandler(void)
{
if ( EXTI_GetITStatus(EXTI_Line4) != RESET ) {
EXTI_ClearITPendingBit(EXTI_Line4);
GPIO_ResetBits(GPIOB , GPIO_Pin_6);
GPIO_ResetBits(GPIOB , GPIO_Pin_7);
GPIO_ResetBits(GPIOB , GPIO_Pin_8);
GPIO_ResetBits(GPIOB , GPIO_Pin_9);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
}
}
这个是可行的 但是所有的4改为3就不可以用了。求问这是个什么问题? |