Hi, anyone knows if there is any error in my keypad coding...I am using pull up resistor way..The row part is ok..when i press a button it goes low..but for the column part it always go low...for the column 3 it is special... when a button is pressed it will go high instead..i do not know where is the mistake make..
#define _XTAL_FREQ 20000000
#include <htc.h>
#include <stdio.h>
#include <p18f4550.h>
#include "config.h"
#include "lcd.h"
#define ROW1 RA0 //row as output
#define ROW2 RA1
#define ROW3 RA2
#define ROW4 RA3
#define COL1 RA4 //column as input
#define COL2 RA5
#define COL3 RA6
void keypad();
void init()
{
TRISA=0B00001111; //row as input to the PIC
PORTA=0B00000000;
TRISB=0B00000000;
PORTB=0B00000000;
TRISD=0B00000000;
PORTD=0B00000000; //LCD
}
void main()
{
init();
lcd_init();
while(1)
{
COL1=0; //set col1 to low
COL2=1;
COL3=1;
while(!ROW1) //if row1 col 1 is pressed (row1 low)
lcd_puts("1");
while(!ROW2)
lcd_puts("4");
while(!ROW3)
lcd_puts("7");
while(!ROW4)
lcd_puts("*");
COL1=1; //set col2 to low
COL2=0;
COL3=1;
while(!ROW1)
lcd_puts("2");
while(!ROW2)
lcd_puts("5");
while(!ROW3)
lcd_puts("8");
while(!ROW4)
lcd_puts("0");
COL1=1; //set col3 to low
COL2=1;
COL3=0;
while(!ROW1)
lcd_puts("3");
while(!ROW2)
lcd_puts("6");
while(!ROW3)
lcd_puts("9");
while(!ROW4)
lcd_puts("#");
}
}
#define _XTAL_FREQ 20000000
#include <htc.h>
#include <stdio.h>
#include <p18f4550.h>
#include "config.h"
#include "lcd.h"
#define ROW1 RA0 //row as output
#define ROW2 RA1
#define ROW3 RA2
#define ROW4 RA3
#define COL1 RA4 //column as input
#define COL2 RA5
#define COL3 RA6
void keypad();
void init()
{
TRISA=0B00001111; //row as input to the PIC
PORTA=0B00000000;
TRISB=0B00000000;
PORTB=0B00000000;
TRISD=0B00000000;
PORTD=0B00000000; //LCD
}
void main()
{
init();
lcd_init();
while(1)
{
COL1=0; //set col1 to low
COL2=1;
COL3=1;
while(!ROW1) //if row1 col 1 is pressed (row1 low)
lcd_puts("1");
while(!ROW2)
lcd_puts("4");
while(!ROW3)
lcd_puts("7");
while(!ROW4)
lcd_puts("*");
COL1=1; //set col2 to low
COL2=0;
COL3=1;
while(!ROW1)
lcd_puts("2");
while(!ROW2)
lcd_puts("5");
while(!ROW3)
lcd_puts("8");
while(!ROW4)
lcd_puts("0");
COL1=1; //set col3 to low
COL2=1;
COL3=0;
while(!ROW1)
lcd_puts("3");
while(!ROW2)
lcd_puts("6");
while(!ROW3)
lcd_puts("9");
while(!ROW4)
lcd_puts("#");
}
}