基于51单片机的简易4位密码锁(液晶1602显示)

本文详细介绍了使用51单片机设计并实现一个4位数字密码锁的过程,通过液晶1602模块显示相关信息。文中涉及C语言编程,包括密码输入、比对与错误提示等功能实现。
摘要由CSDN通过智能技术生成
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^5;
sbit lcden=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
uchar new1,new2,new3,new4;
uchar number[]="1234";
uchar password[]="4321";
uchar cuowu[]="Error";
uchar zhengque[]="right";
uchar kaisuo[]="open";
uchar jinzhi[]="wait a minute";
uchar temp,key,wei,wanbi,allow,times,reset;
void delay(uint i)        //延时
{
	uint m,n;
	for(m=i;m>0;m--)
	for(n=114;n>0;n--);
}
void write_com(uchar com)        //写指令
{
	P0=com;
	rs=0;
	lcden=1;
	delay(10);
	lcden=0;
}
void write_dat(uchar dat)        //写数据
{
	P0=dat;
	rs=1;
	lcden=1;
	delay(10);
	lcden=0;
}
void init()            //初始化
{
	dula=0;
	wela=0;            //关数码管
	write_com(0x38);     
	write_com(0x0c);
	write_com(0x06);
}
void getkey()        //矩阵按键
{
	{	
    P3=0xfe;
    temp=P3;
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值