View previous topic :: View next topic |
Author |
Message |
Vitoco.lr
Joined: 08 Jul 2017 Posts: 5
|
How to connect matrix keypad to portc on pic16f877a? |
Posted: Sat Jul 08, 2017 1:57 pm |
|
|
Hello guys, I'm new at this site and I really need help as I'm an electronics technician more than a programmer... my question is:
What should I change to kbd.c so i can work with this pic using the matrix keypad on portC?, hopefully you guys can teach me a little bit of it so I can be more independent on that kind of topic... Any help will be much appreciated |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Jul 08, 2017 2:36 pm |
|
|
Check here...
http://www.ccsinfo.com/forum/viewtopic.php?t=26333&highlight=flexkbd
This is a 'flexible' version of the keypad driver. I'm currently using it for a couple of projects. The GREAT thing about it is how EASY it is to re-define PIC I/O pins to be rows and columns !
One warning...be sure to check the I/O pins as to whether they can be used for input or output or both. Some pins can ONLY be say input...so you can NEVER use them as an output.
If the link doesn't work, just use the forum search and enter 'flex_kbd', 4th or 5th hit is the flex driver.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jul 08, 2017 7:33 pm |
|
|
Vitoco.lr wrote: | What should I change to kbd.c so i can work with this pic using the matrix keypad on portC ? |
Replace the conditional compilation sections at the start of kbd.c with
this new code. This adds the option to support PortC:
Code: | #if defined use_portb_kbd
#byte kbd = getenv("SFR:PORTB")
#elif defined use_portc_kbd
#byte kbd = getenv("SFR:PORTC")
#else
#byte kbd = getenv("SFR:PORTD")
#endif
#if defined use_portb_kbd
#define set_tris_kbd(x) set_tris_b(x)
#elif defined use_portc_kbd
#define set_tris_kbd(x) set_tris_c(x)
#else
#define set_tris_kbd(x) set_tris_d(x)
#endif |
Then in your main source file, you should put the #define statement
for 'use_portc_kbd' above the #include line for the kbd driver. Example:
Code: | #include <16F887.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#define use_portc_kbd
#include <kbd.c>
//==========================
void main()
{
while(TRUE);
} |
|
|
|
Vitoco.lr
Joined: 08 Jul 2017 Posts: 5
|
For PCM Programmer |
Posted: Sat Jul 08, 2017 9:41 pm |
|
|
For some reason the code isn't working for me, I already installed the pull up resistors in the rows, i even changed them to the columns and nothing... this is how i have the driver code... maybe there is a mistake on how i pasted it.
Code: |
// Make sure the port used has pull-up resistors (or the LCD) on
// the column pins
#if defined use_portb_kbd
#byte kbd = getenv("SFR:PORTB")
#elif defined use_portc_kbd
#byte kbd = getenv("SFR:PORTC")
#else
#byte kbd = getenv("SFR:PORTD")
#endif
#if defined use_portb_kbd
#define set_tris_kbd(x) set_tris_b(x)
#elif defined use_portc_kbd
#define set_tris_kbd(x) set_tris_c(x)
#else
#define set_tris_kbd(x) set_tris_d(x)
#endif
//Keypad connection: (for example column 0 is B0)
#define COL0 (1 << 0) // PIN_B0
#define COL1 (1 << 1) // PIN_B1
#define COL2 (1 << 2) // PIN_B2
#define COL3 (1 << 3) // PIN_B3
#define ROW0 (1 << 4) // PIN_B4
#define ROW1 (1 << 5) // PIN_B5
#define ROW2 (1 << 6) // PIN_B6
#define ROW3 (1 << 7) // PIN_B7
#define ALL_ROWS (ROW0|ROW1|ROW2|ROW3)
#define ALL_PINS (ALL_ROWS|COL0|COL1|COL2|COL3)
// Keypad layout:
char const KEYS[4][4] = {{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}}; |
|
|
|
Vitoco.lr
Joined: 08 Jul 2017 Posts: 5
|
Woops! my mistake |
Posted: Sat Jul 08, 2017 10:02 pm |
|
|
At last the code worked, it didn't after I applied to code you sent because of one mistake I had in the main code. It worked amazingly, thank you all very much! |
|
|
|