I'm trying to display two digits on the 7 segment LED display for the project I'm doing. So far I can only display one digit and when I press the second button the first number completely erases and display the 2nd digit. Here is the code I wrote so far. The function "ScanKeyPad()" outputs 0-15 which corresponds to the keypad number. So basically when I click 4 and 8 it should display 48. Below is the C program.
Code:
while(1)
{
key = ScanKeyPad();
if(key != 16) // If a key is pressed
{
hold_var = key ; // holds (remember) the value of the key
// this sequence shows the value of the key that is pressed, in 2 digits
for (i=0;i<20;i++){
PTP = 0x0f;
PTB = SegPat[hold_var/10];
PTP &= ~0x04;
delayby1ms(10);
PTP = 0x0f;
PTB = SegPat[hold_var%10];
PTP &= ~0x08;
delayby1ms(10);
}
}
// If a new key is not pressed (DEFAULT)
if(key = 16)// this sequence keeps showing the same number if a new key is not pressed
{
PTP = 0x0f;
PTB = SegPat[hold_var/10];
PTP &= ~0x04;
delayby1ms(10);
PTP = 0x0f;
PTB = SegPat[hold_var%10];
PTP &= ~0x08;
delayby1ms(10);
}
}