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.
code snippet`:
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.