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

ACE KIT Excercise EX20.c which uses the keypad and the lcd.

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



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

ACE KIT Excercise EX20.c which uses the keypad and the lcd.
PostPosted: Sun Sep 18, 2005 5:14 pm     Reply with quote

I have read all (well maybe not all) the comments regarding the lcd and keypad from other users, but no one seems to be using the ACE KIT. I have gone through many of the excercises but this one has me stymied.
The keypad connector is connected to Port D and the lcd is connected to the port D LCD header as instructed in the documentation. The lcd lights but there is nothing displayed.
Other posts have mentioned the need for pullup resistors but in this excercise the lcd is providing that requirement.
If anyone has gone through this successfully please send me a tip or two.
I have a little concern since the excercise document appears to not be in its final configuration. Mine has several of the Figures blacked out, so I am wondering if it is going to have another pass through the editing process.

Thanks,
JimB

The code follows;

#include <16f877A.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock=20000000)

#include <lcd.c>
#include <kbd.c>

void main() {
char k;

lcd_init();
kbd_init();

lcd_putc("\fReady....\n");

while (TRUE) {
k=kbd_getc();
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 18, 2005 6:02 pm     Reply with quote

Quote:
but no one seems to be using the ACE KIT.

CCS doesn't post the manuals or the schematics for any of this stuff,
(unlike Microchip, who does post them) so it's tough for us to provide
any support.
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Mon Sep 19, 2005 7:27 am     Reply with quote

As I recall, the LCD port in the ACE kit works fine "out of the box". There are two possible places where you can plug it it, port B, or port D. If you use the keypad as well, you must use port B. Make sure the driver file is talking to the correct port.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Statement in the kbd.c
PostPosted: Mon Sep 19, 2005 7:47 pm     Reply with quote

After looking around here, the forum, for similar problems, I read the kbd.c and found the statement about needing pullup resistors on the keypad unless the lcd is attached. See next two lines taken directly from the kbd.c file.

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

So from this statement I am led to believe that having the keypad and the lcd on the same port was intentional. I will try moving it to the B port and see what happens.
I hope that CCS didn't make a mistake regarding this. I know that they sometimes leave out little tidbits of information.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

PostPosted: Mon Sep 19, 2005 11:39 pm     Reply with quote

Moved the lcd to port B and removed comment lines to enable use of port B for the lcd. Added the three pullup resistors to the column lines.
Still no go. Anybody have ideas. I am basically parroting the excercise given.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 12:28 am     Reply with quote

That comment in the CCS example file is in error. The pull-up
resistors must be on the ROW pins for the kbd.c file.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Comments from CCS
PostPosted: Tue Sep 20, 2005 10:34 pm     Reply with quote

I asked CCS support about the problems I was having. Here is the reply that was sent.

*************************************************
"You need pull-ups (or LCD) on COL0, COL1, COL2 (D5-D7)."

"To read the keypad the software will set ROW0 to low, and ROW1,ROW2 and ROW3 to high.
If COL0-COL3 all read high then no key in ROW0 is pressed. The software then sets ROW1
low and the others HIGH. Again if COL0-COL3 are all high nothing is pressed in that row. If
one of the COLx pins reads low then that column and the row that is now low will indicate
the key that is pressed. The software rotates through all rows and then repeats."

AND

"With this kit use port D for both the keypad and LCD. The POT #10
is used to adjust the LCD contrast. From your description I think the
contrast is not set right. On power up you should see a row of black
boxes, when lcd_init is called the screen should clear. You should
then see the text from the printf even before you press any keys."

****************************************************
There was no mention of the pot in the exercise so I need to pursue that avenue now. At least they gave an explanation of how the keypad is read. Now I wish someone would go through the kbd.c and lcd.c and give a narrative explaining what is going on in these two files. Being a beginner I find much of what is presented a little cryptic. It is hard for me to separate the C functions from the other expressions much of the time.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 21, 2005 12:26 am     Reply with quote

Quote:
"You need pull-ups (or LCD) on COL0, COL1, COL2 (D5-D7)."
"To read the keypad the software will set ROW0 to low, and ROW1,ROW2
and ROW3 to high. If COL0-COL3 all read high then no key in ROW0 is
pressed. The software then sets ROW1 low and the others HIGH. Again if
COL0-COL3 are all high nothing is pressed in that row. If one of the COLx
pins reads low then that column and the row that is now low will indicate
the key that is pressed. The software rotates through all rows and then
repeats."


Maybe they're looking at a different driver file than me. They have given
a description that is the exact opposite of the way that KBD.C works,
in terms of the Row and Column pins. The KBD.C driver file in
c:\Program Files\Picc\Drivers sets the column lines low, one at a time,
and reads the rows.

The following code is from the kbd_getc() routine. I've added comments
to show what the bitmasks are.

If you look at the kdb_getc() code in KBD.C, you can see that the
column variable "col" is incremented down at the bottom of the routine.
Each time you call it, "col" will cycle through one of the values
of 0, 1, and 2. So, each time you call kbd_getc(), a different "case"
in the switch statement is performed. Notice what they do.
The value "kbd" is equivalent to Port D. They take the inverted
form of the column bitmask, AND it with ALL_PINS, and shove
it out to Port D. They are setting one Column line low, in
sequence, each time they call kbd_getc().

Code:

#define COL0 (1 << 5)   //  = 00100000b
#define COL1 (1 << 6)   //  = 01000000b
#define COL2 (1 << 7)   //  = 10000000b

// The inverted forms of the column bitmasks are:
// ~COL0 = 11011111b
// ~COL1 = 10111111b
// ~COL2 = 01111111b

// ALL_PINS = 11111110b

#byte kbd = 8     

switch (col) {
         case 0   : set_tris_kbd(ALL_PINS&~COL0);
                    kbd=~COL0&ALL_PINS;
                    break;
         case 1   : set_tris_kbd(ALL_PINS&~COL1);
                    kbd=~COL1&ALL_PINS;
                    break;
         case 2   : set_tris_kbd(ALL_PINS&~COL2);
                    kbd=~COL2&ALL_PINS;
                    break;
       }


Here is the row code from KBD.C. Notice that they take
the value of kbd (that is, they read Port D), and they mask
it down with the bitmask of the Row that they want to test.
Since once each pass, a Column line is held low, if a button
is pushed, a connection will be made between that Column
line and a Row line. When they read the Row pins, and
mask it down to a particular row, and if the result is zero,
then they know the column and the row of the button that's
been pushed.

For this to work, the Row pins must have pull-ups on them.
If they're floating, you can't be sure of the bit values
that are read.

Example:
Suppose the button for COL2 and ROW3 is pressed. Let's
assume we're on the 3rd call to kbd_getc() from your main
routine. Then the line for Column 2 will be set low.
First they read kbd (Port D), and mask it down with ALL_ROWS
to see if any Row line is low. If one is low, then they
check to see which specific Row it is. They do this with
a series of if-else statements, below.

When you use the value of "kbd" below, you have read
the whole of Port D. You've read both the Row pins
and the Column pins. But, the code is only testing
the value of the Row pins, because it's using bitmasks
for the Row pins. This is why the Row pins, as inputs,
must have pull-up resistors on them. Otherwise they'd
be floating and you could read any random value. Without
a pull-up, you might read a low value on a Row pin even
though a button wasn't pushed on that row.
Code:

#define ROW0 (1 << 1)   // = 00000010b
#define ROW1 (1 << 2)   // = 00000100b
#define ROW2 (1 << 3)   // = 00001000b
#define ROW3 (1 << 4)   // = 00010000b

      if((kbd & (ALL_ROWS))!=(ALL_ROWS)) {
             if((kbd & ROW0)==0)
               row=0;
             else if((kbd & ROW1)==0)
               row=1;
             else if((kbd & ROW2)==0)
               row=2;
             else if((kbd & ROW3)==0)
               row=3;
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

PostPosted: Sat Sep 24, 2005 3:09 am     Reply with quote

I reviewed the great reply from PCM Programmer and learned a great deal from that reply. However, I did get the keyboard and lcd to work as CCS advertised in their exercise, i.e. I got them to work correctly placing the lcd and the keypad on port D, without any pullups. What is a little confusing is that without the program running I measured the voltages on the port D pins and found the following.
D0 - low, D1 - +5V, D2 - +5V, D3 - low, D4 - low, D5 - +5V, D6 - low, and D7 - low. The same hold when the program is loaded but no keypad buttons pushed. This implies that two rows and one column is pulled up by the lcd??????
Where is the book that explains all this stuff in detail. Seems like this forum and all the code displayed is becoming my best instructor.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 24, 2005 11:41 am     Reply with quote

Download the specification for the controller chip used on many
characters LCDs:
http://www.melabs.com/downloads/hd44780u.pdf
Go to page 54, which shows a schematic of the input circuits.
Notice that signals DB0-DB7, R/W, and RS, are labeled with "pull up MOS".
This means they are using a MOSFET to create a weak pullup on those pins.
On page 48, they say the typical pull-up current is 50ua at 3v.
This means the pullups are typically 60K ohms.


While I was searching for the LCD driver document above, I also
found a good appnote from Maxim on keypad interfacing.
http://www.maxim-ic.com/appnotes.cfm/appnote_number/3414
It can also be downloaded as a PDF, at the bottom of the page.
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