Hi all,
I am currently working on a PIC programming project. I am new to embedded programming, so please bear with me if I come across as an idiot. My project is to program a user interface for a power supply unit, this includes a 3x4 matrix keypad and multiplexed 7segment LEDs. My code includes a function that scans the keypad and verifies the key pressed using polling, and an array with the decoded values to drive the 7 segment displays. My code works fine and displays the correct key pressed on one digit but I can't seem to get how to store the keypresses and display them on the multiplexed displays and shift the displayed numbers to the left as the user enters the 2nd and 3rd...digit numbers
Below is the function that finds the key pressed and sends value to PORTC where the 7segment displays are connected
below is the part of the code I thought would display numbers on the 2 multiplexed 7segment displays but it doesn't work
Can you please give me some suggestions as to how I can improve this, thanks a lot in advance.
I am currently working on a PIC programming project. I am new to embedded programming, so please bear with me if I come across as an idiot. My project is to program a user interface for a power supply unit, this includes a 3x4 matrix keypad and multiplexed 7segment LEDs. My code includes a function that scans the keypad and verifies the key pressed using polling, and an array with the decoded values to drive the 7 segment displays. My code works fine and displays the correct key pressed on one digit but I can't seem to get how to store the keypresses and display them on the multiplexed displays and shift the displayed numbers to the left as the user enters the 2nd and 3rd...digit numbers
Below is the function that finds the key pressed and sends value to PORTC where the 7segment displays are connected
Rich (BB code):
unsigned char find_key(void)
{
while (1)
{
PORTB &= 0x00;
PORTBbits.RB5 = 1; //set row 1 high
wait_1ms ();
if (PORTBbits.RB1)
{
wait_5ms();
if (PORTBbits.RB1)
key = pat7seg[7]; //send '7' to portc to drive sevenseg display
}
if (PORTBbits.RB2)
{
wait_5ms();
if (PORTBbits.RB2)
key = pat7seg[8]; //send '8'
}
if (PORTBbits.RB3)
{
wait_5ms();
if (PORTBbits.RB3)
key = pat7seg[9]; //send '9'
}
PORTB &= 0x00;
PORTBbits.RB4 = 1; //set row 2 high
wait_1ms ();
if (PORTBbits.RB1)
{
wait_5ms();
if (PORTBbits.RB1)
key = pat7seg[4]; //send '4'
}
if (PORTBbits.RB2)
{
wait_5ms();
if (PORTBbits.RB2)
key = pat7seg[5]; //send '5'
}
if (PORTBbits.RB3)
{
wait_5ms();
if (PORTBbits.RB3)
key = pat7seg[6]; //send '6'
}
PORTB &= 0x00;
PORTBbits.RB6 = 1; //set row3 high
wait_1ms ();
if (PORTBbits.RB1) //check column 1
{
wait_5ms();
if (PORTBbits.RB1)
key = pat7seg[1]; //send '1'
}
if (PORTBbits.RB2)
{
wait_5ms();
if (PORTBbits.RB2)
key = pat7seg[2]; //send '2'
}
if (PORTBbits.RB3)
{
wait_5ms();
if (PORTBbits.RB3)
key = pat7seg[3]; //send '3'
}
PORTB &= 0x00;
PORTBbits.RB7 = 1; //set row4 high
wait_1ms ();
if (PORTBbits.RB1) //is column 1 pressed?
{
wait_5ms();
if (PORTBbits.RB1)
key = pat7seg[10]; //send dp
}
if (PORTBbits.RB2)
{
wait_5ms();
if (PORTBbits.RB2)
key = pat7seg[0]; //send '0'
}
if (PORTBbits.RB3)
{
wait_5ms();
if (PORTBbits.RB3)
key = ENTER; //send 'H'
}
}
return key;
}
Rich (BB code):
do
{
clearDisplay ();
Keypressed = find_key();
while (Keypressed != 0)
if (Keypressed == ENTER)
break;
Keypressed++;
Dig1 = Keypressed % 10; //ones digit
Dig1 = pat7seg[Dig1];
Dig2 = Keypressed / 10;
Dig2 = pat7seg[Dig2];
for (i = 0; i <= 1; i++)
{
PORTC = Dig1;
PORTDbits.RD6 = 0;
PORTDbits.RD7 = 1;
wait_5ms ();
PORTC = Dig2;
PORTDbits.RD6 = 1;
PORTDbits.RD7 = 0;
wait_5ms ();
}
}
while (1);
Last edited by a moderator: