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 support@ccsinfo.com

Pinouts 4x4 keypad

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







Pinouts 4x4 keypad
PostPosted: Sun Mar 09, 2003 7:29 am     Reply with quote

<font face="Courier New" size=-1>I have modify the code for 4x4 keypad. Now my question is how should we lay the pin outs. My keypad is on PORTB.

B2--Col0
B3--Col1
B4--Col2
B5--Col3
B6--Row0
B7--Row1
B8--Row2
B1--Row3</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12479
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Pinouts 4x4 keypad
PostPosted: Mon Mar 10, 2003 1:42 pm     Reply with quote

:=<font face="Courier New" size=-1>I have modify the code for 4x4 keypad. Now my question is how should we lay the pin outs. My keypad is on PORTB.
:=
:=B2--Col0
:=B3--Col1
:=B4--Col2
:=B5--Col3
:=B6--Row0
:=B7--Row1
:=B8--Row2
:=B1--Row3</font>
-------------------------------------------------------------

You can lay them out whatever way you want. You just have
to make sure to define the proper bitmasks for the pins.
CCS does this in the kbd.c file, by doing this:

#define COL0 (1 << 2)
#define COL1 (1 << 3)
#define COL2 (1 << 6)

That's the same thing as this:
// Bit: 76543210
#define COL0 0b00000100
#define COL1 0b00001000
#define COL2 0b01000000
</PRE>

I suspect that the reason CCS has the pins out of order,
is because their keypad has them out of order, and they
wanted to use a flat-ribbon cable, and go directly from
the keypad connector to another connector on Port B.
They didn't want to have crossed wires or make a special cable.
It's easy to define the signal location with a #define
statement.

If you have a question about which pin is COL0, COL1, etc.,
on your keypad, then look at the data sheet for that keypad.
If you still can't tell, then post the keypad manufacturer
and part number, and I will check it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12501
slahiri
Guest







Re: Pinouts 4x4 keypad
PostPosted: Mon Mar 10, 2003 6:44 pm     Reply with quote

:=:=<font face="Courier New" size=-1>I have modify the code for 4x4 keypad. Now my question is how should we lay the pin outs. My keypad is on PORTB.
:=:=
:=:=B2--Col0
:=:=B3--Col1
:=:=B4--Col2
:=:=B5--Col3
:=:=B6--Row0
:=:=B7--Row1
:=:=B8--Row2
:=:=B1--Row3</font>
:=-------------------------------------------------------------
:=
:=You can lay them out whatever way you want. You just have
:=to make sure to define the proper bitmasks for the pins.
:=CCS does this in the kbd.c file, by doing this:
:=
:=#define COL0 (1 << 2)
:=#define COL1 (1 << 3)
:=#define COL2 (1 << 6)
:=
:=That's the same thing as this:
:= :=// Bit: 76543210
:=#define COL0 0b00000100
:=#define COL1 0b00001000
:=#define COL2 0b01000000
:=</PRE>
:=
:=I suspect that the reason CCS has the pins out of order,
:=is because their keypad has them out of order, and they
:=wanted to use a flat-ribbon cable, and go directly from
:=the keypad connector to another connector on Port B.
:=They didn't want to have crossed wires or make a special cable.
:=It's easy to define the signal location with a #define
:=statement.
:=
:=If you have a question about which pin is COL0, COL1, etc.,
:=on your keypad, then look at the data sheet for that keypad.
:=If you still can't tell, then post the keypad manufacturer
:=and part number, and I will check it.


I have a velleman keypad 4x4 my pin outs are:
pin1 col0
pin2 col1
pin3 col2
pin4 col3
pin5 row0
pin6 row1
pin7 row2
pin8 row3

Now question I have is how are we calculating bit mask, I am confuse a) Is it 8 bit, so when we say
#define COL0 (1 << 2)
00000001<< 2 = 00000100 =4 Is this correct
#define COL1 (1 << 3)
00000001 << 3 = 00001000 = 8 Is this correct
#define COL2 (1 << 6)
00000001 << 6 = 01000000 = 64 ? this is where I am lost
then what should be col3 bit mask would look.


#define ROW0 (1 << 4)
#define ROW1 (1 << 7)
#define ROW2 (1 << 1)
#define ROW3 (1 << 5)
___________________________
This message was ported from CCS's old forum
Original Post ID: 12511
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Pinouts 4x4 keypad
PostPosted: Mon Mar 10, 2003 8:01 pm     Reply with quote

:=:=:=<font face="Courier New" size=-1>I have modify the code for 4x4 keypad. Now my question is how should we lay the pin outs. My keypad is on PORTB.
:=:=:=</font>

-------------------------------------------------
Let's assume that you connect COL0 to Port B bit 0,
and so on.

The following chart will show what bitmask you should use
for each signal name.

<PRE>
Signal Keypad 16F877 Port B bitmask
name pin pin bit
<BR>
COL0 1 33 0 0b00000001
COL1 2 34 1 0b00000010
COL2 3 35 2 0b00000100
COL3 4 36 3 0b00001000
ROW0 5 37 4 0b00010000
ROW1 6 38 5 0b00100000
ROW2 7 39 6 0b01000000
ROW3 8 40 7 0b10000000
<BR>
<BR>
So you would use these define statements:
<BR>
#define COL0 0b00000001
#define COL1 0b00000010
#define COL2 0b00000100
#define COL3 0b00001000
#define ROW0 0b00010000
#define ROW1 0b00100000
#define ROW2 0b01000000
#define ROW3 0b10000000
</PRE>

I have shown the bitmasks in binary format, so that you
don't have to think about the CCS "left shift" format.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12514
slahiri
Guest







Re: Pinouts 4x4 keypad
PostPosted: Mon Mar 10, 2003 10:13 pm     Reply with quote

:=:=:=:=<font face="Courier New" size=-1>I have modify the code for 4x4 keypad. Now my question is how should we lay the pin outs. My keypad is on PORTB.
:=:=:=:=</font>
:=
:=-------------------------------------------------
:=Let's assume that you connect COL0 to Port B bit 0,
:=and so on.
:=
:=The following chart will show what bitmask you should use
:=for each signal name.
:=
:=<PRE>
:=Signal Keypad 16F877 Port B bitmask
:=name pin pin bit
:=<BR>
:=COL0 1 33 0 0b00000001
:=COL1 2 34 1 0b00000010
:=COL2 3 35 2 0b00000100
:=COL3 4 36 3 0b00001000
:=ROW0 5 37 4 0b00010000
:=ROW1 6 38 5 0b00100000
:=ROW2 7 39 6 0b01000000
:=ROW3 8 40 7 0b10000000
:=<BR>
:=<BR>
:=So you would use these define statements:
:=<BR>
:=#define COL0 0b00000001
:=#define COL1 0b00000010
:=#define COL2 0b00000100
:=#define COL3 0b00001000
:=#define ROW0 0b00010000
:=#define ROW1 0b00100000
:=#define ROW2 0b01000000
:=#define ROW3 0b10000000
:=</PRE>
:=
:=I have shown the bitmasks in binary format, so that you
:=don't have to think about the CCS "left shift" format.

Thank you sir, I have learned lot thing from this forum, this is great thanks again.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12517
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