STMSTM32按键输入控制LED、蜂鸣器
基于stm32f407,为实现以上功能,可将问题分为三个部分:LED、蜂鸣器和按键输入。
led部分
LED部分 c文件中分为三部分:①使能IO口时钟,②初始化IO口模式,③使IO口输出高电平
#include "stm32f4xx.h"
#include "led.h"
void LED_Init()
{
GPIO_InitTypeDef GPIO_InitLed;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
GPIO_InitLed.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitLed.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitLed.GPIO_OType=GPIO_OType_PP;
GPIO_InitLed.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitLed.GPIO_Speed=GPIO_High_Speed;
GPIO_Init(GPIOF,&GPIO_InitLed);
GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);
}
h文件中对LED_Init 进行申明,同时对两个LED灯通过位带操作进行定义:
#include "stm32f4xx.h"
#ifndef __LED_H
#define __LED_H
#define LED0 PFout(9)
#
|