#include "stm32f10x.h"
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure IO connected to LD1, LD2, LD3 and LD4 leds *********************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource8);
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
}
//系统中断管理
void EXIT_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStruct;
EXTI_InitStruct.EXTI_Line = EXTI_Line9;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
EXTI_GenerateSWInterrupt(EXTI_Line9);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the EXTI9_5 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//配置系统时钟,使能各外设时钟
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE );
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL ,ENABLE );
}
//配置所有外设
void Init_All_Periph(void)
{
RCC_Configuration();
EXIT_Configuration();
GPIO_Configuration();
NVIC_Configuration();
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
//发送开机信息
int main(void)
{
Init_All_Periph();
while(1)
{
GPIO_ResetBits(GPIOD, GPIO_Pin_8);
/* Insert delay */
// Delay(2000000);
/* Turn on LD2 and LD3 */
GPIO_ResetBits(GPIOD, GPIO_Pin_9 );
/* Turn off LD1 */
// Delay(2000000);
GPIO_ResetBits(GPIOD, GPIO_Pin_10 );
/* Turn off LD1 */
// Delay(2000000);
//
//// GPIO_ResetBits(GPIOD, GPIO_Pin_11 );
// GPIO_SetBits(GPIOD, GPIO_Pin_8);
// /* Insert delay */
// // Delay(2000000);
//
// /* Turn on LD2 and LD3 */
// GPIO_SetBits(GPIOD, GPIO_Pin_9 );
// /* Turn off LD1 */
// // Delay(2000000);
//
// GPIO_SetBits(GPIOD, GPIO_Pin_10 );
// /* Turn off LD1 */
// //
//
// GPIO_SetBits(GPIOD, GPIO_Pin_11 );
// Delay(2000000);
}
}
void EXTI9_5_IRQHandler(void)
{
//GPIO_SetBits(GPIOD, GPIO_Pin_8);
/* Insert delay */
// Delay(2000000);
/* Turn on LD2 and LD3 */
GPIO_SetBits(GPIOD, GPIO_Pin_9 );
/* Turn off LD1 */
// Delay(2000000);
GPIO_SetBits(GPIOD, GPIO_Pin_10 );
/* Turn off LD1 */
// GPIO_SetBits(GPIOD, GPIO_Pin_11 );
// Delay(2000000);
// GPIO_ResetBits(GPIOD, GPIO_Pin_8);
// /* Insert delay */
// // Delay(2000000);
//
// /* Turn on LD2 and LD3 */
// GPIO_ResetBits(GPIOD, GPIO_Pin_9 );
// /* Turn off LD1 */
// // Delay(2000000);
//
// GPIO_ResetBits(GPIOD, GPIO_Pin_10 );
// /* Turn off LD1 */
// Delay(2000000);
// GPIO_ResetBits(GPIOD, GPIO_Pin_11 );
}
此帖出自
小平头技术问答
而不是EXTI_ClearFlag( EXTI_Line9)
一周热门 更多>