当前位置:网站首页>简易密码锁
简易密码锁
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);
}
}
}
}
边栏推荐
- Read blog type data from mysql, Chinese garbled code - solved
- Kubernetes notes (IV) kubernetes network
- Detailed explanation of findloadedclass
- Redis cluster creation, capacity expansion and capacity reduction
- Method of converting GPS coordinates to Baidu map coordinates
- Simple understanding of ThreadLocal
- Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
- Kubernetes notes (III) controller
- IE browser flash back, automatically open edge browser
- Understand the first prediction stage of yolov1
猜你喜欢
![[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)](/img/a4/00aca72b268f77fe4fb24ac06289f5.jpg)
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)

Kubesphere - set up redis cluster

表达式的动态解析和计算,Flee用起来真香

Cesium 点击获三维坐标(经纬度高程)

多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)

智牛股项目--04

Project summary --2 (basic use of jsup)

Mysql

Scripy learning

Zhiniu stock project -- 04
随机推荐
Cannot get value with @value, null
ThreadLocal的简单理解
剖析虚幻渲染体系(16)- 图形驱动的秘密
Support vector machine for machine learning
Understand expectations (mean / estimate) and variances
Phpstudy setting items can be accessed by other computers on the LAN
BeanDefinitionRegistryPostProcessor
Pytorch dataloader implements minibatch (incomplete)
Detailed explanation of contextclassloader
Code generator - single table query crud - generator
Reinstalling the system displays "setup is applying system settings" stationary
What's the difference between using the Service Worker Cache API and regular browser cache?
Mysql database
MySQL帶二進制的庫錶導出導入
Some thoughts on machine learning
Loss function in pytorch multi classification
Printer related problem record
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
Leetcode solution - 02 Add Two Numbers
YOLOV1学习笔记