![]() | ![]() | ![]() |
| |||||||
| 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? |
![]() |
| | Tools |
| | #1 |
|
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!! | |
| |
| | #2 |
|
Schematic? Code? Do you have pullups on port C?
| |
| |
| | #3 |
|
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; } } } | |
| |
| | #4 |
|
tis is a part of my schematic.....
| |
| |
| | #5 |
|
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.
| |
| |
| | #6 |
|
izit because tat i din put pullups resistor that cause this problem???
| |
| |
| | #7 |
|
Add them to the 4 input lines of your keypad matrix.
| |
| |
| | #8 | |
| Quote:
| ||
| |
| | #9 | |
| Quote:
| ||
| |
| | #10 | |
| Quote:
| ||
| |
| | #11 | |
| Quote:
sorry for the lame Q... | ||
| |
| | #12 |
|
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.
| |
| |
| | #13 | |
| Quote:
And, what does the compiler say?Chunei, You just need the pullups on the inputs. Mike. | ||
| |
| | #14 |
|
do u mean i need to put the pullups which is a 'gang resistors 10K' like in this schematic????
| |
| |
| | #15 |
|
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) Last edited by blueroomelectronics; 7th April 2008 at 05:33 PM. | |
| |
|
| 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 |