Initial password: 12345678
This program is implemented by using 51 single chip microcomputer to control 74LS164 latch
The MCU and the memory use IIC communication to establish the cryptographic system communication.
Simulation starts and password is set
Universal password lock reference program source code:
#include #include "intrins.h" #include "key.h" #include "xsh.h" #include "24c02.h" #define ulong unsigned long bit BJCB=0; //Alarm flag XG=0, //Change password flag BJ=0, //Alarm flag SJ=0; //Keyboard lock flag // xg=0; //Change password flag uchar PSWD0_0[16]={0}; //password input cache storage unit //uchar code PSWD0_1[16]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8}; //User initial password storage unit //uchar PSWD1_0[16]={0}; //Read the password cache storage unit uchar PSWD1_1[16]={1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8}; Administrator initial password storage unit sbit OUT=P3^5; //output port sbit L1=P0^2; //Power-on indication sbit L2=P0^1; //Unlock indication sbit L3=P0^0; //Alarm indication uint mg=0, //Number of passwords KSC=0, //Number of unlocking times BJC=0, //Number of alarms TCNTY=0, //User key timing count accumulation TCNTG=0, //Timed number of times the administrator enters the password yhsh, //User input flag glsh, //Administrator input flag shw; // Password input completed flag void yhmimaxig(); //password modification procedure void glmimaxig(); //Administrator modifies the program void bjyin(ulong t) { ulong c; uint n; for(c=0;c for(n=0;n<50;n++); //delay BEEP=~BEEP; //Invert the signal output to the speaker } } void delay_10ms(void) { uint i = 1000; while(i–); } //Timer interrupt service function// void timer0() interrupt 1 { uint i; TH0=(65536-50000)/256; //Assign 50MS timing to TH0 TL0 TL0=(65536-50000)%256; //Reload count initial value if(yhsh1) { TCNTY++; //User timing count if(shw1) { TR0=0; TCNTY=0; } if(TCNTY400) { TR0=0; //turn off T0 timer TCNTY=0; mg=0; //Password number cleared L1=1; for(i=0;i<2;i++)//sound and light alarm circuit { L3=0; bjyin(1000); L3=1; delay(1000); } L1=0; } } else if(glsh1) { TCNTG++; //Administrator timing count if(shw1) { TR0=0; TCNTG=0; } if(TCNTG400) { TR0=0; //turn off T0 timer TCNTG=0; mg=0; //Password number cleared L1=1; for(i=0;i<2;i++)//sound and light alarm circuit { L3=0; bjyin(1000); L3=1; delay(1000); } L1=0; } } } void main() { uint i; TMOD=0x01; //Timer works in mode 1 ET0=1; EA=1; TH0=(65536-50000)/256; //Assign value to TH0 TL0 TL0=(65536-50000)%256; // Make the timer interrupt once every 0.05 seconds //Read_page24c02(0x00,PSWD1_1,16); //Read the user's initial password from 24c02 //i2cWrite24LC16B(0,0X20); /Write the initial administrator password, user password, and unlock times into 24c02 for the first time/ for(i=0;i<16;i++) //Write one at a time to 24c02 { i2cWrite24LC16B(PSWD1_1[i],i); delay_10ms; } for(i=0;i<16;i++) //Write one at a time to 24c02 { i2cWrite24LC16B(PSWD1_1[i],0x10+i); delay_10ms; } //Used during proteus simulation, when burning the program, use it for the first time and not for the second time. KSC=i2cRead24LC16B(0X20); loop: L1=0; //The red light turns on when powered on L2=1; //The green light turns on after unlocking successfully L3=1; // Yellow light turns on to alarm when input is wrong OUT=0; //Open signal close display_0(KSC); //Display before unlocking ///Password input/ if(SJ0) //keyboard lock flag is 0 { do { flag=0; //Keyboard flag key(); if(flag1&&num12) //Judge whether the administrator function key is pressed { goto gl; } if(flag1&&num<=9) { PSWD0_0[mg]=num; mg++; //Number of passwords } if(flag1&&num14&&mg>=1)//delete input error { mg=mg-1; } if(mg1) //A password key is pressed to start the timer { TR0=1; yhsh=1; } } while(num!=15); if(mg!=16) { for(i=mg;i<16;i++) { PSWD0_0[i]=0; } } /Password comparison circuit if(flag1&&num==15) { flag=0; yhsh=0; shw=1; num=0; for(i=0;i<16;i++) //Read 16 passwords from 24c02 { PSWD1_1[i]=i2cRead24LC16B(i); delay_10ms; } for(i=0;i<16;i++) { if(PSWD1_1[i]!=PSWD0_0[i]) { BJCB=1; break; } else BJCB=0; } } if(BJCB!=0) { BJC++; if(BJC!=3) { BJCB=0; //First and second alarms delay(500); mg=0; //Password number cleared L1=1; for(i=0;i<3;i++)//sound and light alarm circuit { L3=0; display_3(); bjyin(1000); L3=1; delay(1000); } goto loop; } else if(BJC3) { BJC=0; BJCB=0; display_5(); //Failed to enter the password three times, self-lock SJ=1; //Keyboard lock flag mg=0; //Password number cleared L1=1; for(i=0;i<2;i++)//sound and light alarm circuit { L3=0; bjyin(1000); L3=1; delay(1000); } goto loop; } } else if(BJCB0) { KSC++; display_1(KSC); i2cWrite24LC16B(KSC,0X20); if(KSC100) { SJ=1; } L2=0; L1=1; OUT=1; mg=0; //Password number cleared loop1:do //keyboard scan and wait for function key to be pressed { flag=0; key(); if(flag) { flag=0; switch(num) { case 13: { display_2(); do { flag=0; //Keyboard flag key(); if(flag1&&num<=9) { PSWD0_0[mg]=num; mg++; //Number of passwords } if(flag1&&num14&&mg>=1)//delete input error { mg=mg-1; } if(mg16) { do //Keyboard scan waiting for function key to be pressed { flag=0; key(); } while(num!=15); } } while(num!=15); if(mg!=16&&num15) { for(i=mg;i<16;i++) { PSWD0_0[i]=0; } } if(flag1&&num15) { flag=0; mg=0; for(i=0;i<16;i++) //Write one at a time to 24c02 { i2cWrite24LC16B(PSWD0_0[i],i); delay_10ms; } display_1(KSC); do //Keyboard scan waiting for function key to be pressed { flag=0; key(); } while(num!=11); //Press the return key and the lock will return { goto loop; } } };break; case 11: { goto loop; //break; } } } } while(flag!=0); //If the password key is pressed goto loop1; // i2cWrite24c02_page(0x00,PSWD1_1,mg); } } else { do { flag=0; key(); } while(num!=12);//Judge whether the administrator function key is pressed gl:do//Administrator enters password { flag=0; key(); if(flag1&&num<=9) { PSWD0_0[mg]=num; mg++; //Number of passwords } if(flag1&&num14&&mg>=1)//Delete key is pressed { mg=mg-1; } if(mg1) { TR0=1; }//Open the timer to unlock in 5 seconds } while(num!=15); if(mg!=16&&num15) { for(i=mg;i<16;i++) { PSWD0_0[i]=0; } } //Compare the administrator password/// //Read_page24c02(0x10,PSWD0_1,16) for(i=0;i<16;i++) //Read 16 passwords from 24c02 { PSWD1_1[i]=i2cRead24LC16B((0x10+i)); delay_10ms; } if(flag1&&num==15) { flag=0; shw=1; num=0; for(i=0;i if(PSWD1_1[i]!=PSWD0_0[i]) { BJCB=1; break; } else BJCB=0; } } if(BJCB!=0) { BJC++; if(BJC!=3) { BJCB=0; //First and second alarms mg=0; //Password number cleared L1=1; for(i=0;i<2;i++)//sound and light alarm circuit { L3=0; display_3(); bjyin(1000); L3=1; delay(1000); } display_1(KSC); goto loop; } else { BJCB=0; display_5(); //Failed to enter the password three times, self-lock mg=0; //Password number cleared delay(10000); display_1(KSC); goto loop; } } else { SJ=0; display_4(); //Administrator unlock display mg=0; L2=0; L1=1; L3=0; //Password number cleared do //Keyboard scan waiting for function key to be pressed { flag=0; key(); } while(flag0); //If the password key is pressed if(flag1&&num13) { flag=0; display_2(); do { flag=0; //Keyboard flag key(); if(flag1&&num<=9) { PSWD0_0[mg]=num; mg++; //Number of passwords } if(flag1&&num14&&mg>=1)//delete input error { mg=mg-1; } if(mg16) { do //Keyboard scan waiting for function key to be pressed { flag=0; key(); } while(num!=15); } } while(num!=15); if(mg!=16&&num15) { for(i=mg;i<16;i++) { PSWD0_0[i]=0; } } if(flag1&&num15) { flag=0; mg=0; for(i=0;i<16;i++) //Write one at a time to 24c02 { i2cWrite24LC16B(PSWD0_0[i],(0x10+i)); delay_10ms; } display_4(); do //Keyboard scan waiting for function key to be pressed { flag=0; key(); } while(num!=11); //Press the return key and the lock will return { goto loop; } } } if(flag1&&num10) { KSC=0; i2cWrite24LC16B(KSC,0X20); display_1(KSC); do //Keyboard scan waiting for function key to be pressed { flag=0; key(); } while(num!=11);//Press the return key to return goto loop; } if(flag1&&num11)//Press the return key and the lock will return { goto loop; } } } }
Previous article:Design of a mobile phone Bluetooth remote control car controlled by 51 single chip microcomputer
Next article:Ultrasonic distance measurement based on STC51 single chip microcomputer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Stack reuse in GD32VF103 multi-tasking applications
- [ATmega4809 Curiosity Nano Review] Wifi Controlled Lighting (IoT Led Part 2)
- 10UA current drive
- Practice together in 2021 + review my 2020
- What technology is generally used to convert Bluetooth WiFi to 0-10V in smart dimming?
- Busy like a top at the end of the year
- Battery SBS Glossary
- Using ADP1055 as an example to improve dynamic loop response
- Ended | [Microchip Embedded Security Solutions | Security Resilience of Platform Firmware]
- FAQ: How to choose a suitable automotive MOSFET