kgavionics
Full Member level 3
- Joined
- Jun 12, 2012
- Messages
- 167
- Helped
- 7
- Reputation
- 14
- Reaction score
- 11
- Trophy points
- 1,298
- Location
- Alberta.Canada
- Activity points
- 2,482
Hi guys
i'm trying to build a C program to scan my 3x4 matrix keypad.Before i describe the problem i want to let you know about the connection i made between the pic18f452 and the keypad.
The 3 rows are connected to PORTE (RE0 to RE2) and the 4 rows are connected to PORTC ( RC0 to RC3) .The rows and columns are connected to Vcc through 10k pull up resistors.
this is my code
My problem, when i press a key , nothing happens and the leds connected to PORTB remains off.
can someone help me please and tell me what's wrong with my program?
thanks in advance
i'm trying to build a C program to scan my 3x4 matrix keypad.Before i describe the problem i want to let you know about the connection i made between the pic18f452 and the keypad.
The 3 rows are connected to PORTE (RE0 to RE2) and the 4 rows are connected to PORTC ( RC0 to RC3) .The rows and columns are connected to Vcc through 10k pull up resistors.
this is my code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <p18f452.h>
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#define column PORTE
#define row PORTC
unsigned char highn;
unsigned char lown;
unsigned char keypress;
void main (void)
{
TRISB=0;
while (1)
{
TRISE=0; //set column as outputs
TRISC=1; //set row bits as inputs
column=0; // set column bits to 0
lown=row; //read rows
lown=lown<<1; // to get the 4 bits lower nibbles
TRISE=1; //set colum as inputs
TRISC=0; //set row bits as outputs
row=0; // set row bits to 0
highn=column; // read columns bits
highn =highn & 0x0f; // mask the higher bits
highn=highn<<4; // make lower bits as higher bits
keypress=lown | highn; // combine rows and columns
PORTB=keypress; // send the keypress to portb
}
}
My problem, when i press a key , nothing happens and the leds connected to PORTB remains off.
can someone help me please and tell me what's wrong with my program?
thanks in advance