当前位置:网站首页>简易密码锁
简易密码锁
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);
}
}
}
}
边栏推荐
- Mysql database table export and import with binary
- Use selenium to climb the annual box office of Yien
- Common interview questions
- 项目总结--04
- Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
- What's the difference between using the Service Worker Cache API and regular browser cache?
- JMeter performance automation test
- 23 design models
- Synthetic keyword and NBAC mechanism
- [set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
猜你喜欢
Tabbar settings
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
深入解析kubernetes controller-runtime
GPS坐标转百度地图坐标的方法
ruoyi接口权限校验
从小数据量 MySQL 迁移数据到 TiDB
多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
Core principles and source code analysis of disruptor
剖析虚幻渲染体系(16)- 图形驱动的秘密
Kubesphere - Multi tenant management
随机推荐
Use selenium to climb the annual box office of Yien
Shell conditional statement
Redis cluster creation, capacity expansion and capacity reduction
Leetcode solution - 02 Add Two Numbers
智牛股--03
Method of converting GPS coordinates to Baidu map coordinates
Install VM tools
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
BeanDefinitionRegistryPostProcessor
Cesium entity(entities) 实体删除方法
Maximum likelihood estimation, divergence, cross entropy
Beandefinitionregistrypostprocessor
CKA certification notes - CKA certification experience post
智牛股项目--05
Introduction to software engineering
Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
arcgis创建postgre企业级数据库
Mysql database table export and import with binary
Creating postgre enterprise database by ArcGIS
IE browser flash back, automatically open edge browser