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

what should I modify to kbd.c to use port C?

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



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

what should I modify to kbd.c to use port C?
PostPosted: Mon Feb 14, 2005 6:43 pm     Reply with quote

Hello All,

Would someone please tell me what should be modified in kbd.c to use port C? (PIC18F252).

Thank you in advance
Peter

Code:

// Un-comment the following define to use port B
// #define use_portb_kbd TRUE

// Make sure the port used has pull-up resistors (or the LCD) on
// the column pins


#if defined(__PCH__)
#if defined use_portb_kbd
   #byte kbd = 0xF81                   // This puts the entire structure
#else
   #byte kbd = 0xF83                   // This puts the entire structure
#endif
#else
#if defined use_portb_kbd
   #byte kbd = 6                  // on to port B (at address 6)
#else
   #byte kbd = 8                 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_kbd
   #define set_tris_kbd(x) set_tris_b(x)
#else
   #define set_tris_kbd(x) set_tris_d(x)
#endif

//Keypad connection:   (for example column 0 is B2)
//                Bx:

#ifdef blue_keypad  ///////////////////////////////////// For the blue keypad
#define COL0 (1 << 2)
#define COL1 (1 << 3)
#define COL2 (1 << 6)

#define ROW0 (1 << 4)
#define ROW1 (1 << 7)
#define ROW2 (1 << 1)
#define ROW3 (1 << 5)

#else ////////////////////////////////////////////////// For the black keypad
#define COL0 (1 << 5)
#define COL1 (1 << 6)
#define COL2 (1 << 7)

#define ROW0 (1 << 1)
#define ROW1 (1 << 2)
#define ROW2 (1 << 3)
#define ROW3 (1 << 4)

#endif
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 14, 2005 7:55 pm     Reply with quote

The lines that you need to change are shown in bold below.
I'm going to let you look in the data sheet to see the register
address for Port C in the 18F252. The change to the 2nd
bolded line should be obvious.

Also remember that you need to put 4 external pull-up
resistors (10K) on the Row pins.

#if defined(__PCH__)
#if defined use_portb_kbd
#byte kbd = 0xF81 // This puts the entire structure
#else
#byte kbd = 0xF83 // This puts the entire structure
#endif
#else
#if defined use_portb_kbd
#byte kbd = 6 // on to port B (at address 6)
#else
#byte kbd = 8 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_kbd
#define set_tris_kbd(x) set_tris_b(x)
#else
#define set_tris_kbd(x) set_tris_d(x)
#endif
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

keypad connection?
PostPosted: Tue Feb 15, 2005 12:31 pm     Reply with quote

Hello PCM programmer,

I've already modified the 2 lines to:

#byte kbd = 0xF82 // This puts the entire structure
#define set_tris_kbd(x) set_tris_c(x)

would you please explain to me how to connect the keypad to port c?

I've already have the pull-up resistors, what I don't know is to which pins do I connect COLS and to which pins do I connect ROWS...

Thank you in advance
Peter
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 15, 2005 12:38 pm     Reply with quote

Can you give the manufacturer and part number of your keypad ?
If you have a link to the web page, post that too.
I would like to look at keypad's connector pinout in the data sheet.
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

keypad info
PostPosted: Tue Feb 15, 2005 2:43 pm     Reply with quote

www.storm-keypads.com

Graphic Series
12 KEY PAD
Part No: GS120203

Contact Connections ('o' are pins, as viewed from rear of keypad):
o o o o o o o o
8 7 6 5 4 3 2 1

Key Location: ('o' are keys, as viewed from front of keypad)
A 1 2 3
B o o o
C o o o
D o o o

Contact Matrix:

Pin - Row Column:
1-A
2-B
3-1
4-2
5-3
6-Not used
7-D
8-C

Thank you in advance
Peter
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 15, 2005 4:20 pm     Reply with quote

Let's assume that you wire the keypad connector to the PIC
in a 1:1 manner. That is, pin 1 on the keypad goes to pin C0
on the PIC, pin 2 on the keypad goes to pin C1 on the PIC,
and so on. This chart shows the connections:

Code:

 Keypad     Keypad    PIC     CCS signal   10K Pull-up
pin name    pin       pin       name        required

   A         1        C0        Row0         Yes
   B         2        C1        Row1         Yes
   1         3        C2        Col0         No
   2         4        C3        Col1         No
   3         5        C4        Col2         No
   -         6        NC           -         No
   D         7        C6        Row3         Yes
   C         8        C7        Row2         Yes


Then your bitmask statements would be:
Code:

#define COL0 (1 << 2)
#define COL1 (1 << 3)
#define COL2 (1 << 4)
#define ROW0 (1 << 0)
#define ROW1 (1 << 1)
#define ROW2 (1 << 7)
#define ROW3 (1 << 6)


The equivalent binary notation for the bitmasks is:
Code:

#define COL0  0b00000100
#define COL1  0b00001000
#define COL2  0b00010000
#define ROW0  0b00000001
#define ROW1  0b00000010
#define ROW2  0b10000000
#define ROW3  0b01000000


Here is a thread that explains how this is done:
http://www.ccsinfo.com/forum/viewtopic.php?t=2671
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

Thank you!
PostPosted: Tue Feb 15, 2005 5:03 pm     Reply with quote

I just wanted to say thank you. It worked perfectly!

Best Regards
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