EXTI_Init(&EXTI_InitStructure); //完成配置
GPIO_EXTILineConfig(Key2_EXTI_PortSource,Key2_EXTI_PinSource);
EXTI_InitStructure.EXTI_Line =Key2_EXTI_Line;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(Key3_EXTI_PortSource,Key3_EXTI_PinSource);
EXTI_InitStructure.EXTI_Line =Key3_EXTI_Line;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(Key4_EXTI_PortSource,Key4_EXTI_PinSource);
EXTI_InitStructure.EXTI_Line =Key4_EXTI_Line;
EXTI_Init(&EXTI_InitStructure);
}
void Key_NVIC(void)
{
NVIC_InitTypeDef
NVIC_InitStructure;
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0000); //NVIC起始地址在FLASH非外部SRAM
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //优先级分组方式
NVIC_InitStructure.NVIC_IRQChannel =Key1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel =Key2_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel =Key3_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel =Key4_IRQn;
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_Init(&NVIC_InitStructure);
}
#endif
#ifndef _KEY_H
#define _KEY_H
#include"stm32f10x.h"
#define Key_Interrupt
#define Key1_RCC
RCC_APB2Periph_GPIOA
#define Key1_Port
GPIOA
#define Key1_Pin
GPIO_Pin_0
#define Key1_EXTI_Line
EXTI_Line0
#define Key1_EXTI_PortSource GPIO_PortSourceGPIOA
#define Key1_EXTI_PinSource
GPIO_PinSource0
#define Key1_IRQn
EXTI0_IRQn
#define Key2_RCC RCC_APB2Periph_GPIOC
#define Key2_Port GPIOC
#define Key2_Pin GPIO_Pin_13
#define Key2_EXTI_Line EXTI_Line13
#define Key2_EXTI_PortSource GPIO_PortSourceGPIOC
#define Key2_EXTI_PinSource GPIO_PinSource13
#define Key2_IRQn EXTI15_10_IRQn
#define Key3_RCC RCC_APB2Periph_GPIOA
#define Key3_Port GPIOA
#define Key3_Pin GPIO_Pin_1
#define Key3_EXTI_Line EXTI_Line1
#define Key3_EXTI_PortSource GPIO_PortSourceGPIOA
#define Key3_EXTI_PinSource GPIO_PinSource1
#define Key3_IRQn EXTI1_IRQn
#define Key4_RCC RCC_APB2Periph_GPIOC
#define Key4_Port GPIOC
#define Key4_Pin GPIO_Pin_3
#define Key4_EXTI_Line EXTI_Line3
#define Key4_EXTI_PortSource GPIO_PortSourceGPIOC
#define Key4_EXTI_PinSource GPIO_PinSource3
#define Key4_IRQn EXTI3_IRQn
typedef enum{KeyNone=0,Key1=1,Key2=2,Key3=3,Key4=4}KeyNumber;
#ifdef Key_Polling
void Key_Init(void);
KeyNumber Get_Key_Number(void);
#endif
#ifdef Key_Interrupt
void Key_Init(void);
void Key_EXTI(void);
void Key_NVIC(void);
#endif
#endif
3.上led.c与led.h代码
#include"stm32f10x.h"
#include"led.h"
static void Delay(vu32 Time)
{
for(;Time!=0;Time--);
}
void Led_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(Led1_RCC,ENABLE); //all led use GPIOF
#ifdef Degub //在led.h中定义
GPIO_DeInit(Led1_Port); //GPIO外设设置为缺省值
GPIO_StructInit(&GPIO_InitStructure); //将GPIO_InitStructure按缺省值填入
GPIO_PinLockConfig(Led1_Port,Led1_Pin); //锁定LED1使用的IO引脚
#endif
#if 1
GPIO_InitStructure.GPIO_Pin=Led1_Pin|Led2_Pin|Led3_Pin|Led4_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(Led1_Port,&GPIO_InitStructure); //all led use GPIOF
LedAll_On;
Delay(0x6fffff);
LedAll_Off;
#endif
#if 0
GPIO_InitStructure.GPIO_Pin=Led1_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(Led1_Port,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=Led2_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;