开关控制led灯
This commit is contained in:
29
BSP/Key.c
Normal file
29
BSP/Key.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "stm32f10x.h"
|
||||
#include "Delay.h"
|
||||
|
||||
void Key_Init(void) {
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_11;
|
||||
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
uint8_t Key_GetNum(void) {
|
||||
uint8_t KeyNum = 0;
|
||||
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0) {
|
||||
Delay_ms(10);
|
||||
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0);
|
||||
KeyNum = 1;
|
||||
}
|
||||
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0) {
|
||||
Delay_ms(10);
|
||||
while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0);
|
||||
KeyNum = 2;
|
||||
}
|
||||
|
||||
return KeyNum;
|
||||
}
|
||||
8
BSP/Key.h
Normal file
8
BSP/Key.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __KEY_H
|
||||
#define __KEY_H
|
||||
|
||||
void Key_Init(void);
|
||||
|
||||
uint8_t Key_GetNum(void);
|
||||
|
||||
#endif
|
||||
44
BSP/LED.c
Normal file
44
BSP/LED.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void LED_Init(void) {
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
|
||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_0 | GPIO_Pin_1);
|
||||
}
|
||||
|
||||
void LED0_ON(void) {
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
|
||||
}
|
||||
|
||||
void LED0_OFF(void) {
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_0);
|
||||
}
|
||||
|
||||
void LED0_TOGGLE(void) {
|
||||
if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_0) == 0) {
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_0);
|
||||
}else {
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_0);
|
||||
}
|
||||
}
|
||||
|
||||
void LED1_ON(void) {
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
|
||||
}
|
||||
|
||||
void LED1_OFF(void) {
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_1);
|
||||
}
|
||||
|
||||
void LED1_TOGGLE(void) {
|
||||
if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_1) == 0) {
|
||||
GPIO_SetBits(GPIOA, GPIO_Pin_1);
|
||||
}else {
|
||||
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user