当前位置:网站首页>51 single chip microcomputer key control LED light status
51 single chip microcomputer key control LED light status
2022-07-25 08:44:00 【Pear blossom presses Begonia】
Preface
Update the programming of the key module today
First look at the circuit diagram 
You can see ,K1,K2,K3 When not pressed ,KEY1,KEY2,KEY3 Three interfaces are connected with vcc Unicom , At high level .
When K1,K2,K3 When pressed ,vcc Connect with the earth ,KEY1,KEY2,KEY3 All are low level .
To sum up, we can see that , Press the switch interface to 0, Release the switch as 1.
Our goal is to use k1,k2,k3 Each control LED The lamp L0,L1,L2 On and off , Press the switch and the corresponding light will light up , Release the switch and the light goes out .
Let's take another look LED Circuit diagram of 
LED In the last article , It's just more here .
Let's take a look at the code :
#include <STC15F2K60S2.H>
sbit LedSel=P2^3;
sbit Key1=P3^2;
sbit Key2=P3^3;
sbit Key3=P1^7;
void Init(){
P2M0=0x08;
P2M1=0x00;
P0M0=0xff;
P0M1=0x00;
LedSel=1;
P0=0;
}
void main(){
Init();
while(1){
if(Key1==0)
P0=0x01;
else P0=0;
if(Key2==0)
P0=0x02;
else P0=0;
if(Key3==0)
P0 = 0x04;
else P0=0;
}
}
There is nothing obscure about the code , It is necessary to pay attention to writing else, Otherwise, the light will not go out after it is on .
The following is the effect of the code :
VID_20220719_093750
Postscript
That's all for the key module , If you have any questions, welcome to communicate
To be continued ······
边栏推荐
- Hash table questions (Part 1)
- Graduation project of wechat small program ordering system of small program completion works (6) opening defense ppt
- 【黑马程序员】Redis学习笔记003:Redis事务
- Chapter 3 business function development (modifying clues, data echo and modifying data)
- Centernet network structure construction
- Wechat Reservation Reservation of applet completion works applet graduation project (8) graduation project thesis template
- Unity client reading text configuration
- 递归调用实现打印一个整数的每一位
- 016 fundamentals of machine learning mathematics: Introduction
- serialization and deserialization
猜你喜欢

JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development

Wechat reservation applet graduation design of applet completion works (2) applet function

FreeMaker模板引擎

Centernet network structure construction

Graduation project of wechat small program ordering system of small program completion works (7) Interim inspection report

Review the second time, 220614, video, day03_ Data warehouse design,

机器人跳跃问题

Wechat reservation applet graduation design of applet completion works (3) background function

@Autowired注解的实现原理
![[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)](/img/07/235785b7658b5ae022dfa3f53ec86d.png)
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
随机推荐
Technical aspect ② what are the index types in MySQL and briefly introduce them? When do I need to create an index? When is it not necessary to create an index? Why does the query speed increase after
LeetCode·83双周赛·6129.全0子数组的数目·数学
Swift初始化器及可选链
uni-app
Qt|QLable多行展示时更改行间距
游戏外挂怎么做?
C语言基础
Foundation 32: page element positioning method XPath --- axis positioning method
@Use of data annotation (instead of get and set methods in entity classes)
Hash table questions (Part 1)
Database query optimization
PHP reports an error: classes\phpexcel\cell php Line(594) Invalid cell coordinate ESIGN1
Keep your Eyes on the Lane: Real-time Attention-guided Lane Detection
YOLOV5环境配置
51 MCU peripherals: buzzer
Blue and white porcelain used by Charles
Wechat sports ground reservation applet graduation design of applet completion works (2) applet function
QA robot sequencing model
51单片机内部外设:串口通信
OpenGL es to realize the visualization of real-time audio