Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
Tools
Old 6th April 2008, 03:27 PM   #1
Default Problems with 4x4 keypad interact with LCD..

Hi..
I have a problem here...

My 4x4 keypad had been connected to PIC16F877A Port C...according to this datasheet : http://www.futurlec.com/Keypad4x4.shtml

However i had programme some code into the PIC & the LCD do display something but when i press the button of the keypad, it just display the wrong key...
Example : When I press 1 >> LCD Display "0" or sometimes display different number... Even when I didnt press anything, sometime it will just display a number... & there is a Delay when i press a Key...

Wanna ask whats the problem of my circuit????
Isnt that I need to connect some sort of encoder instead of just connect the keypad directly to the Port C of my PIC???

hoe someone can help me!!!! Thanks!!
chunei is offline  
Old 6th April 2008, 03:41 PM   #2
Default

Schematic? Code? Do you have pullups on port C?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 6th April 2008, 04:03 PM   #3
Default

Erm.. I didnt put pullups on port C... Does this effect the interaction from keypad to PIC to LCD???? whats da purpose of pullups???

these is the codes :

unsigned char var1, var2, kp;
char attempts=0;
char state = 1;//start from state 1
char txt[4];

char text[] = "Combination Lock" ;//message text
char text1[]= " *Door1 On*";
char text2[]= " *Door2 On*";
char text3[]= "*Door1&2 On*";

char table[17] = {0,1,2,3,0,4,5,6,0,7,8,9,0,10,0,11,0};

void main(void) {

CMCON = 0x07 ;//PORTA to digital mode
LCD_Init(&PORTB) //Pin assignment
;//RS,E,RW,D7,D6,D5,D4
LCD_Cmd(LCD_CLEAR) ;//Clear display
LCD_Cmd(LCD_CURSOR_OFF) ;//Turn cursor off
LCD_Cmd(LCD_SECOND_ROW) ;//Move to ROW2 for rest of program
//Seup Keypad on PORTB
Keypad_Init(&PORTC) ;// Initialize Keypad on PORTB
LCD_OUT(1,1,text) ;//Print welcome message
while(1) { //while ever loop
switch(state){ //check the current state
case 1:
LCD_Cmd(LCD_CLEAR) ;
LCD_out(1,1,text);
LCD_out(2,1,"EnterPass:");
while(!keypad_Read()){} //wait for key1 press
Delay_ms(5) ;//debounce time
kp = Keypad_Released() ;//wait for release
var1=kp; //store var1 into kp
var1=table[kp];
ByteToStr(var1,txt);
Lcd_Out_Cp(txt);
state = 2;
break;
case 2:
if(kp==15) state=1; //go back state 1 when kp = # (enter key)
else if(kp==13) state=1;//go back state 1 when kp = * (clear key)
else
state = 3;//go to state 3 get key2
break;
case 3:
while(!keypad_Read()){} //wait for key2 press
Delay_ms(5) ;//debounce time
kp = Keypad_Released() ;//wait for release
var2=kp;//store var2 into kp
var2=table[kp];
ByteToStr(var2,txt);
Lcd_Out_Cp(txt);
state=4;
break;
case 4:
if(kp==15) state=1;//enter key goes back state 1
else if(kp==13) state=1;//clear key goes back state 1
else
state = 5;//continue goes to state 4
break;
case 5:
while(!keypad_Read()){} //wait for enter key press
Delay_ms(10) ;//debounce time
kp = Keypad_Released() ;//wait for release
state = 6;
break;
case 6:
if(kp==13)
state =1; //clear goes back to s1
else if(kp==15)
state = 7;//enter key goes to state 7
else state = 5;
break;
case 7:
if (var1==0 && var2==5)//comparing for door1
state = 9; //goes state 11 open door1
else state =8;
break;

case 8:
LCD_OUT(2,1,"**Invalid Code**") ;
attempts++; //increment attempts
kp+=attempts;//kp = kp + attempts
if(attempts < 3) //attempts less than 3 times
state=1; //go state 1
else
state=10;
while(!keypad_Read()){} //wait for enter key press
Delay_ms(10) ;//debounce time
kp = Keypad_Released() ;//wait for release
LCD_Cmd(LCD_CLEAR);
break;
case 9://open door1 for 5secs
LCD_Cmd(LCD_CLEAR);
Lcd_out(2,1,text1) ;
Lcd_out(1,1,text);
//turn door1 led on
PORTA.F4=1;
PORTB.f4=1;
PORTB.F7 = 0;
PORTB.F6 = 0;
PORTB.F5 = 0 ;
Delay_ms(5000); //delay 5secs
//turn door1 led off
PORTA.F4 = 0;
LCD_Cmd(LCD_CLEAR) ;
attempts=0;
state=1;
break;

default:// must be a bad attempts
LCD_OUT(2,1," **Alarm On**");
LCD_OUT(1,1,text);
PORTA.F4=1;
PORTB.F4=0;
PORTB.F5=0;
PORTb.f6=0;
PORTb.f7=1;
Delay_ms(5000);
PORTA.F4=0;
LCD_Cmd(LCD_CLEAR);
attempts=0;
state = 1; //goes to state 1
break;
}
}
}
chunei is offline  
Old 6th April 2008, 04:23 PM   #4
Default

