1. When you want to exit from the flag, you must know which flag the program is currently reading, and then set the exit in it. Otherwise, it cannot be used, which is equivalent to having nothing.
The microcontroller source program is as follows:
/*********************************************************************************************
Password lock, a microcontroller-based lock that can change personal password and administrator password.
Key value code: 1 2 3 set
To enter a password, you can only press 0~9, the 10th digit is the confirmation key, and the 11th digit is the cancel key (to enter a small password,
4 5 6 ↑ to cancel the entered password at 8 o'clock), 12 is the clock function key, 13 is the clock "+",
7 8 9 ↓ 14 is the clock "-", 15 is the confirmation key when changing the password
ok 0 c fun
******************************************************************************************/
/******************************head File****************************************/
#include #include #include #include "lcd.h" #include "ds1302.h" #include "keyboard.h" #include "delay.h" #include "deal.h" #include "i2c.h" #include "uart.h" /*****************************Macro definition****************************************/ #define uchar unsigned char #define uint unsigned int //========================IO port definition==================================// sbit s = P2^2; //control backlight sbit k2 = P3^2; // sbit JDQ_key = P3^7; //Relay control unsigned char flag4,flag5=0,flag8=1,flag1=0,flag_time=0, flag_time2=0;flag3=0; unsigned char wrongtimes=0,k,p=1,miao=59,t=0,snum=0, c=0,up=0,down=0,a=0; //===========================Initial value of the password========================// unsigned char MIMAword[8]={1,2,3,4,5,6,7,8}; //Initial value of password unsigned char G_MIMA[8]={8,8,8,8,8,8,8,8}; //Administrator password, can be changed void MIMA_input(); //EEPROM write void MIMA_output(); //EEPROM read //===========================Configure timer============================// void init_conf() { TH0=(65536-50000)/256; // TL0=(65536-50000)%256; EA=1; ET0=1; IT0=1; // Jump edge trigger mode (falling edge) EX0=1; //Turn on the interrupt enable of INT0. TR1 = 1; ET1 = 1; } //=================================Main function==========================// void main() { unsigned char num,i = 0,j; unsigned char temp[8]; unsigned char Ztemp[8]={'1','2','3','4','5','6','7','8'}; unsigned char Zresponsuccess[4]={0x55,0x11,0x01,0x00}; unsigned char Zresponfail[]="your command is wrong"; unsigned char ch[8]={0},z1=0, Znum[8]={0}; bit Flag; /***********************The following is the data read out of EEPROM after power failure and restart*******************************/ //When powering on for the first time, clear 88888888 to change the administrator password, then unhide and use the changed administrator password to change your personal password G_MIMA[0] = EEPROMread_add(11,19); delay(20); G_MIMA[1] = EEPROMread_add(12,20); delay(20); G_MIMA[2] = EEPROMread_add(13,21); delay(20); G_MIMA[3] = EEPROMread_add(14,22); delay(20); G_MIMA[4] = EEPROMread_add(15,23); delay(20); G_MIMA[5] = EEPROMread_add(16,24); delay(20); G_MIMA[6] = EEPROMread_add(17,25); delay(20); G_MIMA[7] = EEPROMread_add(18,26); delay(20); /***********************The above is the data read out of EEPROM after power off and restart*************************************/ s=0; //Backlight control, low level turns on the transistor when powered on JDQ_key=1; //Relay drive device, low level (transistor is not conducting, relay works, lock is closed //Change the level after changing to J3Y init_conf(); //Configure timer LCD12864_Init(); //12864 initialization Ds1302Init(); //1302 initialization UartInit(); //Serial port initialization LCD12864_SetWindow(0,2,"Welcome"); //The first line displays information LCD12864_SetWindow(1,1,"North China Institute of Science and Technology"); //The second line displays information LCD12864_SetWindow(2,1,"MCU Laboratory"); //The third line displays information LCD12864_SetWindow(3,1,"Enter the eight-digit password"); //The fourth line displays information Delay3000ms(); LCD12864_SetWindow(0,0," "); LCD12864_SetWindow(1,0," "); while(1) { //==============================Serial port processing function====================================// while(UART_Re_N(8,ch)) { for(z1=0;z1<8;z1++) { Znum[z1]= ch[z1]; } if((Ztemp[0]==Znum[0])&&(Ztemp[1]==Znum[1])) { UART_Send_Strs(Zresponsuccess); UART_Send_Enter(); JDQ_key=0; //If the transistor is not conducting, the relay will not work and the lock will be unlocked. LCD12864_SetWindow(3,0," "); //After testing, it was found that the correct "正" could not be displayed normally. //Patch is needed to display, the internal code of "正" is missing, //Using GBK national standard extension code, the display is as follows LCD12864_WriteCmd(0x98+2); LCD12864_WriteData(0xc3);//Secret LCD12864_WriteData(0xdc); LCD12864_WriteData(0xc2); //code LCD12864_WriteData(0xeb); LCD12864_WriteData(0xd5);//positive LCD12864_WriteData(0xfd); LCD12864_WriteData(0xc8);//Confirm LCD12864_WriteData(0xb7); Delay5000ms(); //After 5s, turn on the relay to lock the lock LCD12864_SetWindow(2,0," "); LCD12864_SetWindow(3,0," "); // Clear the line LCD12864_SetWindow(2,1,"MCU Laboratory"); //Write the third line of information LCD12864_SetWindow(3,1,"Enter the eight-digit password"); JDQ_key=1; //The transistor is turned on, the relay works, and the lock is closed } else { UART_Send_Strs(Zresponfail); UART_Send_Enter(); } } if(flag3 == 1) { MIMA_input(); //Change password } else { if(flag_time2==0) { p=1; LCD12864_WriteCmd(0x0c); LCD12864_SetWindow(2,1,"MCU Laboratory"); //The third line displays information Ds1302Write(0x90,0xa9); //Trickle charge Ds1302ReadTime(); //Time reading LcdDisplaytime(); //Display time delay(5); week(); //Display the day of the week delay(5); displayday(); //Display date delay(5); while(UART_Re_N(8,ch)) //Serial port processing { for(z1=0;z1<8;z1++) { Znum[z1]= ch[z1]; } if((Ztemp[0]==Znum[0])&&(Ztemp[1]==Znum[1])) { UART_Send_Strs(Zresponsuccess); UART_Send_Enter(); JDQ_key=0; //If the transistor is not conducting, the relay will not work and the lock will be unlocked.
Previous article:Design of 51 single chip microcomputer intelligent clock
Next article:Application of CH375_CH376 USB disk read and write module on 51 single chip microcomputer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Popular must-read! Can't these 20 amplifier Q&A selections help you solve your problems?
- Fudan Micro FM1935 self-polling door lock development information
- dsp28335 SCI Summary
- systick_config() function debugging problem
- How to assign a separate segment to the bss of a C file in the link file?
- Voltage to Frequency Converter
- ON
- Why are PCBs mostly green?
- [GD32L233C-START Review] 5. UART+DMA receives variable length data
- 【TI Course】What is the resolution within 5 meters?