EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Need help with Electronic code lock project

Need help with Electronic code lock project

|

Microcontroller › 8051 › Need help with Electronic code lock project

  • This topic has 5 replies, 5 voices, and was last updated 13 years, 7 months ago by luiz oliveira.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • February 5, 2012 at 7:57 am #1683
    rona
    Participant

    Hello, im currently working on a project – a security door lock that opens after u enter the correct 4 digit code and after 3 incorrect tries the alarm will sound.

    (i write in ASM)

     

    so i have one problem , the default password is 1234, and there should be an option to change it (the user can).

    so after u input the correct code im gonna show a question in which u can press A to open door or B to change password.

    the problem is i dont know how to recieve the 4 numbers from the keyboard into the memoryregister.

    and after that how do i compare the this new saved password to what i type in keyboard next time i want to open door?

     

    now i use this 

     

    codecheck:
    press1:
    mov r0,pcount;4
    cjne r0,#4, press2
    dec pcount
    cjne a,#1, mistake
    jmp sof
    press2:
    mov r0,pcount;3
    cjne r0,#3, press3
    dec pcount
    cjne a,#2, mistake
    jmp sof
    press3:
    mov r0,pcount;2
    cjne r0,#2, press4
    dec pcount;1
    cjne a,#3, mistake
    jmp sof
    press4:
    dec pcount;0
    cjne a,#4, mistake
    jnb 22h, success
    jmp sof

     

     

    but this works only if the code 1234 because i always compare the numbers i press from keyboard to 1,2,3,4. so how do i compare them to the register or place where i saved the new password.

    February 10, 2012 at 1:06 pm #7139
    Syed Aameer
    Participant

    Not good in Assemble..Sorry Pal

    February 16, 2012 at 4:57 am #7178
    Dexter
    Participant

    this may be useful

    c coding is the batter

    my working code

     

    #include <reg51.H>          //……………….headder file
    #include <stdio.h>          //……………….headder file
    #include <string.h>     //……………….headder file

    /*………………PIN CONNECTIONS…………………………………………………………….*/

    #define LCD_PORT P2        //……………….lcd data port to be connected
    #define    port0 P0        //……………….Port for keypad connection
    #define REL_PORT P1        //……………….relay connection port
    sbit    LED2=P3^3;        //……………….LCD PIN Connection
    sbit    EN=P3^7;        //……………….enable pin for LCD
    sbit    RW=P3^6;        //……………….write pin for LCD         
    sbit    RS=P3^5;        //……………….register select pin of LCD

    /*………………..Declarations ……………………………………………*/

    //………………..DELAYS………………………//

    void Delay_in_ms(unsigned char);    //……………..milli second delay is to be specifide
    void Delay_in_10ms(unsigned char);    //……………..10 * number of milli sec
    void Delay_in_1s(unsigned char);    //……………..number of sec

    //………………….LCD………………………//

    void lcd_init        (void);                    //………routine to initialise LCD
    void write_in        (unsigned char );        //………writes data in to LCD as instruction
    void write            (unsigned char );        //………writes one byte into LCD
    void printLcd        (unsigned char *);        //………prints a line on LCD
    void printLcd2        (unsigned char *);        //………prints a line on LCD
    void clear_display    (void);                    //………clears LCD screen
    void set_add        (unsigned char );        //………sets the display position
    void write_data        (unsigned char );        //………writes one byte into LCD as data

    //………………..relay………………………//

    void RELAY_GO(unsigned char ,unsigned char );    //…..selection of relay through keybord
    void relay_set(unsigned char);                    //…..selected relay ON or OFF            
    #define RON  1         //……………………………relay pin on state
    #define ROFF 0         //……………………………relay pin off state
    sbit RELAY1 = P1^0;    //……………………………relay one
    sbit RELAY2 = P1^1;    //……………………………relay two
    sbit RELAY3 = P1^2;    //……………………………relay three
    sbit RELAY4 = P1^3;    //……………………………relay four
    sbit RELAY5 = P1^4;    //……………………………relay five
    sbit RELAY6 = P1^5;    //……………………………relay six
    sbit RELAY7 = P1^6;    //……………………………relay seven
    sbit RELAY8 = P1^7;    //……………………………relay eight

    /* ………………password functions…………………*/

    char  key0 = ‘*’;            //……………………..MASK key press
    unsigned char key1;            //……………………..1 key press
    unsigned char key2;            //……………………..2 key press
    unsigned char key3;            //……………………..3 key press
    unsigned char key4;            //……………………..4 key press
    unsigned char key5;            //……………………..5 key press
    unsigned char key6;            //……………………..6 key press

    void relese_go(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
    void lock_go(unsigned char , unsigned char , unsigned char , unsigned char , unsigned char , unsigned char );

    /*…………………….4X4 keybord……………………*/

    // key select functions

    void select(void);                //……………………..selection of relay
    void locker();                    //……………………..lockre rootine
    void menu_1(void);                //……………………..function choose
    void menu_2(void);                //……………………..function choose
    void stop(void);                //……………………..system halt
    void sleep(void);                //……………………..system standby
    unsigned char keyS;                //……………………..selected key
    unsigned char keypad(void);        //……………………..key input
    void call_for_column(void);        //……………………..key routien work
    unsigned char getport0,col,row;    //…………………..key routien work
    unsigned char keypad_value;        //……………………..value of key
    unsigned char key[4][4] = { ‘1’,’2′,’3′,’R’,
                                ‘4’,’5′,’6′,’P’,
                                ‘7’,’8′,’9′,’L’,
                                ‘*’,’0′,’#’,’S’};

    //………………progam starts………………………………….//
    void main()
    {
        REL_PORT=0x00;                        //………initialising relay port
        lcd_init();                            //………initialising lcd port
        lock= ROFF;    
        clear_display();                    //………clear th display
            printLcd(”  Dexter8051  “);        //……..FOR PRINTING IN FIRST LINE
            printLcd2(” WELCOMES YOU    “);    //……..FOR PRINTING IN SECAND LINe
            Delay_in_1s(2);*/

            locker();
        }    
    }

    //……………..menu 1 select………………//

    void menu_1(void )
        {
        clear_display();
        printLcd (“RELAY :press R “);
        keyS= keypad();
        if(keyS==’R’)
                    {
                    select();
                    }
        else
            {
            clear_display();
            printLcd(“WRONG INPUT”);
            Delay_in_1s(1);
            menu_1();
            }
        }

    //…………on off select function………….//

    void select(void)
    {
        clear_display();
        printLcd(“Enter relay no:”);
        key1=keypad();
        write_data(key1);
        Delay_in_10ms(2);
        set_add(0xc0);
        printLcd(“PRESS # ON * OFF”);
        Delay_in_1s(1);
        key2=keypad();
        Delay_in_10ms(2);
        clear_display();
        RELAY_GO(key1,key2);
        Delay_in_1s(1);
        menu_1();
    }

    //…………………..relay to be on off select rooine…………//

    void RELAY_GO(unsigned char a,unsigned char b)
    {
        {
        if(a==’1’& b==’#’)
                    {
                    relay_set(1);// RELAY 1 on //calling relay_set function
                    }
    else if(a==’1’& b==’*’)
                    {
                    relay_set(2);// RELAY 1 off //calling relay_set function
                    }
    else if(a==’2’& b==’#’)
                    {
                    relay_set(3);// RELAY 2 on //calling relay_set function
                    }
    else if(a==’2’& b==’*’)
                    {
                    relay_set(4);// RELAY 2 off //calling relay_set function
                    }
    else if(a==’3’& b==’#’)
                    {
                    relay_set(5);// RELAY 3 on //calling relay_set function
                    }
    else if(a==’3’& b==’*’)
                    {
                    relay_set(6);// RELAY 3 off //calling relay_set function
                    }
    else if(a==’4’& b==’#’)
                    {
                    relay_set(7);// RELAY 4 on //calling relay_set function
                    }
    else if(a==’4’& b==’*’)
                    {
                    relay_set(8);// RELAY 4 off //calling relay_set function
                    }
    else if(a==’5’& b==’#’)
                    {
                    relay_set(9);// RELAY 5 on //calling relay_set function
                    }
    else if(a==’5’&b==’*’)
                    {
                    relay_set(10);// RELAY 5 off //calling relay_set function
                    }
    else if(a==’6’&b==’#’)
                    {
                    relay_set(11);// RELAY 6 on //calling relay_set function
                    }
    else if(a==’6’& b==’*’)
                    {
                    relay_set(12);// RELAY 6 off //calling relay_set function
                    }
    else if(a==’7’& b==’#’)
                    {
                    relay_set(13);// RELAY 7 on //calling relay_set function
                    }
    else if(a==’7’& b==’*’)
                    {
                    relay_set(14);// RELAY 7 off //calling relay_set function
                    }
    else if(a==’8’& b==’#’)
                    {
                    relay_set(15);// RELAY 8 on //calling relay_set function
                    }
    else if(a==’8′ & b==’*’)
                    {
                    relay_set(16);// RELAY 8 off //calling relay_set function
                    }
        else
                {
                  clear_display();
                printLcd(“WRONG INPUT KEY”);
                }
            }
    }

    //…………………LCD Routines…………………..//

    //routine to initialise the lcd
    void lcd_init(void)
    {        
        write_in(0x38);          //to make lcd
        Delay_in_ms(1);
        write_in(0x0f);          //to make lcd to select 5×7 matrix display
        Delay_in_ms(1);
         write_in(0x01);          //to make lcd to clear the display
        Delay_in_ms(1);
        write_in(0x80);          //to make lcd cursor to bigining of first line
        Delay_in_ms(1);
    }
    //routine to write an instruction to LCD
    void write_in(unsigned char ch)
    {
        RS=0;                //rs =0 for instr
        RW=0;            
        write(ch);            //routine to transfer 8 bits to LCD
    }
    //routine to transfer 8 bits to LCD module
    void write(unsigned char ch)
    {
        LCD_PORT = ch;        //preserves the old value of port
        EN = 1;                //enable pin high
        Delay_in_ms(1);
        EN = 0;                //enable = 0
    }
    //clears the entire display area of LCD
    void clear_display(void)
    {
        write_in(0x01);            //clears the lcd display
        write_in(0x80);            //write code to blink at first line first coloum
    }
    //printing rootin
    //routine to display the value in the accumulator in LCD
    //routine to display a string on first line
    //this routine will display a string stored at address pointed by dptr
    void printLcd(unsigned char *str)
    {
        unsigned char len,i;
        len = strlen(str);
        set_add(0x80);                //sets display position in first line
        for(i=0;i<len;i++)
        {
        write_data(*str);        //displays the character on LCD
        str++;
        }
    }
    void printLcd2(unsigned char *str)
    {
        unsigned char len,i;
        len = strlen(str);
        set_add(0xc0);        //sets display position in second  line
        
        for(i=0;i<len;i++)
            {
                write_data(*str);    //displays the character on LCD
                str++;
            }
    }
    //routine to set the display position
    void set_add(unsigned char ch)
    {
        write_in(ch);        //writes it as instruction
    }
    //routine to write a data to LCD
    void write_data(unsigned char ch)
    {
        RS = 1;
        RW=0;            
        write(ch);            //……….transfers 8 bits to lcd module    
    }
    //ms delay in milli secand
    void Delay_in_1s(unsigned char ms)//……………..number of secands
    {
        int t;
        t=ms;
        {
        unsigned int i;
        for(i=0;i<t;i++)
        {
        Delay_in_10ms(10);
        }
        }
    }    
    void Delay_in_10ms(unsigned char ms)//……………..milli sec * 10
    {
        int t;
        t=ms;
        {
        unsigned int i;
        for(i=0;i<t;i++)
        {
        Delay_in_ms(100);
        }
        }
    }    
    void Delay_in_ms(unsigned char ms)//……………….milli sec
    {
        int t;
        t= ms;
        {
        unsigned int i,j;
        for(i=0;i<t;i++)
        for(j=0;j<120;j++);
        }
    }
    //…………..key board processes……………..//

    unsigned char keypad()
    {
        do
        {
            do
            {
            port0 = 0x0f;
            getport0 = port0;
            getport0 = getport0 & 0x0f;
            }while(getport0 != 0x0f);
        
        getport0 = port0;
        getport0 = getport0 & 0x0f;
        }while(getport0 !=0x0f);
        
        while(1)
        {
                port0 = 0xef;
                getport0 = port0;
                getport0 = getport0 & 0x0f;
                if(getport0 != 0x0f)
                {
                    row = 0;
                    call_for_column();

                    break;
                }
                port0 = 0xdf;
                getport0 = port0;
                getport0 = getport0 & 0x0f;
                if(getport0 != 0x0f)
                {
                    row = 1;
                    call_for_column();
                    break;
                }
               
                port0 = 0xbf;
                getport0 = port0;
                getport0 = getport0 & 0x0f;
                if(getport0 != 0x0f)
                {
                    row = 2;
                    call_for_column();
                    break;
                }
               
                port0 = 0x7f;
                getport0 = port0;
                getport0 = getport0 & 0x0f;
                if(getport0 != 0x0f)
                {
                    row = 3;
                    call_for_column();
                    break;
                }
        }
    keypad_value = key[row][col];
    return keypad_value;
    }
    void call_for_column()
    {
        while(1)
        {
            if(getport0 == 0x07)
            {
                col = 0;
               
                Delay_in_10ms(3);
               
                break;
            }
            else if(getport0 == 0x0b)
            {
                col = 1;
               
                Delay_in_10ms(3);
               
                break;
            }
            else if(getport0 == 0x0d)
            {
                col = 2;
               
                Delay_in_10ms(3);
               
                break;
            }
            else if(getport0 == 0x0e)
            {
                col = 3;
               
                Delay_in_10ms(3);
               
                break;
            }
        }
    }

    //……….relay switching processes……………..//

    void relay_set(unsigned char relay)
    {
        int x;
        x= relay;
         switch (x)
        {
        case 1:            //………………..RELAY 1 OFF
       RELAY1= RON;
           printLcd(“RELAY 1 ON “);
        break;
        case 2:            //………………..RELAY 1 0N
       RELAY1= ROFF;
        printLcd(“RELAY 1 OFF”);
        break;
        case 3:            //………………..RELAY 2 OFF
       RELAY2= RON;
       printLcd(“RELAY 2 ON “);
        break;
        case 4:            //………………..RELAY 2 0N
       RELAY2= ROFF;
       printLcd(“RELAY 2 OFF”);
        break;
        case 5:            //…………………RELAY 3 OFF
       RELAY3= RON;
       printLcd(“RELAY 3 ON “);
        break;
        case 6:            //………………..RELAY 3 0N
       RELAY3= ROFF;
       printLcd(“RELAY 3 OFF”);
        break;
        case 7:            //………………..RELAY 4 OFF
       RELAY4= RON;
       printLcd(“RELAY 4 ON “);
        break;
        case 8:            //………………..RELAY 4 0N
       RELAY4= ROFF;
       printLcd(“RELAY 4 OFF”);
        break;
        case 9:            //………………..RELAY 5 OFF
       RELAY5= RON;
       printLcd(“RELAY 5 ON “);
        break;
        case 10:            //……………….RELAY 5 0N
       RELAY5= ROFF;
       printLcd(“RELAY 5 OFF”);
        break;
        case 11:            //……………….RELAY 6 OFF
       RELAY6= RON;
       printLcd(“RELAY 6 ON “);
        break;
        case 12:            //………………..RELAY 6 0N
       RELAY6= ROFF;
       printLcd(“RELAY 6 OFF”);
        break;
        case 13:            //………………..RELAY 7 OFF
       RELAY7= RON;
       printLcd(“RELAY 7 ON “);
        break;
        case 14:            //………………..RELAY 7 0N
       RELAY7= ROFF;
       printLcd(“RELAY 7 OFF”);
        break;
        case 15:            //………………..RELAY 8 0FF
       RELAY8= RON;
       printLcd(“RELAY 8 ON “);
        break;
        case 16:            //………………..RELAY 8 0N
       RELAY8= ROFF;
       printLcd(“RELAY 8 OFF”);
        break;
        }
    }

    //…………..locker password code…………….//

    void locker(void)
    {    
        clear_display();
        printLcd(“ENTER PASSWORD”);
        set_add(0xc0);
        key1=keypad();
        write_data(key0);
        key2=keypad();
        write_data(key0);
        key3=keypad();
        write_data(key0);
        key4=keypad();
        write_data(key0);
        key5=keypad();
        write_data(key0);
        key6=keypad();
        write_data(key0);
        lock_go(key1,key2,key3,key4,key5,key6);
    }
    //……………………..lock code ………………………//

    void lock_go(unsigned char a, unsigned char b, unsigned char c, unsigned char d, unsigned char e, unsigned char f)
    {
        if(a==’1′ & b==’2′ & c==’3′ & d==’4′ & e==’5′ & f==’6′)
                {
                clear_display();
                printLcd(“CORRECT PASSWORD”);
                printLcd2(“LOCK IS OPEN”);
                Delay_in_1s(1);
                menu_1();
                }
        else
            {

            locker();
            }
    }

    February 21, 2012 at 9:03 am #7188
    Pravin
    Participant

       hi frd

      i want to do this project

     so plz send me component list , ckt dig., on [email protected]

     

    February 21, 2012 at 5:46 pm #7192
    Dexter
    Participant

    wysiwyg_imageupload:3780:

    April 1, 2012 at 12:14 am #7374
    luiz oliveira
    Participant

    All Friends,

     

     

    Could you please help me to develop a code in C for a microcontroler:  It should have a keypad ( 3x 4) and a 2×16 lcd display

    The keypad has the numbers 0 to 9 , clear and enter. ( just like the one from telephone , star will be clear and the other enter…)

    I have 8 codes of 6 numbers that I will type in the keypad and I should be able to see the numbers in the display. If I do a mistake in the code I can press clear to start over. If I pressed the full 6 digits of a right code I press enter and the micro will comparte that number with a 8 codes of six numbers stored in the micro memory.

    Each specific code of six digists will activate one pin output of the micro to activate a relay. So, it has 8 relays in the output and 8 different codes of 6 digits specific to activate each relay.

     

     

    .

    exemple:

    1 code:  123456 –  turn on relay 1 only

    2 code:  234521 – turn on relay 2 only

    3 code:  897643-  turn on relay 3 only…

    4…code…

    5….code….

    .6….   code…

    .7…

    8…                      …….turn on relay 8 only.

     

     

     

    This is for school project, and I just have two weeks to deliver it.

    I will help you with anything else. 

     

    Thank you.

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque November 10, 2025
  • Anyone In The US Ordered From AliExpress Recently? November 10, 2025
  • Calculation of A Class amplifier November 10, 2025
  • strange laptop problem November 10, 2025
  • restarting this Christmas project November 10, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise