C51 单片机 矩阵按键具有更改密码功能,密码正确,P1口小灯全亮

黄色部分少了两个等于符号,打不上去,头一次写,请多谅解
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar count=0,num=10;
uchar mima_init=54;
uchar shi=0;
uchar ge=0;
uchar mimahecheng=0;
sbit beep=P2^3;
sbit key0=P2^4;
sbit key1=P2^5;
sbit key2=P2^6;
sbit key3=P2^7;
sbit key4=P3^0;
sbit key5=P3^1;
sbit key6=P3^2;
sbit key7=P3^3;
sbit key8=P3^4;
sbit key9=P3^5;
sbit queren=P3^7;
sbit genggai=P3^6;
void delay(uint i)
{
uint x,y;
for(x=0;x<255;x++)
for(y=0;y<i;y++);
}
void keyscan()
{
if(key00)
{
delay(10);
if(key0=0)
{
num=0;
count++;
}
while(key0
0);
}
if(key10)
{
delay(10);
if(key1
0)
{
num=1;
count++;
}
while(key10);
}
if(key2
0)
{
delay(10);
if(key20)
{
num=2;
count++;
}
while(key2
0);
}
if(key30)
{
delay(10);
if(key3
0)
{
num=3;
count++;
}
while(key30);
}
if(key4
0)
{
delay(10);
if(key40)
{
num=4;
count++;
}
while(key4
0);
}
if(key50)
{
delay(10);
if(key5
0)
{
num=5;
count++;
}
while(key50);
}
if(key6
0)
{
delay(10);
if(key60)
{
num=6;
count++;
}
while(key6
0);
}
if(key70)
{
delay(10);
if(key7
0)
{
num=7;
count++;
}
while(key70);
}
if(key8
0)
{
delay(10);
if(key80)
{
num=8;
count++;
}
while(key8
0);
}
if(key90)
{
delay(10);
if(key9
0)
{
num=9;
count++;
}
while(key90);
}
}
void chuli()
{
if(count
1)
shi=num;
if(count2)
ge=num;
mimahecheng=shi*10+ge;
}
void xiugai()
{
if(genggai
0)
{
delay(10);
if(genggai0)
{
keyscan();
if(count
1)
shi=num;
if(count2)
ge=num;
mima_init=shi*10+ge;
while(genggai
0);
}
}
}
void yanzheng()
{

if(queren==0)
{
   delay(10);
	if(queren==0)
	{
		if(mimahecheng==mima_init)
		{
			 P1=0;
		}
		else
		{
			beep=0;
			P1=0xff;
		}
		count=0;
		shi=0;
		ge=0;
	    while(queren==0); 
	}
}

}

void main()
{
while(1)
{
keyscan();
chuli();
yanzheng();
xiugai();
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西楼^o^

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值