下面的程序,是我从一个教程的代码上修改的,调了2天,还是不行,真急人。望大家多多指点,谢谢了
#include <stm32f10x_lib.h>
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
ErrorStatus HSEStartUpStatus;
void RCC_Config(void);
void GPIO_Config(void );
void NVIC_Config(void );
void EXTI_Config(void );
void Delay(vu32 ncount);
int main(void)
{
RCC_Config();
GPIO_Config();
NVIC_Config();
EXTI_Config();
while(1)
{
GPIO_SetBits(GPIOD , GPIO_Pin_3);
GPIO_ResetBits(GPIOD , GPIO_Pin_4|GPIO_Pin_7|GPIO_Pin_13);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
GPIO_SetBits(GPIOD , GPIO_Pin_4);
GPIO_ResetBits(GPIOD , GPIO_Pin_3|GPIO_Pin_7|GPIO_Pin_13);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
GPIO_SetBits(GPIOD , GPIO_Pin_7);
GPIO_ResetBits(GPIOD , GPIO_Pin_4|GPIO_Pin_3|GPIO_Pin_13);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
GPIO_SetBits(GPIOD , GPIO_Pin_13);
GPIO_ResetBits(GPIOD , GPIO_Pin_4|GPIO_Pin_7|GPIO_Pin_3);
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
}
}
//延时程序
void Delay(vu32 ncount)
{
for(;ncount!=0;ncount--);
}
//步骤一系统初始化,使用固件模板中自带的SystemInit();函数即可。
void RCC_Config(void)
{
SystemInit();
//该函数配置系统时钟,其函数原型在system_stm32f10x.c
//RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO , ENABLE);
//使能所用时钟,主要是各个GPIO时钟,不要忘记RCC_APB2Periph_AFIO时钟使能
}
//步骤二GPIO 配置 ,使用 GPIO_Config()函数
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);
/*
* LD1 -> PD7 , LD2 -> PD13 , LD3 -> PD3 , LD4 -> PD4
* B3 -> PB8 , B4-> PC13
*/
RCC->APB2ENR|=0x09;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 |GPIO_Pin_13|GPIO_Pin_3|GPIO_Pin_4; //配置PD为输出模式,由CPU驱动LED点亮
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //配置PB8为浮空输入模式FLOATING,触发中断1--IPU 上拉
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //配置PC13为浮空输入模式,触发中断2
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
//步骤三EXTI 的配置。此步相当于单片机的中断配置,使用 EXTI_Config()函数
void EXTI_Config(void)
{
/* Initialize the EXTI Init Structure parameters */
EXTI_InitTypeDef EXTI_InitStructure; //声明语句 要写在前面,一句就可以了
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); // 管脚选择
EXTI_ClearITPendingBit(EXTI_Line9); //清除中断标志位,进入中断后,先做清除中断标志位,否则它会不断响应中断,不断进入中断函数。
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //上升下降沿都触发 Falling Rising
EXTI_InitStructure.EXTI_Line = EXTI_Line9; //EXTI_Line8,这个表示的是中断线8。对于外部中断中的GPIO,有16 个中断线,分别是0-15,刚好对应于每个GPIO 端口的0-15 引脚。
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //启动中断的接收
EXTI_Init(&EXTI_InitStructure); //外部中断启动
EXTI_GenerateSWInterrupt(EXTI_Line9);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line13);
}
//步骤四NVIC 配置。先解释下NVIC,它的中文全称是“嵌套向量中断控制器"。用的是NVIC_Config()函数
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //for中断1
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //for中断2
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//步骤五中断服务子程序的编写。
void EXTI9_IRQHandler(void) //中断1
{
if ( EXTI_GetITStatus(EXTI_Line9) != RESET ) //判断外部中断1的标志位是否为1,
{
EXTI_ClearITPendingBit(EXTI_Line9); //若外部中断1的标志位为1,则清中断标志位
GPIO_ResetBits(GPIOD , GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_7|GPIO_Pin_13); //给PD口的3、4、7、13脚置0
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
EXTI_ClearFlag( EXTI_Line9); //清中断标志
}
}
void EXTI13_IRQHandler(void) //中断2
{
if ( EXTI_GetITStatus(EXTI_Line13) != RESET )
{
EXTI_ClearITPendingBit(EXTI_Line13); //清中断
GPIO_SetBits(GPIOD , GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_7|GPIO_Pin_13); //给PD口的3、4、7、13脚置1(set)
Delay(0xfffff);
Delay(0xfffff);
Delay(0xfffff);
EXTI_ClearFlag( EXTI_Line13); //清中断标志
}
}
此帖出自
小平头技术问答
帮看看.s文件里改后的部分,改的对么?
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD TAMPER_IRQHandler ; Tamper
DCD RTC_IRQHandler ; RTC
DCD FLASH_IRQHandler ; Flash
DCD RCC_IRQHandler ; RCC
DCD EXTI0_IRQHandler ; EXTI Line 0
DCD EXTI1_IRQHandler ; EXTI Line 1
DCD EXTI2_IRQHandler ; EXTI Line 2
DCD EXTI3_IRQHandler ; EXTI Line 3
DCD EXTI4_IRQHandler ; EXTI Line 4
DCD DMAChannel1_IRQHandler ; DMA Channel 1
DCD DMAChannel2_IRQHandler ; DMA Channel 2
DCD DMAChannel3_IRQHandler ; DMA Channel 3
DCD DMAChannel4_IRQHandler ; DMA Channel 4
DCD DMAChannel5_IRQHandler ; DMA Channel 5
DCD DMAChannel6_IRQHandler ; DMA Channel 6
DCD DMAChannel7_IRQHandler ; DMA Channel 7
DCD ADC_IRQHandler ; ADC
DCD USB_HP_CAN_TX_IRQHandler ; USB High Priority or CAN TX
DCD USB_LP_CAN_RX0_IRQHandler ; USB Low Priority or CAN RX0
DCD CAN_RX1_IRQHandler ; CAN RX1
DCD CAN_SCE_IRQHandler ; CAN SCE
DCD EXTI9_IRQHandler ; EXTI Line 9..5
DCD TIM1_BRK_IRQHandler ; TIM1 Break
DCD TIM1_UP_IRQHandler ; TIM1 Update
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM4_IRQHandler ; TIM4
DCD I2C1_EV_IRQHandler ; I2C1 Event
DCD I2C1_ER_IRQHandler ; I2C1 Error
DCD I2C2_EV_IRQHandler ; I2C2 Event
DCD I2C2_ER_IRQHandler ; I2C2 Error
DCD SPI1_IRQHandler ; SPI1
DCD SPI2_IRQHandler ; SPI2
DCD USART1_IRQHandler ; USART1
DCD USART2_IRQHandler ; USART2
DCD USART3_IRQHandler ; USART3
DCD EXTI13_IRQHandler ; EXTI Line 15..10
DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
Default_Handler PROC
EXPORT WWDG_IRQHandler [WEAK]
EXPORT PVD_IRQHandler [WEAK]
EXPORT TAMPER_IRQHandler [WEAK]
EXPORT RTC_IRQHandler [WEAK]
EXPORT FLASH_IRQHandler [WEAK]
EXPORT RCC_IRQHandler [WEAK]
EXPORT EXTI0_IRQHandler [WEAK]
EXPORT EXTI1_IRQHandler [WEAK]
EXPORT EXTI2_IRQHandler [WEAK]
EXPORT EXTI3_IRQHandler [WEAK]
EXPORT EXTI4_IRQHandler [WEAK]
EXPORT DMAChannel1_IRQHandler [WEAK]
EXPORT DMAChannel2_IRQHandler [WEAK]
EXPORT DMAChannel3_IRQHandler [WEAK]
EXPORT DMAChannel4_IRQHandler [WEAK]
EXPORT DMAChannel5_IRQHandler [WEAK]
EXPORT DMAChannel6_IRQHandler [WEAK]
EXPORT DMAChannel7_IRQHandler [WEAK]
EXPORT ADC_IRQHandler [WEAK]
EXPORT USB_HP_CAN_TX_IRQHandler [WEAK]
EXPORT USB_LP_CAN_RX0_IRQHandler [WEAK]
EXPORT CAN_RX1_IRQHandler [WEAK]
EXPORT CAN_SCE_IRQHandler [WEAK]
EXPORT EXTI9_IRQHandler [WEAK]
EXPORT TIM1_BRK_IRQHandler [WEAK]
EXPORT TIM1_UP_IRQHandler [WEAK]
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
EXPORT TIM1_CC_IRQHandler [WEAK]
EXPORT TIM2_IRQHandler [WEAK]
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM4_IRQHandler [WEAK]
EXPORT I2C1_EV_IRQHandler [WEAK]
EXPORT I2C1_ER_IRQHandler [WEAK]
EXPORT I2C2_EV_IRQHandler [WEAK]
EXPORT I2C2_ER_IRQHandler [WEAK]
EXPORT SPI1_IRQHandler [WEAK]
EXPORT SPI2_IRQHandler [WEAK]
EXPORT USART1_IRQHandler [WEAK]
EXPORT USART2_IRQHandler [WEAK]
EXPORT USART3_IRQHandler [WEAK]
EXPORT EXTI13_IRQHandler [WEAK]
EXPORT RTCAlarm_IRQHandler [WEAK]
EXPORT USBWakeUp_IRQHandler [WEAK]
WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMAChannel1_IRQHandler
DMAChannel2_IRQHandler
DMAChannel3_IRQHandler
DMAChannel4_IRQHandler
DMAChannel5_IRQHandler
DMAChannel6_IRQHandler
DMAChannel7_IRQHandler
ADC_IRQHandler
USB_HP_CAN_TX_IRQHandler
USB_LP_CAN_RX0_IRQHandler
CAN_RX1_IRQHandler
CAN_SCE_IRQHandler
EXTI9_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI13_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
一周热门 更多>