Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing Seven Segment Display.

Status
Not open for further replies.

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
640
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,298
Activity points
6,922
Hi all..
I am trying to interface keypad and Seven Segment display with 89S52.
what i need to do is whatever keys are pressed from keypad, it should show on seven segment display. for Eg. if 2 is pressed from keypad then display should show 2. and so on.
my code is...
Code:
#include<reg51.h>
#include<stdio.h>

sbit row0=P2^7; //assigning PORT-0 to read rows
sbit row1=P2^6; //assigning PORT-0 to read rows
sbit row2=P2^5; //assigning PORT-0 to read rows
sbit row3=P2^4; //assigning PORT-0 to read rows
sfr COL=0xA0;   //assigning PORT-2 to read colomns

sbit buz=P3^2;

sbit seg0=P3^0;
sbit seg1=P3^1;
sbit seg2=P3^2;
sbit seg3=P3^3;
sbit seg4=P3^4;
sbit seg5=P3^5;

void msdelay(unsigned int value);
int keypad();

char digi[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};

unsigned char numbers[6]={"44444"};

void main()
{
unsigned int i;
while(1)
  {
   do
   {
    numbers[i]=keypad();
    i++;
   }
   while(i!=6);
   i=0;
    {
     P1=0x40;
    }
   }

}                       // MAIN ENDS HERE.



void msdelay(unsigned int value)
{
 unsigned int i,j;
 for(i=0;i<value;i++)
 for(j=0;j<100;j++);
}

int keypad()
{
        unsigned char dat[4][4]={'7','8','9','A',        // assigning key matrix
                                 '4','5','6','B',
                                 '1','2','3','-',
                                 '*','0','#','+',};

 unsigned char colloc,rowloc;
 COL=0x0F;
 row0=0;
 row1=0;
 row2=0;
 row3=0;
 while(1)
 {
  do
   {
    do
     {
      msdelay(90);
      colloc=COL;
      colloc&=0x0F;
     }
   while(colloc==0x0F);
   msdelay(90);
   colloc=COL;
   colloc&=0x0F;
   }
  while(colloc==0x0F);
  while(1)
  {
        row0=0;
        row1=1;
        row2=1;
        row3=1;
        msdelay(5);
        colloc=COL;
        colloc&=0x0F;
        if(colloc!=0x0F)
        {
         rowloc=0;
         break;
        }
         row0=1;
         row1=0;
         row2=1;
         row3=1;
         msdelay(5);
         colloc=COL;
         colloc&=0x0F;
         if(colloc!=0x0F)
         {
          rowloc=1;
          break;
         }
         row0=1;
         row1=1;
         row2=0;
         row3=1;
         msdelay(5);
         colloc=COL;
         colloc&=0x0F;
         if(colloc!=0x0F)
          {
           rowloc=2;
           break;
          }
        row0=1;
        row1=1;
        row2=1;
        row3=0;
        msdelay(5);
        colloc=COL;
        colloc&=0x0F;
        if(colloc!=0x0F)
        {
         rowloc=3;
         break;
        }
  }
if(colloc==0x0E)
  return(dat[rowloc][0]);
else if(colloc==0x0D)
  return(dat[rowloc][1]);
else if(colloc==0x0B)
  return(dat[rowloc][2]);
else
  return(dat[rowloc][3]);
}
}
i have not tried anything because i am not getting any idea of how to start with...
because the output from keypad i get is numbers. and to display on seven segment we need hex.
how can i do this.
in my code, in MAIN function i have just tried to save the numbers from what i get from keypad to array numbers[7].
seven segment display are common anode and are connected to port 1 of 89S52.
 

how looping in the while(i!=6) solve my problem.
what i want is when i press number 2 from keypad the segment should display 2 on it and when again i press 3 it should show 3 and when 4 is press it should show 4 and so on..
 

What Easyrider83 is pointing out is:
Code:
 while(i!=6);
   i=0;
    {
     P1=0x40;
    }
doesn't make a lot of sense.
"while(i!=6);" without something such as an interrupt changing the value of 'i', just sits in a loop forever.
Should the ';' be there and if you meant "if(i != 6)" the following lines should be enclosed in brackets.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top