一、适用功能
检测按键,光电开关,水位传感器等检测 GPIO 输入电平信号。
二、 硬件设计(参考)
三、 软件设计
① 使用到的固件库文件
#include stm32f10x_gpio.c/stm32f10x_gpio.h
#include stm32f10x_rcc.c/stm32f10x_rcc.h
② 代码整理
- delay.h
#ifndef __DELAY_H
#define __DELAY_H
#include "stm32f10x.h"
void Delay(__IO uint32_t nCount);
#endif
- delay.c
#include "delay.h"
void Delay(__IO uint32_t nCount) // 简单的延时函数
{
for(; nCount != 0; nCount--);
}
- led.h
#ifndef _LED_H
#define _LED_H
#include "stm32f10x.h"
void LED_Init(void);
void LED0_Level(unsigned char Level);
void LED1_Level(unsigned char Level);
#endif
- led.c
#include "led.h"
/*******************************************************************************
* 函 数 名 : LED_Init
* 函数功能 : LED初始化函数
* 输 入 : 无
* 输 出 : 无
* 说 明 :无
*******************************************************************************/
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // 使能PB端口时钟
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; // LED0-->PB.5 端口配置
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; // 推挽输出