按键中断尝试

#include "stm32f10x.h"

void LED_GPIO_Config(void);
void interrupt_Init(void);
void key_Init(void);
int main(void)
{
    LED_GPIO_Config();
    interrupt_Init();
    key_Init();
    GPIO_SetBits(GPIOD,GPIO_Pin_7);
    while(1);
}

void LED_GPIO_Config(void)
{
    GPIO_InitTypeDef LED;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
    LED.GPIO_Mode=GPIO_Mode_Out_PP;
    LED.GPIO_Pin=GPIO_Pin_7;
    LED.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&LED);
}

void interrupt_Init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
    GPIO_InitTypeDef GPIO_IntStructure;
    GPIO_IntStructure.GPIO_Mode=GPIO_Mode_IPU;
    GPIO_IntStructure.GPIO_Pin=GPIO_Pin_0;
    GPIO_IntStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_IntStructure);
    
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource5); 
    EXTI_InitTypeDef EXTI_IntStructure;
    EXTI_IntStructure.EXTI_Line=EXTI_Line5;
    EXTI_IntStructure.EXTI_LineCmd=ENABLE;
    EXTI_IntStructure.EXTI_Mode=EXTI_Mode_Interrupt;
    EXTI_IntStructure.EXTI_Trigger=EXTI_Trigger_Falling;
    EXTI_Init(&EXTI_IntStructure);
    
    NVIC_InitTypeDef NVIC_IntStructure;
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
    NVIC_IntStructure.NVIC_IRQChannel=EXTI9_5_IRQn;
    NVIC_IntStructure.NVIC_IRQChannelCmd=ENABLE;
    NVIC_IntStructure.NVIC_IRQChannelPreemptionPriority=1;
    NVIC_IntStructure.NVIC_IRQChannelSubPriority=1;
    NVIC_Init(&NVIC_IntStructure);
}


void key_Init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
    GPIO_InitTypeDef GPIO_Inite;
    GPIO_Inite.GPIO_Mode=GPIO_Mode_IPU;
    GPIO_Inite.GPIO_Pin=GPIO_Pin_5;
    GPIO_Inite.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOC,&GPIO_Inite);
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值