51 MCU 12864 display electronic password lock source code

Publisher:SparklingMelodyLatest update time:2020-02-17 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

[1] [2] [3] [4] [5] [6]
Reference address:51 MCU 12864 display electronic password lock source code

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

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号