tis is a part of my schematic.....
Attached Thumbnails
Problems with 4x4 keypad interact with LCD..-snapshot20080406231431.jpg  
chunei is offline  
Old 6th April 2008, 04:25 PM   #5
Default

Please use code tags, also yes you need pullups on port C. A pullup is a resistor that pulls floating input pins to VDD, usually 10K is a good choice.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 6th April 2008, 04:36 PM   #6
Default

izit because tat i din put pullups resistor that cause this problem???
chunei is offline  
Old 6th April 2008, 04:38 PM   #7
Default

Add them to the 4 input lines of your keypad matrix.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 7th April 2008, 11:33 AM   #8
Default

Quote:
Originally Posted by chunei
izit because tat i din put pullups resistor that cause this problem???
yes. if you don't put pull up resistor (connected to VCC, usually 10k) or pull down resistor (connected to GND) the value read from that port will be floating when the the input is not connected, giving wrong values. Pullup/pulldown resistors give the read value a default value of 1 or 0 if nothing is connected.
mdanh2002 is offline  
Old 7th April 2008, 03:11 PM   #9
Default

Quote:
Originally Posted by blueroomelectronics
Add them to the 4 input lines of your keypad matrix.
erm... 4 input lines??? my keypad is 4x4 matrix.. and it should be 8 input lines right??
chunei is offline  
Old 7th April 2008, 04:44 PM   #10
Default

Quote:
Originally Posted by chunei
erm... 4 input lines??? my keypad is 4x4 matrix.. and it should be 8 input lines right??
No, 4 inputs and 4 outputs.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 7th April 2008, 04:48 PM   #11
Default

Quote:
Originally Posted by Nigel Goodwin
No, 4 inputs and 4 outputs.
Do u mean that 4inputs is for the columns & 4outputs is for the row????

sorry for the lame Q...
chunei is offline  
Old 7th April 2008, 04:53 PM   #12
Default

Read what the compiler instructions say, it's not obvious from the code - you could always stick 8 resistors on, they won't do any harm on the outputs.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 7th April 2008, 05:01 PM   #13
Default

Quote:
Originally Posted by Nigel Goodwin
Read what the compiler instructions say, it's not obvious from the code - you could always stick 8 resistors on, they won't do any harm on the outputs.
You put pullups on your outputs? And, what does the compiler say?

Chunei,

You just need the pullups on the inputs.

Mike.
Pommie is online now  
Old 7th April 2008, 05:19 PM   #14
Default

do u mean i need to put the pullups which is a 'gang resistors 10K' like in this schematic????
Attached Thumbnails
Problems with 4x4 keypad interact with LCD..-snapshot20080408000445.jpg  
chunei is offline  
Old 7th April 2008, 05:31 PM   #15
Default

That'll work.

If you want to get fancy you could mux the 4 LCD data lines to the 4 keypad columns. (The resistors only need to go across the rows since you're driving the columns)
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/

Last edited by blueroomelectronics; 7th April 2008 at 05:33 PM.
blueroomelectronics is offline  
Reply

Tags
4x4, interact, keypad, lcd, problems

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
LCD 2x16 Demo for the Unicorn (18F4550) blueroomelectronics Micro Controllers 25 13th January 2009 03:04 AM
HD44780 LCD operation ssylee Micro Controllers 25 15th December 2007 01:52 AM
HD44780 lcd help jay543_uk Micro Controllers 12 8th November 2007 04:26 PM
PIC16F628A LCD problems. HerbertMunch Micro Controllers 17 2nd October 2007 10:20 AM
PicBasic Keypad program Sora Micro Controllers 0 20th April 2004 08:02 PM



All times are GMT. The time now is 03:09 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker