当前位置:网站首页>Simple password lock
Simple password lock
2022-07-03 06:23:00 【Bitongo】
This section simulates the smart door lock , be based on 51 The four digit simple password lock made under the single chip microcomputer
The modules used are LCD1602 LCD screen ( Used to display the entered password ) and Matrix key ( Used to enter a password )
The specific code is as follows :
LCD1602 Previously described in detail , Only the functions that need to be used are listed here , For details, please click “ LCD1602 Liquid crystal display (LCD) ”
LCD1602.c
/** * @brief stay LCD1602 Start displaying the given number at the specified position * @param Line Start line position , Range :1~2 * @param Column Start column position , Range :1~16 * @param Number Number to display , Range :0~65535 * @param Length The length of the number to display , Range :1~5 * @retval nothing */
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 stay LCD1602 Start displaying the given string at the specified position * @param Line Start line position , Range :1~2 * @param Column Start column position , Range :1~16 * @param String String to display * @retval nothing */
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 initialization
LCD_ShowString(1,1,"Input Keys :"); //LCD display string
while(1)
{
t=MatrixKey(); // Get matrix keyboard key code
if(t) // If a key is pressed
{
if(t<=10)
{
if(cot<4)
{
keys=keys*10;
keys=keys+t%10;
cot++;
}
LCD_ShowNum(2,1,keys,4);//LCD Display password
}
if(t==11)
{
if(keys==1102)
{
LCD_ShowString(1,14,"OK ");
keys=0;
cot=0;
LCD_ShowNum(2,1,keys,4);//LCD Display password
}
else
{
LCD_ShowString(1,14,"ERR");
keys=0;
cot=0;
LCD_ShowNum(2,1,keys,4);//LCD Display password
}
}
if(t==12)
{
keys=0;
cot=0;
LCD_ShowNum(2,1,keys,4);
}
}
}
}
边栏推荐
- Simple solution of small up main lottery in station B
- GPS坐标转百度地图坐标的方法
- Openresty best practices
- Mysql database binlog log enable record
- Zhiniu stock -- 03
- Use selenium to climb the annual box office of Yien
- Migrate data from Mysql to tidb from a small amount of data
- Cesium 点击获三维坐标(经纬度高程)
- Mysql database
- The win7 computer can't start. Turn the CPU fan and stop it
猜你喜欢

Important knowledge points of redis

Push box games C #

Zhiniu stock project -- 04

Svn branch management

Kubernetes notes (II) pod usage notes

从小数据量分库分表 MySQL 合并迁移数据到 TiDB

Kubesphere - build Nacos cluster

Kubernetes notes (VIII) kubernetes security

Read blog type data from mysql, Chinese garbled code - solved

Kubesphere - build MySQL master-slave replication structure
随机推荐
phpstudy设置项目可以由局域网的其他电脑可以访问
Interface test weather API
Some thoughts on machine learning
UNI-APP中条件注释 实现跨段兼容、导航跳转 和 传参、组件创建使用和生命周期函数
Read blog type data from mysql, Chinese garbled code - solved
How to scan when Canon c3120l is a network shared printer
Oracle Database Introduction
Project summary --2 (basic use of jsup)
tabbar的设置
Selenium ide installation recording and local project maintenance
What's the difference between using the Service Worker Cache API and regular browser cache?
The most responsible command line beautification tutorial
Redis cluster creation, capacity expansion and capacity reduction
Cannot get value with @value, null
Cesium 点击获三维坐标(经纬度高程)
JMeter linked database
Mysql
从小数据量 MySQL 迁移数据到 TiDB
Cesium entity (entities) entity deletion method
SQL实现将多行记录合并成一行