CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to connect matrix keypad to portc on pic16f877a?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Vitoco.lr



Joined: 08 Jul 2017
Posts: 5

View user's profile Send private message

How to connect matrix keypad to portc on pic16f877a?
PostPosted: Sat Jul 08, 2017 1:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 08, 2017 2:36 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 08, 2017 7:33 pm     Reply with quote

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

View user's profile Send private message

For PCM Programmer
PostPosted: Sat Jul 08, 2017 9:41 pm     Reply with quote

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

View user's profile Send private message

Woops! my mistake
PostPosted: Sat Jul 08, 2017 10:02 pm     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group