![]() | ![]() | ![]() |
| |||||||
| 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 |
|
hello all, i'm now testing the 4x4 keypad, but now i just do a simple program that just to on a led when i pressing a '1' after troubleshooting, the code has no problem but the led could not blink.. here is my simple code: #include <p18f4550.h> #define row1 PORTBbits.RB7 #define row2 PORTBbits.RB6 #define row3 PORTBbits.RB5 #define row4 PORTBbits.RB4 #define col1 PORTBbits.RB3 #define col2 PORTBbits.RB2 #define col3 PORTBbits.RB1 #define col4 PORTBbits.RB0 void main() { TRISB=0xFF; TRISD=0x00; while (1){ int i; int temp; PORTB=0; if (row1==1 & col1==1) { PORTDbits.RD7=1; temp=200; while(temp){ temp--; } i=1; } } } i had pull down 10k resistor to ground but it still cannot work. please help. Last edited by darsin; 14th July 2008 at 05:58 PM. | |
| |
| | #2 | |
| Quote:
you have used the bitwise and (&) rather than the logical and (&&) I'm not sure this is your only problem, but try changing the line Code: if (row1==1 & col1==1) Code: if (row1==1 && col1==1) | ||
| |
| | #3 |
|
well, i changed it just now but the result is still the same... am I correct that i pull down resistor to ground at the column pins before connecting to the port? | |
| |
| | #4 |
|
Hi, For the 4x4 key pad, either the row or the column has to be output, to source and the other one as input, to read. For example: If the rows are used to source, then set them as output. Set row1 high, then read all the columns, followed by row2, etc. Pull down resistors for the input pins are necessary.
__________________ bananasiong | |
| |
| | #5 |
|
If your keypad is a 4x4 matrix, then making both the row and columns inputs on the PIC won't work. Make the 4 PIC pins connected to the columns outputs and set them to the low state. Make the 4 PIC pins connected to the row inputs and use pull up resistors on them. Then wait for one of the row inputs to go low when a switch is pressed. Then scan each column output low while making the others high until you've identified which column was active. Now you'll know which key is pressed.
__________________ Inside every little problem, is a big problem trying to get out. | |
| |
| | #6 |
|
#include <p18f4550.h> #define row1 PORTBbits.RB7 #define row2 PORTBbits.RB6 #define row3 PORTBbits.RB5 #define row4 PORTBbits.RB4 #define col1 PORTBbits.RB3 #define col2 PORTBbits.RB2 #define col3 PORTBbits.RB1 #define col4 PORTBbits.RB0 void main() { TRISB=0x0F; TRISD=0x00; while (1){ int i; int temp; PORTB=0; if (row1==1) { PORTDbits.RD7=1; temp=200; while(temp){ temp--; } i=1; } } } is it like that?? but my led still can not work... | |
| |
| | #7 |
|
No. row1 is configured as output and you don't read from it. if (row1==1) is reading the pin. I assume number 1 on the keypad is connected on row1 and col1. So you should set row1 high, then read from col1. Do you get what I mean?
__________________ bananasiong | |
| |
| | #8 |
|
okay how to read from col1? pressing the "1"?
| |
| |
| | #9 |
|
Read from col1 means Code: if (col1 == 1)
__________________ bananasiong | |
| |
| | #10 |
|
#include <p18f4550.h> #define row1 PORTBbits.RB7 #define row2 PORTBbits.RB6 #define row3 PORTBbits.RB5 #define row4 PORTBbits.RB4 #define col1 PORTBbits.RB3 #define col2 PORTBbits.RB2 #define col3 PORTBbits.RB1 #define col4 PORTBbits.RB0 void main() { TRISB=0x0f; //row configure as output, col is input TRISD=0; //configure port d as output while (1){ int i; //store i int temp; row1=1; if (col1==1) //read from col1 { PORTDbits.RD7=1; //if key 1 is press then high D7 temp=200; //delay while(temp){ temp--; } i=1; //i as 1 } } } is it correct? | |
| |
| | #11 |
|
why the portD7 can't be high??although i already set it as output high
| |
| |
| | #12 |
|
Oops. Just realize your row1 is RB7 and col1 is RB3. Can you show the schematic? RD7 doesn't go high even you have tried all the buttons?
__________________ bananasiong | |
| |
| | #13 |
|
=.=! how to attach image up there?cant attach it.. i use pic18f4550.h and r1-r4 is RB7-RB4 while col1-col4 is RB3-RB0 is my program correct? i got pull down 10k resistor to ground but still cannot on the led... please help me.. | |
| |
| | #14 |
|
It is in the "additional options" when you're posting the reply. Click on manage attachment.
__________________ bananasiong | |
| |
| | #15 |
|
so this is my schematic but i just give you the one i just connect the keypad coz' i don't want to draw again my circuit. do i need to connect 1k resistor at the column? | |
| |
|
| Tags |
| 4x4, code, keypad, problems |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Problems with 4x4 keypad interact with LCD.. | chunei | General Electronics Chat | 17 | 10th April 2008 02:23 PM |
| Problem with keypad code | pic_programm3r | Micro Controllers | 20 | 2nd April 2008 07:37 AM |
| what wrong with my keypad code | eleceyes | Micro Controllers | 0 | 20th February 2008 03:08 AM |
| Keypad Code | gregmcc | Micro Controllers | 5 | 11th May 2006 09:01 AM |
| code lock keypad questions.... | eyevancsu | Electronic Projects Design/Ideas/Reviews | 7 | 10th April 2003 08:17 AM |