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

kbd.c and Lab-x1

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



Joined: 19 Feb 2004
Posts: 23

View user's profile Send private message

kbd.c and Lab-x1
PostPosted: Mon Aug 29, 2005 7:45 am     Reply with quote

I have the LCD working on the MELABS lab-x1 board. Now I'm trying to make the kbd.c work. No luck i keep runnign into a wall (forehead getting sore).

I've modified the have bits to match the schematic

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

#define COL0 (1 << 4)
#define COL1 (1 << 5)
#define COL2 (1 << 6)

I'm using the pcw version 3.216

I've left the
#byte kbd = 6
and use
#define set_tris_kbd(x) set_tris_b(x)

all of which I "think" are right.

Since i've looked through so many posts i'm assuing that my problems are hardware related. The Lab-X1 schematic is:

http://www.melabs.com/downloads/labx1sch.pdf

I've tried 10K pullups on B0 and B1 with no luck

also having toruble understanding what this really means:

case 0 : set_tris_d(ALL_PINS&~COL0);
kbd=~COL0&ALL_PINS;
break;

I do understand that line one is setting the outout bits and line two is reading the bport. Guess the (~) is throwing me.

I also understanad the B3, b5 and B7 are used byt he ICDU but that should allow me access to col 0 and Col 1 for themost part.

Any help would be appreaciated.
sadlpx



Joined: 19 Feb 2004
Posts: 23

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 7:47 am     Reply with quote

I have changed

case 0 : set_tris_d(ALL_PINS&~COL0);
to
case 0 : set_tris_kbd(ALL_PINS&~COL0);
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 9:33 am     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=19726

It might be a little "high powered", but it works very well. And it was developed on the Lab-X1 board too.
sadlpx



Joined: 19 Feb 2004
Posts: 23

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 10:34 am     Reply with quote

newguy in your code the opening line is #byte portb = 0xf81
can you help me understand why this is a larger value than one 0xff and what your trying to accomplish.
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Mon Aug 29, 2005 10:57 am     Reply with quote

0xF81 is the address of port b in the pic's memory (the special function registers, or SFRs). This information is found in the pic's data sheet. Look in the memory organization section.

The code uses the "interrupt on change" port b interrupt (int_RB) to detect a button press. In order to do this, the upper 4 bits of port b have to be set to input, with the pullups enabled. The lower 4 bits have to be set to output a low (0). When one of the 16 buttons is pressed, one of the lower 4 bits of port b will be connected to one of the upper 4 bits of port b, which will pull one of these upper bits low, creating a change, which triggers the interrupt. Once the interrupt happens, you have to scan the keypad to see what happened/which key was pressed.

Instead of reading/writing to port b using CCS' built-in functions, I simply create a "shortcut" to port b using the #byte command you asked about. I can then write to port b/read from it just by saying "something = portb" (read) or "portb = something" (write).
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