View previous topic :: View next topic |
Author |
Message |
sadlpx
Joined: 19 Feb 2004 Posts: 23
|
kbd.c and Lab-x1 |
Posted: Mon Aug 29, 2005 7:45 am |
|
|
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
|
|
Posted: Mon Aug 29, 2005 7:47 am |
|
|
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: 1909
|
|
|
sadlpx
Joined: 19 Feb 2004 Posts: 23
|
|
Posted: Mon Aug 29, 2005 10:34 am |
|
|
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: 1909
|
|
Posted: Mon Aug 29, 2005 10:57 am |
|
|
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). |
|
|
|