当前位置:网站首页>Extended application of single chip microcomputer-06 independent key
Extended application of single chip microcomputer-06 independent key
2022-07-05 07:41:00 【LCH Nan'an】
subject :
Blue Bridge Cup MCU simulation schematic diagram : Blue Bridge Cup MCU simulation schematic diagram .pdsprj- Handout document resources -CSDN library
Circuit diagram :
Code :
# include<reg52.h>
// Decoder
sbit HC138_C = P2^7;
sbit HC138_B = P2^6;
sbit HC138_A = P2^5;
// LED
sbit L1 = P0^0;
sbit L2 = P0^1;
sbit L3 = P0^2;
sbit L4 = P0^3;
sbit L5 = P0^4;
sbit L6 = P0^5;
// Independent keyboard
sbit S7 = P3^0;
sbit S6 = P3^1;
sbit S5 = P3^2;
sbit S4 = P3^3;
void SwitchHC138(unsigned char channel)
{
switch(channel)
{
case 4:
HC138_C = 1;
HC138_B = 0;
HC138_A = 0;
break;
case 5:
HC138_C = 1;
HC138_B = 0;
HC138_A = 1;
break;
case 6:
HC138_C = 1;
HC138_B = 1;
HC138_A = 0;
break;
case 7:
HC138_C = 1;
HC138_B = 1;
HC138_A = 1;
break;
}
}
void DelayKeys(unsigned char t)
{
while(t--);
}
unsigned char flag=0;
void ScanKeys()
{
if(S7 == 0)
{
DelayKeys(100);
if(S7==0)
{
if(flag==0)
{
L1 = 0;
flag=1;
}
else if(flag == 1)
{
L1 = 1;
flag = 0;
}while(S7 == 0);
}
}
if(S6 == 0)
{
DelayKeys(100);
if(S6==0)
{
if(flag==0)
{
L2 = 0;
flag=2;
}
else if(flag == 2)
{
L2 = 1;
flag = 0;
}while(S6 == 0);
}
}
if(S5 == 0)
{
DelayKeys(100);
if(S5 == 0)
{
if(flag == 1)
{
L3 = 0;
while(S5 == 0); // Close when you let go L3
L3 = 1;
}
else if(flag == 2)// Close when you let go L4
{
L5 = 0;
while(S5 == 0);
L5 = 1;
}
}
}
if(S4 == 0)
{
DelayKeys(100);
if(S4 == 0)
{
if(flag == 1)
{
L4 = 0;
while(S4 == 0); // Close when you let go L3
L4 = 1;
}
else if(flag == 2)// Close when you let go L4
{
L6 = 0;
while(S4 == 0);
L6 = 1;
}
}
}
}
void Init()
{
SwitchHC138(7);
P0=0x00;
SwitchHC138(5);
P0=0x00;
SwitchHC138(4);
P0=0xff;
}
void main()
{
Init();
while(1)
{
ScanKeys();
}
}
边栏推荐
- Apple system optimization
- Idea shortcut key
- Set theory of Discrete Mathematics (I)
- Application of ultra pure water particle counter in electronic semiconductors
- Daily Practice:Codeforces Round #794 (Div. 2)(A~D)
- assert_ Usage of param function
- Simple use of timeunit
- P3D gauge size problem
- Web page Chinese display (print, etc.) GBK error, solution, software
- CADD course learning (6) -- obtain the existing virtual compound library (drugbank, zinc)
猜你喜欢
Daily Practice:Codeforces Round #794 (Div. 2)(A~D)
611. Number of effective triangles
Rough notes of C language (2) -- constants
CADD课程学习(5)-- 构建靶点已知的化合结构(ChemDraw)
611. 有效三角形的个数
Light up the running light, rough notes for beginners (1)
From then on, I understand convolutional neural network (CNN)
Rough notes of C language (1)
P3D gauge size problem
玩转gRPC—深入概念与原理
随机推荐
High end electronic chips help upgrade traditional oil particle monitoring
assert_ Usage of param function
Detailed explanation of C language pointer
RF ride side door processing of prompt box
Light up the running light, rough notes for beginners (1)
Don't confuse the use difference between series / and / *
I 用c I 实现队列
With the help of Navicat for MySQL software, the data of a database table in different or the same database link is copied to another database table
611. 有效三角形的个数
Pit record of Chmod 2 options in deepin
GPIO circuit principle of stm32
Miracast技术详解(一):Wi-Fi Display
Clickhouse database installation deployment and remote IP access
Efficiency difference: the add method used by the set directly and the add method used by the set after judgment
Apple animation optimization
UE5热更新-远端服务器自动下载和版本检测(SimpleHotUpdate)
Embedded AI intelligent technology liquid particle counter
How to realize audit trail in particle counter software
并查集理论讲解和代码实现
deepin 20 kivy unable to get a window, abort