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 / How to interface keypad with 8051 microcontroller (AT89C51)

How to interface keypad with 8051 microcontroller (AT89C51)

|

Projects › Projects › How to interface keypad with 8051 microcontroller (AT89C51)

  • This topic has 3 replies, 2 voices, and was last updated 14 years, 4 months ago by Qaisar.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • August 5, 2011 at 6:09 pm #1246
    nikhil
    Participant

    In the project-how to interface keypad with 8051(AT89C51) there is a code given for displaying 1-9,0,# & *…………..so if i want to display more nos. lyk 1- 99 wat modifications i hav to do in the code?……………..also i need help  to interface seven segment display and keypad with AT89C51 to display 1-99 nos…….i need it..

    August 12, 2011 at 10:21 am #6602
    Qaisar
    Participant

     

    interfacing 2 dig seven segment display with 89C51

     

    Compiler:  Keil

    Simulator: Proteus

     

    C Code:

     

     

    #include <AT89X51.H>

    unsigned char unit1 = 0;
    unsigned char tens1 = 0;

    char e = 0;

    unsigned char font[10] = 0;

    void delay(void)
    {
     int i = 0;

     for(i = 0; i < 300; i++)
     {
     
     }
    }

    void mux(void)
    {
    int i = 0;

     for(i = 0; i < 100; i++)
     {

     P2 = unit1;
     P1_0 = 0;
     delay();
     P1_0 = 1;

     P2 = tens1;
     P1_1 = 0;
     delay();
     P1_1 = 1;

     

    }
    }

    void decode(void)
    {
     unit1 = e % 10;
     tens1 = (e % 100) / 10;

     unit1 = font[unit1];
     tens1 = font[tens1];

    }

     

    void main(void)
    {

    // 7 seg (CC) equivalent codes
    font[0] = 0x3f;
    font[1] = 0x06;
    font[2] = 0x5b;
    font[3] = 0x4f;
    font[4] = 0x66;
    font[5] = 0x6d;
    font[6] = 0x7d;
    font[7] = 0x07;
    font[8] = 0x7f;
    font[9] = 0x6f;

     while(1)
     {

      e++;
      if(e == 100)
      {
      e = 0; 
      }
      decode(); 
      mux();

      
     }
    }

    August 12, 2011 at 10:28 am #6603
    Qaisar
    Participant

    wysiwyg_imageupload:2500:

    August 12, 2011 at 10:48 am #6604
    Qaisar
    Participant

     

     

    interfacing keypad and seven segment with 89C51

     

    C Code:

    //////////////////////////////////////////////////////////////////////////

     

    #include <AT89X51.H>
    #include <my.h>   //delay built in function

    #define led P1_0

    char unit, tens,e = 0;

    char scan (void);

     

    #define row1 P3_0
    #define row2 P3_1
    #define row3 P3_2
    #define row4 P3_3

     

    #define col1 P3_4
    #define col2 P3_5
    #define col3 P3_6
    #define col4 P3_7 

     

    unsigned char ch = 0;
    unsigned int ar[1] = 0;
    unsigned int font[10];
    unsigned char counter = 0;

     

    void decode(void)
    {
     unit = e % 10;
     tens = (e % 100) / 10;

     unit = font[unit];
     tens = font[tens];
     

    }
     void display(void)
    {
     int i = 0;

     for(i = 0; i < 100; i++)
     {

     P0 = unit;
     P2_1 = 0;
     delay(1);
     P2_1 = 1;

     P0 = tens;
     P2_0 = 0;
     delay(1);
     P2_0 = 1;

     

    }}

     

    void main (void)
    {               // 7 seg equivalent code

        font[0] = 0x3f;
        font[1] = 0x06;
        font[2] = 0x5b;
        font[3] = 0x4f;
        font[4] = 0x66;
        font[5] = 0x6d;
        font[6] = 0x7d;
        font[7] = 0x07;
        font[8] = 0x7f;
        font[9] = 0x6f;

    while(1)
    {
    decode();
    display();

     ch = scan();
     
     if(ch != 100)
     {
      if(ch == 13)  // % symbol in keypad causes reset
      {
       e = 0;
       counter= 0;
       
      }
      if(ch < 10)
      {
       e = ch;
       
       if(counter < 2)
       {
        ar[counter] = ch;
        counter++;

        if(counter == 2)
        {
         e = ar[0] * 10;
         e = e + ar[1];

         decode();
         display();
         counter = 0;
    }}

    }}}  }
     

     

     

    char scan (void)

    {
    row1 = 0;
    row2 = 1;
    row3 = 1;
    row4 = 1;

    col1 = 1;
    col2 = 1;
    col2 = 1;
    col4 = 1;

     
    if (col1 == 0)
    {
    led = 1;
    delay(100);
    led = 0;
    return 1;
    }

    if (col2 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 2;
    }

    if (col3 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 3;
    }

    if (col4 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 13;
    }

     

    row1 = 1;
    row2 = 0;

    if (col1 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 4;
    }

    if (col2 == 0)
    {
    led = 1;
    delay(100);
    led= 0;

    return 5;
    }

    if (col3 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 6;
    }

    if (col4 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 14;
    }

     

    row2 = 1;
    row3 =0;

    if (col1 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 7;
    }

    if (col2 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 8;
    }

    if (col3 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 9;
    }

    if (col4 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 15;
    }

     

    row3 = 1;
    row4 = 0;

    if (col1 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 11;
    }

    if (col2 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 0;
    }

    if (col3 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 12;
    }

    if (col4 == 0)
    {
    led = 1;
    delay(100);
    led = 0;

    return 16;
    }

    row4 = 1;

    return 100;
    }

     

    wysiwyg_imageupload:2503:

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

RSS Recent Posts

  • mechanism to shutdown feeding when sensor temperature rises December 9, 2025
  • Want Thermal Camera with Fixed Thermal Span option December 8, 2025
  • Bad design , bad maintenance or just how it was. December 8, 2025
  • Looking for single photovoltaic cells for light gate December 8, 2025
  • Sanity Check – Peltier "Cooler" for Heating and Cooling December 8, 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