当前位置:网站首页>简易密码锁
简易密码锁
2022-07-03 06:13:00 【比特冬哥】
本节为模拟智能门锁,基于51单片机下制作出的四位简易密码锁
用到的模块有LCD1602液晶屏(用于显示输入的密码)和矩阵按键(用于输入密码)
具体代码如下:
LCD1602前面已详细介绍,这里只列出需要用到的函数部分,了解详情请点击“ LCD1602液晶显示 ”
LCD1602.c
/** * @brief 在LCD1602指定位置开始显示所给数字 * @param Line 起始行位置,范围:1~2 * @param Column 起始列位置,范围:1~16 * @param Number 要显示的数字,范围:0~65535 * @param Length 要显示数字的长度,范围:1~5 * @retval 无 */
void LCD_ShowNum(unsigned char Line,unsigned char Column,unsigned int Number,unsigned char Length)
{
unsigned char i;
LCD_SetCursor(Line,Column);
for(i=Length;i>0;i--)
{
LCD_WriteData(Number/LCD_Pow(10,i-1)%10+'0');
}
}
/** * @brief 在LCD1602指定位置开始显示所给字符串 * @param Line 起始行位置,范围:1~2 * @param Column 起始列位置,范围:1~16 * @param String 要显示的字符串 * @retval 无 */
void LCD_ShowString(unsigned char Line,unsigned char Column,char *String)
{
unsigned char i;
LCD_SetCursor(Line,Column);
for(i=0;String[i]!='\0';i++)
{
LCD_WriteData(String[i]);
}
}
Matrixkey.c
unsigned char MatrixKey()
{
key=0x0f;
if(key!=0x0f)
{
Delay(100);
if(key!=0x0f)
{
key=0x0f;
switch(key)
{
case 0x07 : keyvalue=1;break;
case 0x0b : keyvalue=2;break;
case 0x0d : keyvalue=3;break;
case 0x0e : keyvalue=4;break;
}
key=0xf0;
switch(key)
{
case 0x70 : keyvalue=keyvalue;break;
case 0xb0 : keyvalue=keyvalue+4;break;
case 0xd0 : keyvalue=keyvalue+8;break;
case 0xe0 : keyvalue=keyvalue+12;break;
}
return keyvalue;
}
}
}
main.c
void main()
{
LCD_Init(); //LCD初始化
LCD_ShowString(1,1,"Input Keys :"); //LCD显示字符串
while(1)
{
t=MatrixKey(); //获取矩阵键盘键码
if(t) //如果有按键按下
{
if(t<=10)
{
if(cot<4)
{
keys=keys*10;
keys=keys+t%10;
cot++;
}
LCD_ShowNum(2,1,keys,4);//LCD显示密码
}
if(t==11)
{
if(keys==1102)
{
LCD_ShowString(1,14,"OK ");
keys=0;
cot=0;
LCD_ShowNum(2,1,keys,4);//LCD显示密码
}
else
{
LCD_ShowString(1,14,"ERR");
keys=0;
cot=0;
LCD_ShowNum(2,1,keys,4);//LCD显示密码
}
}
if(t==12)
{
keys=0;
cot=0;
LCD_ShowNum(2,1,keys,4);
}
}
}
}
边栏推荐
- Shell conditional statement
- Kubernetes notes (IX) kubernetes application encapsulation and expansion
- Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
- GPS坐标转百度地图坐标的方法
- Common interview questions
- 认识弹性盒子flex
- Kubernetes notes (VIII) kubernetes security
- [system design] proximity service
- Synthetic keyword and NBAC mechanism
- Jedis source code analysis (I): jedis introduction, jedis module source code analysis
猜你喜欢
Synthetic keyword and NBAC mechanism
Read blog type data from mysql, Chinese garbled code - solved
Understand the first prediction stage of yolov1
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
项目总结--2(Jsoup的基本使用)
智牛股--03
项目总结--01(接口的增删改查;多线程的使用)
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
Kubernetes notes (10) kubernetes Monitoring & debugging
Zhiniu stock project -- 04
随机推荐
技术管理进阶——你了解成长的全貌吗?
Decision tree of machine learning
Bio, NiO, AIO details
Cesium entity(entities) 实体删除方法
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
Migrate data from Amazon aurora to tidb
Kubernetes notes (VII) kuberetes scheduling
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
Alibaba cloud OOS file upload
Introduction to software engineering
Cannot get value with @value, null
Reinstalling the system displays "setup is applying system settings" stationary
SVN分支管理
After the Chrome browser is updated, lodop printing cannot be called
Kubernetes notes (IV) kubernetes network
JDBC connection database steps
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
Install VM tools
Synthetic keyword and NBAC mechanism