Hey guys
I'm trying to interface a 4x4 keypad to the p24fj32ga002 micro but Im getting the wrong output for row 3 on my LCD. I commented out most of my code and tested the row outputs. With every combination of port B pins I try, I get at least 1 pin giving an output of logic low. Does this mean there is problem with my pic? ie. it cant give a logic high (3.3V) for 4 I/O pins of 1 port...
Here is my test code for the Keypad read function (with unused code commented out)....
#include<p24fj32ga002.h>
#define row1 PORTBbits.RB2
#define row2 PORTBbits.RB3
#define row3 PORTBbits.RB5
#define row4 PORTBbits.RB6
#define col1 PORTBbits.RB7
#define col2 PORTBbits.RB8
#define col3 PORTBbits.RB9
#define col4 PORTBbits.RB10
void DelayMs(unsigned int N);
void DelayUs(unsigned int N);
char KeyRead(void)
{
LATBbits.LATB2=0;
LATBbits.LATB3=0;
LATBbits.LATB5=0;
LATBbits.LATB6=0;
//row pins are outputs
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB3 = 0;
TRISBbits.TRISB5 = 0;
TRISBbits.TRISB6 = 0;
//column pins are inputs
TRISBbits.TRISB7 = 1;
TRISBbits.TRISB8 = 1;
TRISBbits.TRISB9 = 1;
TRISBbits.TRISB10 = 1;
/*check if any keys are being pressed
row1,row2,row3,row4 = 0;
while((col1 || col2 || col3 || col4) == 0)
{ }*/
//set all rows to high
row1 = 1;
row2 = 1;
row3 = 1;
row4 = 1;
/*DelayMs(100);
while(1)
{
//scan keypad for user input
row1 = 0;
if (col1 == 0)
{ return('1'); }
else if (col2 == 0)
{ return('2'); }
else if (col3 == 0)
{ return('3'); }
else
{ row1 = 1; }
row2 = 0;
if (col1 == 0)
{ return('4'); }
else if (col2 == 0)
{ return('5'); }
else if (col3 == 0)
{ return('6'); }
else
{ row2 = 1; }
row3 = 0;
if (col1 == 0)
{ return('7'); }
else if (col2 == 0)
{ return('8'); }
else if (col3 == 0)
{ return('9'); }
else
{ row3 = 1; }
row4 = 0;
if (col2 == 0)
{ return('0'); }
else
{ row4 = 1; }
}*/
return ('N');
}
Can anyone with experience with these pics please help!!
THANKS
I'm trying to interface a 4x4 keypad to the p24fj32ga002 micro but Im getting the wrong output for row 3 on my LCD. I commented out most of my code and tested the row outputs. With every combination of port B pins I try, I get at least 1 pin giving an output of logic low. Does this mean there is problem with my pic? ie. it cant give a logic high (3.3V) for 4 I/O pins of 1 port...
Here is my test code for the Keypad read function (with unused code commented out)....
#include<p24fj32ga002.h>
#define row1 PORTBbits.RB2
#define row2 PORTBbits.RB3
#define row3 PORTBbits.RB5
#define row4 PORTBbits.RB6
#define col1 PORTBbits.RB7
#define col2 PORTBbits.RB8
#define col3 PORTBbits.RB9
#define col4 PORTBbits.RB10
void DelayMs(unsigned int N);
void DelayUs(unsigned int N);
char KeyRead(void)
{
LATBbits.LATB2=0;
LATBbits.LATB3=0;
LATBbits.LATB5=0;
LATBbits.LATB6=0;
//row pins are outputs
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB3 = 0;
TRISBbits.TRISB5 = 0;
TRISBbits.TRISB6 = 0;
//column pins are inputs
TRISBbits.TRISB7 = 1;
TRISBbits.TRISB8 = 1;
TRISBbits.TRISB9 = 1;
TRISBbits.TRISB10 = 1;
/*check if any keys are being pressed
row1,row2,row3,row4 = 0;
while((col1 || col2 || col3 || col4) == 0)
{ }*/
//set all rows to high
row1 = 1;
row2 = 1;
row3 = 1;
row4 = 1;
/*DelayMs(100);
while(1)
{
//scan keypad for user input
row1 = 0;
if (col1 == 0)
{ return('1'); }
else if (col2 == 0)
{ return('2'); }
else if (col3 == 0)
{ return('3'); }
else
{ row1 = 1; }
row2 = 0;
if (col1 == 0)
{ return('4'); }
else if (col2 == 0)
{ return('5'); }
else if (col3 == 0)
{ return('6'); }
else
{ row2 = 1; }
row3 = 0;
if (col1 == 0)
{ return('7'); }
else if (col2 == 0)
{ return('8'); }
else if (col3 == 0)
{ return('9'); }
else
{ row3 = 1; }
row4 = 0;
if (col2 == 0)
{ return('0'); }
else
{ row4 = 1; }
}*/
return ('N');
}
Can anyone with experience with these pics please help!!
THANKS