keypad based seven segment display

the article is build around seven segment and keypad. the circuit takes input from keypad and display variable number on the screen. controller AT89s51 used so in the project working at 12MHZ frequency. Whenever an input is pressed the corresponding digit is displayed on the seven segment.

Proteus design

connection is similar as we learn in earlier article.port P1 is connected with keypad and seven segment(common cathode) connected with port P2  

CODE

function  keycheck(); continuously check whether the key has been pressed or not. whenever key goes high digit corresponding to that key will be displayed

function keyaction(); not only avoid echo of displaying single digit all over the screen but also shift the value by one to the left place whenever user provide new input to system. finally the display(); function call for digit to be displayed on screen.

        

complete code

#include<REG51.H>
#define segment P2
sbit row3=P1^1;
sbit row2=P1^2;
sbit row1=P1^3;
sbit row0=P1^4;
sbit col0=P1^5;
sbit col1=P1^6;
sbit col2=P1^7;
sbit unitpin=P3^3;
sbit tenspin=P3^2;
sbit hundpin=P3^1;
sbit thsndpin=P3^0;
char flag=0;
unsigned char unit,tens,hund,thsnd;
unsigned char arr[]={0X3f,0x06,0X5b,0X4f,0X66,0X6d,0X7d,0X07,0X7F,0X6f};
unsigned char key;
void delay();
void keycheck();
void keyaction();
void display();

void main()
{
 unit=tens=hund=thsnd=0XFF;
 while(1)
 {
  keycheck();
  keyaction();
  display();
 }
}
void keycheck()
{
 key=0XFF;
 col0=0;
 col1=1;
 col2=1;
 if (row0==0)
 {
 key=1;
 }
else if(row1==0)
{
key=4;
}
else if (row2==0)
{
key=7;
}
col0=1;
col1=0;
col2=1;
if (row0==0)
{
key=2;
}
else if (row1==0)
{
key=5;
}
else if (row2==0)
{
key=8;
}
else if (row3==0)
{
key=0;
}
col0=1;
col1=1;
col2=0;
if (row0==0)
{
key=3;
}
else if (row1==0)
{
key=6;
}
else if (row2==0)
{
key=9;
}

void keyaction()
{
if (key==0xFF)
 {
 flag=0;
 }
 else if (flag==0)
  {
    thsnd=hund;
    hund=tens;
    tens=unit;
    unit=arr[key];
    flag=1;
   }
}
void display()
   {
   segment=unit;
  unitpin=0;
  delay();
  unitpin=1;
  segment=tens;
  tenspin=0;
  delay();
  tenspin=1;
  segment=hund;
  hundpin=0;
  delay();
  hundpin=1;
  segment=thsnd;
  thsndpin=0;
  delay();
  thsndpin=1;
  }
void delay()
  {       
   unsigned int i;
   for(i=0;i<500;i++)
   {
   }
  }

VIDEO

Category: 

Share

Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified

 

Share

We are Social

Syndicate

Subscribe to Syndicate