当前位置:网站首页>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 ······
边栏推荐
- When easyexcel uses converter conversion to inject nullpoint exception
- This is the worst controller layer code I've ever seen
- JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
- Implementation of depth first and breadth first traversal of binary tree
- Hash table questions (Part 1)
- When crontab scheduled task executes jar through script, it encounters a pit where jar package execution is invalid
- 机器人跳跃问题
- Qt|QLable多行展示时更改行间距
- serialization and deserialization
- LeetCode·83双周赛·6129.全0子数组的数目·数学
猜你喜欢

Foundation 32: page element positioning method XPath --- axis positioning method

Initial knowledge of WebService (generate jar packages and call methods in remote services)

How to do the game plug-in?

Redis学习笔记

Record the process of two multi terminal troubleshooting

NVIDIA programmable reasoning accelerator tensorrt learning notes (II) - practical operation

Fundamentals of C language

递归调用实现打印一个整数的每一位

Source code of pet adoption management system implemented by ssm+jsp+mysql

How can hospitals achieve efficient and low-cost operation and maintenance? Is there any software that can meet it?
随机推荐
OpenGL es to realize the visualization of real-time audio
Unity client reading text configuration
Chapter 3 business function development (modifying clues, data echo and modifying data)
[dark horse programmer] redis learning notes 003: redis transactions
@Feignclient annotated interface. You may not get instances with @autowired
Wechat sports field reservation of the finished works of the applet graduation project (4) opening report
Wechat reservation of the completed works of the applet graduation project (6) opening defense ppt
Wechat Reservation Reservation of applet completion works applet graduation project (8) graduation project thesis template
When crontab scheduled task executes jar through script, it encounters a pit where jar package execution is invalid
51单片机外设篇:电机
Source code of short video live broadcast system
serialization and deserialization
Wechat sports ground reservation applet graduation project of applet completion works (1) development outline
Dirty data and memory leakage of ThreadLocal
51 MCU peripherals: buzzer
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
@Implementation principle of Autowired annotation
Redis learning notes
51单片机内部外设:定时器和计数器
Bigdecimel in words