当前位置:网站首页>Touch key and key control corresponding LED status reversal
Touch key and key control corresponding LED status reversal
2022-06-29 22:42:00 【Let everything burn】
List of articles
Mission requirements :
As shown in the figure :
Task a :
Touch the key to control the corresponding LED State flip
Thought analysis :
Touch key implementation LED The principle of state reversal is the same as that of mechanical key , And there is no need to use delay jitter
.
Completion code
int main (void){
// The main program
RCC_Configuration(); // System clock initialization
LED_Init();//LED initialization
TOUCH_KEY_Init();// Key initialization
while(1){
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_C)){
// Read the level of the key interface
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_C)){
// Read the level of the key interface
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED1))); //LED Take the opposite
while(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_C)); // Wait for the key to release Prevent the program from running repeatedly without releasing the key
}
}
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_D)){
// Read the level of the key interface
if(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_D)){
// Read the level of the key interface
GPIO_WriteBit(LEDPORT,LED2,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED2))); //LED Take the opposite
while(!GPIO_ReadInputDataBit(TOUCH_KEYPORT,TOUCH_KEY_D)); // Wait for the key to release Prevent the program from running repeatedly without releasing the key
}
}
}
}
Task 2 :
Key control corresponds to LED State flip
Code :
//main.c
int main (void){
// The main program
// Initializer
RCC_Configuration(); // The clock is set
LED_Init();//LED initialization
KEY_Init();// Key initialization
// Main circulation
// Initialization start LED Is off
GPIO_WriteBit(LEDPORT,LED3,(BitAction)(1));
GPIO_WriteBit(LEDPORT,LED4,(BitAction)(1));
while(1){
// There is a latch
if(!GPIO_ReadInputDataBit(KEYPORT,KEY1)){
// Read the level of the key interface
delay_ms(20); // Delay de jitter
if(!GPIO_ReadInputDataBit(KEYPORT,KEY1)){
// Read the level of the key interface
GPIO_WriteBit(LEDPORT,LED3,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED3))); //LED Take the opposite
while(!GPIO_ReadInputDataBit(KEYPORT,KEY1)); // Wait for the key to release
}
}
if(!GPIO_ReadInputDataBit(KEYPORT,KEY2)){
// Read the level of the key interface
delay_ms(20); // Delay de jitter
if(!GPIO_ReadInputDataBit(KEYPORT,KEY2)){
// Read the level of the key interface
GPIO_WriteBit(LEDPORT,LED4,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED4))); //LED Take the opposite
while(!GPIO_ReadInputDataBit(KEYPORT,KEY2)); // Wait for the key to release
}
}
}
}
Be careful :
The corresponding should also be modified , Because the two one. LED The corresponding interface is inconsistent with that of the two small lights on the core board
led.h
#define LEDPORT GPIOA // Definition IO Interface
#define LED3 GPIO_Pin_2 // Definition IO Interface
#define LED4 GPIO_Pin_3 // Definition IO Interface
led.c
void LED_Init(void){
//LED Lamp interface initialization
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin = LED3; // Select the port number (0~15 or all)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // choice IO How the interface works
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Set up IO Interface speed (2/10/50MHz)
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
边栏推荐
- Qt5.14.2 error connecting to the MySQL database of Ubuntu 20.04
- STM32基础知识点
- Spark cluster installation
- Hidden worries behind the listing of shushulang: the performance has declined significantly, the market position is relatively backward, and the competitiveness is questionable
- laravel 关联模型 多态关系
- grpc的开发详解
- What if MySQL fails to store emoticons
- Unicom warehousing | all Unicom companies that need to sell their products need to enter the general warehouse first
- static关键字续、继承、重写、多态
- 请教一下,CDC2.2.1可以同时监听多个pgsql 的库吗?
猜你喜欢

从第三次技术革命看企业应用三大开发趋势

一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】

把数组排成最小的数_数组中的逆序对(归并统计法)_数字在升序数组中出现的次数_丑数(剑指offer)

leetcode:91. 解码方法【dfs + 记忆化】

The soft youth under the blessing of devcloud makes education "smart" in the cloud

Huawei's software testing director with 7 years' experience, several suggestions for all students who want to switch to software testing

每日刷题记录 (八)

2022 (第五届)GIS软件技术大会开幕,GIS、IT将加速融合
Why does copying files on a shared folder on a local area network (ERP server) result in the loss of the local Internet

Code sharing for making and developing small programs on the dating platform
随机推荐
论文浅尝 | KR-GCN: 知识感知推理的可解释推荐系统
jfinal中如何使用过滤器监控Druid监听SQL执行?
Three development trends of enterprise application viewed from the third technological revolution
5-2Web应用程序漏洞扫描
软件快速交付真的需要以安全为代价吗?
Daily question brushing record (VIII)
服务器快速搭建AList集成网盘网站【宝塔面板一键部署AList】
Detailed description of gaussdb (DWS) complex and diverse resource load management methods
【多线程】 如何自己实现定时器
为什么在局域网(ERP服务器)共享文件夹上拷贝文件时导致全局域英特网断网
稳!上千微服务接入 Zadig 的最佳姿势(Helm Chart 篇)
科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度
低代码、端到端,一小时构建IoT示例场景,声网发布灵隼物联网云平台
LeetCode85+105+114+124
掌握这28张图,面试再也不怕被问TCP知识了
laravel 关联模型 多态关系
Processing of error b6267342 reported by AIX small machine in production environment
MySQL lock common knowledge points & summary of interview questions
Does rapid software delivery really need to be at the cost of security?
关于深度学习的概念理解(笔记)