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.

[PIC] Problem keypad and multiplexed seven segment

Status
Not open for further replies.

Rakesh Menon

Newbie level 4
Joined
Sep 1, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
102
hello,
I've been trying to interface 4x4 hex keypad with pic16f877a using MPLAB X and XC8 compiler.

My task is to get 4 individual key presses from matrix keypad and convert it into a 4 digit integer and display the 4 digit integer on multiplexed common cathode seven segment display having 4 seven segment devices.

I am able to capture the key presses, also am able to display a 4 digit integer directly on to seven segment.


but whenever i need to make a 4 digit integer out of 4 different key presses and display the integer on to display, I am getting 4 equal numbers in 4 seven segment modules on a single key press.

This is my code logic:

Code:
    char array[4]; // global

    int l=0,t,x=1000,key_int=0,d; // local to main function
    unsigned char key;

 while(1)
   {
       if(getkey())
       {
       key=0;    
       key=getkey();
       key_int=key-'0';
       array[l]=key_int;
       key_int=0;
       l++;
       if(l>3){l=0;}
       if(l==3)      
       {
           t=((array[0]*1000)+(array[1]*100)+(array[2]*10)+(array[3]*1)); 
           Print_seven_segment(t);
           delay(10);  // delay of 10*20 ms
           for(d=0;d<4;d++){array[d]=0;}  // clear array
       }
       
       
       }
       
   }

the getkey() function returns an unsigned character, The print_seven _segment () function accepts an integer, breaks it down to individual digits and passes each digit to corresponding positions in seven segment .

Can anyone figure out where am I going wrong?
Thanks.
 

Thank you for reply,

kindly see my function implementation:

Code:
unsigned char getkey(void)
{
int i; char c;


 PORTD=0X00;

   for(i=16;i<130;i*=2)  // for loop for row scanning
{
    PORTD= i;
    delay(3);
    c=PORTC;
	delay(3);

if(i==16){    // activating 1st row
switch(c){

case 0X10:         // checking  1st row 1st col
return  '1';
break;

case 0X20:       // checking  1st row 2nd col
return '2';
break;

case 0X40:
return '3';
break;

case 0X80:
return '4';
break;

}   
}
else if(i==32){       // activating 2nd row
switch(c){

case 0X10:
return  '4';
break;

case 0X20:
return '5';
break;

case 0X40:
return '6';
break;

case 0X80:
return '7';
break;

}   
}
else if(i==64){    // activating 3rd row
switch(c){

case 0X10:
return  '8';
break;

case 0X20:
return '9';
break;

case 0X40:
return 'x';
break;

case 0X80:
return 'a';
break;

}   
}
else if(i==128){    // activating 4th row
switch(c){

case 0X10:
return  'b';
break;

case 0X20:
return 'c';
break;

case 0X40:
return 'd';
break;

case 0X80:
return 'e';
break;

}   
 
       
    }

}



return 0;

}

When no key is being pressed, The value returned would be zero.

Your explanation is about waiting for "key- release" ?


Thank you
 

If you press any key... your getkey() function store a value for return. Until you press next key, Infinite loop have finished his work hundred of times.

You are not clearing previous value in getkey() function for next character.

- - - Updated - - -

If i wrote these codes it looks like this :

Code:
    char array[4]; // global

    int l=0,t; // local to main function
    unsigned char key;

 while(1)
   {
       if((key = getkey()) != 'N')      // N mean nothing pressed by user.
       {
       array[l] = key - '0';
       l++;
       if(l > 3) l = 0;
       if( l == 3 )      
       {
           t = ((array[0] * 1000) + ( array[1] * 100) + (array[2] * 10) + (array[3] * 1)); 
           Print_seven_segment(t);
           delay(10);  // delay of 10*20 ms
           for(d=0;d<4;d++) { array[d] = 0; }  // clear array
       }
       
       
       }
       
   }
 
thank you for the reply,

Yes now I understand, let me implement the modification and sse

thank you
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top