View previous topic :: View next topic |
Author |
Message |
koirnaos
Joined: 23 Dec 2009 Posts: 6
|
HELP! flex keyboard 4x4 driver. |
Posted: Wed Dec 23, 2009 9:41 am |
|
|
Hi everyone! I'm trying to use my 4x4 keyboard with the flex keyboard driver and I have some questions:
1. I put pull up resistors (external) to the row pins of the keyboard.
Do I have to modify the driver like this for it to work right?
Code: |
void kbd_init()
{
set_tris_b(0xF0);
output_b(0xF0);
//port_b_pullups(true);
}
|
2. I think that the driver for the keyboard is made to work with an lcd. What do I have to do in order to get my output to 4 LEDs which will show the hexadecimal number of the button which is pressed?
Thanks in advance
Here is the schematic:
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 23, 2009 3:19 pm |
|
|
Quote: | Do I have to modify the driver like this for it to work right? |
No. Just comment out all the code in the kbd_init() routine.
You have external pull-up resistors. You don't need the internal pull-ups.
Also, the compiler will set the TRIS automatically when it does the
output_high(), output_low(), and input() functions. Just don't specify
"fast io" mode. Let the compiler handle the TRIS.
Quote: |
What do I have to do in order to get my output to 4 LEDs which will show
the hexadecimal number of the button which is pressed?
|
The kbd_getc() function returns an ASCII value from '0' to '9' and 'A' to 'F'.
So, you need to convert it to a 4-bit integer value, so it will display a
4-bit binary value from 0 to F. (I'm not going to handle the '*').
This function will do the conversion for you. Put this line above main().
Code: | #define toint(c) ((c & 0x5F) > '9' ? c - '7' : c - '0') |
Then, when you get the result from kbd_getc() in the 'k' variable,
remove the printf code and do this instead:
Code: | output_a(toint(k)); |
|
|
|
Guest
|
|
Posted: Fri Dec 25, 2009 3:01 pm |
|
|
Thanks for the tip it works line a charm!!!! |
|
|
|