![]() | ![]() | ![]() |
| |||||||
| 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 |
| | #16 |
|
Hi, From the schematic, it's clearly shown that for checking '1' source RB7 and read from RB3.
__________________ bananasiong | |
| |
| | #17 |
|
so it's means that i the program that i wrote i correct already?
Last edited by darsin; 15th July 2008 at 12:58 PM. | |
| |
| | #18 |
|
Hi Darsin, To read from a matrix keyboard you need to make 1 of the row bits an output and make it high. You can then read 4 column bits. See if this function will read your keyboard, Code: unsigned int ReadKeys(){
unsigned int Key;
TRISB=0b01111111; //make row 1 output
LATB=0b10000000; //and make it high
Key=PORTB&0x0f; //read the columns into bits 0-3
TRISB=0b10111111; //make row 2 output
LATB=0b01000000; //and make it high
Key|=(PORTB&0x0f)<<4; //read the columns into bits 4-7
TRISB=0b11011111; //make row 3 output
LATB=0b00100000; //and make it high
Key|=(PORTB&0x0f)<<8; //read the columns into bits 8-11
TRISB=0b11101111; //make row 4 output
LATB=0b00010000; //and make it high
Key|=(PORTB&0x0f)<<12; //read the columns into bits 12-15
return Key;
}
HTH. Mike. | |
| |
| | #19 |
|
yes it could work already thanks! and it is for just row4 (*,0,#,D) on at pin B3-B0 respectively if i wan it to light up all then have to write the second ReadKeys again? | |
| |
| | #20 |
|
I don't understand your question. However, the integer returned from the function would have a bit set for each key pressed. They would be, bit 0 = A, bit 1 = 3, bit 2 = 2, . . bit 14 = 0, bit 15 = *, So, to do something if the * key was pressed you would do, Code: if(ReadKeys()&(1<<15)!=0){
//do something here
}
Mike. | |
| |
| | #21 | |
| Quote:
When I looked yesterday, it was very quick, and not so helpful... Pommies function will return a word containing the info on which keys are pressed in your pad. It handles all of the keys. If any keys are pressed the corresponding bits will be set in the word it returns. If no keys are pressed you will get 0x00 back. Use a bit mask to see which keys have been pressed. Do you understand how to do this, or do you need more info? What I noticed in your last post, is that you turned on the LED for only 200 cycles. If your mcu is running at 4MHz then this isn't long enough to see it on... its only 200 micro seconds... 2 tenths of a thousandth of a second... You have to turn it on longer than this or you won't see it come on. You should also look up switch debouncing because you will find that the keys are not reliable: http://www.ganssle.com/debouncing.pdf. http://www.best-microcontroller-proj...-debounce.html I see Mike is still on here and I'm so slow... Last edited by BeeBop; 15th July 2008 at 04:28 PM. | ||
| |
| | #22 |
|
oh..i knew it so u mean if i wanna press the key '*', then the code should be: if (ReadKeys()&(1<<15)!=0) then if i put a led on the port c0 and when i press '*' i want to high it is : void main() { TRISC=0b00000000; //make port c output while (1) { if (ReadKeys()&(1<<15)!=0) { LATC=0b00000001; //high the pin c0 } } } i try this but this could not work for my led | |
| |
| | #23 |
|
dear beebop, can you show me the steps? i'm not understand about bit masks.. thanks! | |
| |
| | #24 | |
| Quote:
When you and two words, if any two bit positions are set (logic 1) then the corresponding bit in the result is set. For example, say you use this: Code: #define myKey 0x8000 // same as (1<<15)
if(ReadKeys() & myKey !=0) {
//myKey has been pressed
}
0x8000 = 1000 0000 0000 0000 looking at ReadKeys() it sets the Most Significant Bit if row 4 key 4 was pressed = 1000 0000 0000 0000 so 1000 0000 0000 0000 & 1000 0000 0000 0000 equals 1000 0000 0000 0000 since the 2 most significant bits were set if any other key is pressed, say row 2 col 1: ReadKeys() returns 0000 0000 0001 0000 and when you and this with your bit mask you will get zero: 1000 0000 0000 0000 & 0000 0000 0001 0000 equals 0000 0000 0000 0000 Hope I've explained it well, but if you need more just ask. I need a coffee.... | ||
| |
| | #25 |
|
err... frankly speaking it's a bit complicated for me @.@... well as u mention just now the "row 4 key 4 is press" means is pressing which key? i thought that (1<<15) is pressing the '*' as Pommie said just now? err.. i'm sorry..i'm always trouble u all... | |
| |
| | #26 | |||
| Quote:
His ReadKeys() reads a 4x4 key pad. Just to clarify, you are using a 4x4 keypad, yes? or a 3x4? Quote:
0x0001 << 15 = 1000 0000 0000 0000 Does it make sense now? Quote:
... You don't need to apologize!
Last edited by BeeBop; 15th July 2008 at 06:05 PM. | ||||
| |
| | #27 |
|
oh..i'm using the 4x4 keypad i now can catch a bit what u mean.. the row 2 col1: row2 =1000 0000 0000 0000 col1 = 0000 0000 0001 0000 is it like that? why col1 will be 0000 0000 0001 0000? Last edited by darsin; 15th July 2008 at 06:43 PM. | |
| |
| | #28 |
|
ok so my keypad is work... thank you bananasiong, pommie and beebop for helping me... i'm really appreaciate it... | |
| |
|
| 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 |