本帖最后由 dream-yi 于 2012-5-15 00:08 编辑
u8 FLAG; //在线调试标志
void RCC_Config(void)
{
ErrorStatus HSEStartUpStatus;
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //PLL 72M
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
}
void EXIT_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource0);
EXTI_ClearITPendingBit(EXTI_Line0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
// EXTI_GenerateSWInterrupt(EXTI_Line0); EXTI_Line0中断允许 (软件触发)
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //申明GPIO_TimeBaseStructure
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1 ; //引用PA0和PA1
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP ; //设置引脚为推挽输出
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz ; //设置引脚最高输出速率50MHz
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; //引用PC0
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU; //设置引脚为上拉输入
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz ; //设置引脚最高输出速率50MHz
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;//定义结构体变量
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void delay_ms(int time)
{
for(;time!=0;time--);
}
void EXIT0_IRQHanlder(void)
{
FLAG=1;
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line0);
GPIO_ResetBits(GPIOA,GPIO_Pin_0);
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
}
}
int main(void)
{
RCC_Config();
GPIO_Config();
NVIC_Config();
EXIT_Config();
GPIO_SetBits(GPIOA,GPIO_Pin_0);
GPIO_SetBits(GPIOA,GPIO_Pin_1);
while(1);
}
问题是一直不进中断(标志一直是0)
小弟使用按键触发的(按键在PC0,外部未加上拉电阻)
为什么啊?请高手帮忙看看,谢谢了 |