首页 > 其他分享 >05-独立按键

05-独立按键

时间:2022-12-24 12:22:41浏览次数:42  
标签:P2 P0 05 独立 delay while state 按键 sbit

#include "reg52.h"

sbit S7 = P3^0;
sbit S6 = P3^1;
sbit S5 = P3^2;
sbit S4 = P3^3;

sbit L1 = P0^0;
sbit L2 = P0^1;
sbit L3 = P0^2;
sbit L4 = P0^3;


void SelectHC573(unsigned char n)
{
	switch(n)
	{
        case 4:
			P2 = (P2 & 0x1f) | 0x80;
        	break;
		
        case 5:
			P2 = (P2 & 0x1f) | 0xa0;
        	break;
		
		case 6:
			P2 = (P2 & 0x1f) | 0xc0;
        	break;
		
		case 7:
			P2 = (P2 & 0x1f) | 0xe0;
        	break;
	}
}

void delay(unsigned char t)
{
	while(t--);
}


void ScanKey()
{
	if(S7 == 0)
	{
		delay(100);
		if(S7 == 0)
		{
			L1 = 0;
			while(S7 = 0);
			L1 = 1;
		}
	}
	
	if(S6 == 0)
	{
		delay(100);
		if(S6 == 0)
		{
			L2 = 0;
			while(S6 = 0);
			L2 = 1;
		}
	}
	
	if(S5 == 0)
	{
		delay(100);
		if(S5 == 0)
		{
			L3 = 0;
			while(S5 = 0);
			L3 = 1;
		}
	}
	
	if(S4 == 0)
	{
		delay(100);
		if(S4 == 0)
		{
			L4 = 0;
			while(S4 = 0);
			L4 = 1;
		}
	}
	

}
	



void main()
{
	SelectHC573(4);
	while(1)
	{
		ScanKey();
	}
}

#include "reg52.h"

sbit S7 = P3^0;
sbit S6 = P3^1;
sbit S5 = P3^2;
sbit S4 = P3^3;

sbit L1 = P0^0;
sbit L2 = P0^1;
sbit L3 = P0^2;
sbit L4 = P0^3;
sbit L5 = P0^3;
sbit L6 = P0^3;


void SelectHC573(unsigned char n)
{
	switch(n)
	{
        case 4:
			P2 = (P2 & 0x1f) | 0x80;
        	break;
		
        case 5:
			P2 = (P2 & 0x1f) | 0xa0;
        	break;
		
		case 6:
			P2 = (P2 & 0x1f) | 0xc0;
        	break;
		
		case 7:
			P2 = (P2 & 0x1f) | 0xe0;
        	break;
	}
}

void delay(unsigned char t)
{
	while(t--);
}

unsigned char state = 0;

void ScanKey()
{
	if(S7 == 0)
	{
		delay(100);
		if(S7 == 0)
		{
			if(state == 0)
			{
				L1 = 0;
				state = 1;
			}
			else if(state == 1)
			{
				L1 = 1;
				state = 0;
			}
			while(S7 ==0);
		}
	}
	
	if(S6 == 0)
	{
		delay(100);
		if(S6 == 0)
		{
			if(state == 0)
			{
				L2 = 0;
				state = 2;
			}
			else if(state == 2)
			{
				L2 = 1;
				state = 0;
			}
			while(S6 ==0);
		}
	}
	
	if(S5 == 0)
	{
		delay(100);
		if(S5 == 0)
		{
			if(state == 1)
			{
				L3 = 0;
				while(S5 ==0);
				L3 = 1;
			}
			else if(state == 2)
			{
				L5 = 0;
				while(S5 ==0);
				L5 = 1;
			}
		}
	}
	
	if(S4 == 0)
	{
		delay(100);
		if(S4 == 0)
		{
			if(state == 1)
			{
				L4 = 0;
				while(S4 ==0);
				L4 = 1;
			}
			else if(state == 2)
			{
				L6 = 0;
				while(S4 ==0);
				L6 = 1;
			}
		}
	}
	

}
	



void main()
{
	SelectHC573(4);
	while(1)
	{
		ScanKey();
	}
}

 

标签:P2,P0,05,独立,delay,while,state,按键,sbit
From: https://www.cnblogs.com/Unclesundada/p/17002736.html

相关文章

  • 每日食词—day059
    protectiveadj. n.防护的、给予保护的、保护的、保护assoonas一……就……quantityn.量、数量、值grantv. n.授权、授予、允许、给予、承认servern.......
  • P8294 [省选联考 2022] 最大权独立集问题
    题解可以发现对于一个子树,假设移出的点为\(u\),移入的点到\(v\),那么这棵子树的根一定是\(LCA(u,v)\).于是可以设\(dp_{u,v}\)表示在以\(LCA(u,v)\)为根的子树......
  • 省选05. 线性代数
    P6772[NOI2020]美食家先假设没有美食节,容易得到一个矩阵优化的dp。加上美食节过后分成\(k\)段考虑,每段分别矩阵快速幂,时间复杂度为\(O((5n)^3k\logT)\)。这并不......
  • 每日食词—day058
    topup加满、装满、充值certificaten. v.凭证、证书、认证、证明书persistv.坚持、持续、保持、固执manuallyadv.手动、手工地、人工、用手kerneln.......
  • 力扣-105-从前序与中序遍历序列构造二叉树/剑指Offer-07
    基本步骤是这样:先看先序序列,可以确定根节点,然后在中序遍历中就可以将二叉树划成左子树和右子树两拨对左右子树递归上述步骤好像直到怎么遍历二叉树,却对怎么重建二叉树......
  • 每日食词—day057
    gendern.性别freeadj. adv. v. n.空闲的、自由的、自由、免费、释放、无、空闲、闲置librariesn.图书馆、(程序)库、文件库、函数库compilingn. v.编译......
  • Spring Security系列教程05--实现Form表单认证
    实现Form表单认证前言在上一章节中,​​一一哥​​带大家认识了SpringSecurity中的第一种认证方式,但是这种基本认证的方式,UI效果不漂亮,安全性也很差,好像一无是处的样子,那么......
  • Day17_05_SpringCloud教程之Eureka实战
    SpringCloud之Eureka实战一.版本说明本案例采用的SpringBoot版本为2.0.3.RELEASE,SpringCloud版本为Finchley.RELEASE.二.创建主工程1.项目结构主工程目录结构如下图所......
  • Day07_05_分布式教程之分布式事务详解
    分布式事务详解一.分布式事务的概念随着分布式计算的发展,事务在分布式计算领域也得到了广泛的应用.在单机数据库中,我们很容易能够实现一套满足 ​​ACID​​ 特性的事......
  • SpringBoot2.x系列教程19--Web开发05之XML方式实现SSM整合
    SpringBoot系列教程19--Web开发05之XML方式实现SSM整合作者:一一哥注意:本系列教程案例继续在之前的基础上进行编写!SpringBoot可以帮助我们快速搭建一个SSM框架环境,那么该怎......