|
|
View previous topic :: View next topic |
Author |
Message |
slahiri Guest
|
Keypad 4x4 code "not working" |
Posted: Thu Mar 13, 2003 8:29 pm |
|
|
Can someone take look at my Keypad 4X4 code. My keypad is on PORTB.I am using EX_LCDKBD, for testing.
#define use_portb_kbd TRUE
#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)
//***************My Keypad New Matrix*********************************
#define COL0 0b00000001
#define COL1 0b00000010
#define COL2 0b00000100
#define COL3 0b00001000
#define ROW0 0b00010000
#define ROW1 0b00100000
#define ROW2 0b01000000
#define ROW3 0b10000000
#endif
#define ALL_ROWS (ROW0|ROW1|ROW2|ROW3)
#define ALL_PINS (ALL_ROWS|COL0|COL1|COL2|COL3)
// Keypad layout:
char const KEYS[4][4] = {{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};
#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second
void kbd_init() {
}
char kbd_getc( ) {
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;
byte kchar;
byte row;
kchar='\0';
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) {
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;
case 3 : set_tris_b(ALL_PINS&~COL3); // new CASE statement
kbd=~COL3&ALL_PINS;
break;
}
if(kbd_down) {
if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
kbd_down=false;
kchar=last_key;
last_key='\0';
}
} else {
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;
last_key =KEYS[row][col];
kbd_down = true;
} else {
++col;
col&=0x03;
//if(col==3)
//col=0;
}
}
kbd_call_count=0;
}
set_tris_kbd(ALL_PINS);
return(kchar);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12654 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Keypad 4x4 code "not working" |
Posted: Thu Mar 13, 2003 8:41 pm |
|
|
:=Can someone take look at my Keypad 4X4 code. My keypad is on PORTB.I am using EX_LCDKBD, for testing.
:=
:=void kbd_init() {
:=}
:=
------------------------------------------------------------
Change your kbd_init() function so it looks like this:
void kbd_init()
{
port_b_pullups(true);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12657 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 5:53 am |
|
|
:=:=Can someone take look at my Keypad 4X4 code. My keypad is on PORTB.I am using EX_LCDKBD, for testing.
:=:=
:=:=void kbd_init() {
:=:=}
:=:=
:=------------------------------------------------------------
:=Change your kbd_init() function so it looks like this:
:=
:=void kbd_init()
:={
:=port_b_pullups(true);
:=}
I did that, now I don't get any thing on the LCD, which I don't understand and the keypad is not working either. Before LCD was printing READY... but now I see two black lines.
void kbd_init()
{
port_b_pullups(true);
}
char kbd_getc( ) {
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;
byte kchar;
byte row;
kchar='\0';
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) {
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;
case 3 : set_tris_b(ALL_PINS&~COL3); // new CASE statement
kbd=~COL3&ALL_PINS;
break;
}
if(kbd_down) {
if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
kbd_down=false;
kchar=last_key;
last_key='\0';
}
} else {
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;
last_key =KEYS[row][col];
kbd_down = true;
} else {
++col;
col&=0x03;
//if(col==3)
//col=0;
}
}
kbd_call_count=0;
}
set_tris_kbd(ALL_PINS);
return(kchar);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12665 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 6:52 am |
|
|
:=:=:=Can someone take look at my Keypad 4X4 code. My keypad is on PORTB.I am using EX_LCDKBD, for testing.
:=:=:=
:=:=:=void kbd_init() {
:=:=:=}
:=:=:=
:=:=------------------------------------------------------------
:=:=Change your kbd_init() function so it looks like this:
:=:=
:=:=void kbd_init()
:=:={
:=:=port_b_pullups(true);
:=:=}
:=
:=
:=I did that, now I don't get any thing on the LCD, which I don't understand and the keypad is not working either. Before LCD was printing READY... but now I see two black lines.
:=
:=void kbd_init()
:={
:= port_b_pullups(true);
:=}
:=char kbd_getc( ) {
:= static byte kbd_call_count;
:= static short int kbd_down;
:= static char last_key;
:= static byte col;
:=
:= byte kchar;
:= byte row;
:=
:= kchar='\0';
:= if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) {
:= 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;
:= case 3 : set_tris_b(ALL_PINS&~COL3); // new CASE statement
:= kbd=~COL3&ALL_PINS;
:= break;
:= }
:=
:= if(kbd_down) {
:= if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
:= kbd_down=false;
:= kchar=last_key;
:= last_key='\0';
:= }
:= } else {
:= 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;
:= last_key =KEYS[row][col];
:= kbd_down = true;
:= } else {
:= ++col;
:= col&=0x03;
:= //if(col==3)
:= //col=0;
:= }
:= }
:= kbd_call_count=0;
:= }
:= set_tris_kbd(ALL_PINS);
:= return(kchar);
:=}
:=
I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
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
___________________________
This message was ported from CCS's old forum
Original Post ID: 12667 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 10:49 am |
|
|
:=
:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
------------------------------------------------------------
I'll put together a test circuit with keypad and lcd
later today and make it work. It might be near the
end of the day before I can post it.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12671 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 4:42 pm |
|
|
:=:=
:=:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
:=
:=------------------------------------------------------------
:=
:=I'll put together a test circuit with keypad and lcd
:=later today and make it work. It might be near the
:=end of the day before I can post it.
Please do, that will be great, I can learn from that and see what I am doing wrong. One more thing does this keypad needs GND.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12689 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 4:46 pm |
|
|
:=:=:=
:=:=:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
:=:=
:=:=------------------------------------------------------------
:=:=
:=:=I'll put together a test circuit with keypad and lcd
:=:=later today and make it work. It might be near the
:=:=end of the day before I can post it.
:=
:=Please do, that will be great, I can learn from that and see what I am doing wrong. One more thing does this keypad needs GND.
--------------------------------------------
The normal 3x4 or 4x4 keypad does not have a connection
to ground.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12690 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 7:38 pm |
|
|
:=:=:=:=
:=:=:=:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
:=:=:=
:=:=:=------------------------------------------------------------
:=:=:=
:=:=:=I'll put together a test circuit with keypad and lcd
:=:=:=later today and make it work. It might be near the
:=:=:=end of the day before I can post it.
:=:=
:=:=Please do, that will be great, I can learn from that and see what I am doing wrong. One more thing does this keypad needs GND.
:=--------------------------------------------
:=
:=The normal 3x4 or 4x4 keypad does not have a connection
:=to ground.
What don't understand is, when I hold my logic prob on pin1 on the keypad which is col1 and press any key in that col I don't see prob toggles between high and low.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12694 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Keypad 4x4 code "not working" |
Posted: Fri Mar 14, 2003 9:52 pm |
|
|
<font face="Courier New" size=-1>:=
:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
------------------------------------------------------
I'm still working on my test board. I'll have it ready soon.
But before we go any farther, I want to check something.
You said that as soon as Port B pull-ups were enabled,
your PIC board stopped working.
That's exactly what happens if you don't have NOLVP
at the end of your #fuses statement.
I assume you're using a 16F877, running at 5 volts.
If so, your #fuses statement should look something like this:
#fuses HS ,NOWDT, PUT, BROWNOUT, NOLVP
If your crystal is 4 MHz, then change the HS to XT,
but please make sure you have NOLVP at the end.
---</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12695 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Sat Mar 15, 2003 6:15 am |
|
|
:=<font face="Courier New" size=-1>:=
:=:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
:=------------------------------------------------------
:=
:=I'm still working on my test board. I'll have it ready soon.
:=
:=But before we go any farther, I want to check something.
:=
:=You said that as soon as Port B pull-ups were enabled,
:=your PIC board stopped working.
:=
:=That's exactly what happens if you don't have NOLVP
:=at the end of your #fuses statement.
:=
:=I assume you're using a 16F877, running at 5 volts.
:=If so, your #fuses statement should look something like this:
:=
:=#fuses HS ,NOWDT, PUT, BROWNOUT, NOLVP
:=
:=If your crystal is 4 MHz, then change the HS to XT,
:=but please make sure you have NOLVP at the end.
:=
:=
:=
:=
:=
:=
:=
:=---</font>
This is how I set it up,
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT
#use delay(clock=4000000)
a) I was able to compile my code with PortB pull-ups, I am able print Ready... on the LCD. I am testing my Keypad with EX_LCDKBD.c
b) Yes I am running 16F877 at 5V, my crystal is 4MHz, I will change HS to XT as you have mention and complie it again.
c)I have also notice some things Pin1 in the keypad is always low when I turn power on and Pin6 continue to pulse with tied low at pwr up. I am holding my logic prob to notice that. I am not sure why it is doing that. And over all thank you for helping me.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12707 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Sat Mar 15, 2003 6:54 am |
|
|
:=<font face="Courier New" size=-1>:=
:=:=I was able to print READY... on the LCD again but KEYPAD is still not working right, pin out are exactly same as what you mention earlier.
:=------------------------------------------------------
:=
:=I'm still working on my test board. I'll have it ready soon.
:=
:=But before we go any farther, I want to check something.
:=
:=You said that as soon as Port B pull-ups were enabled,
:=your PIC board stopped working.
:=
:=That's exactly what happens if you don't have NOLVP
:=at the end of your #fuses statement.
:=
:=I assume you're using a 16F877, running at 5 volts.
:=If so, your #fuses statement should look something like this:
:=
:=#fuses HS ,NOWDT, PUT, BROWNOUT, NOLVP
:=
:=If your crystal is 4 MHz, then change the HS to XT,
:=but please make sure you have NOLVP at the end.
:=
:=
:=
:=
:=
:=
:=
:=---</font>
I have change the #fuses statement as you have mention here is no change. I am getting nothing out of the Keypad.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12710 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Keypad 4x4 code "not working" |
Posted: Sun Mar 16, 2003 1:00 am |
|
|
<font face="Courier New" size=-1>:=This is how I set it up,
:=#include <16F877.h>
:=#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT
:=#use delay(clock=4000000)
:=
:=a) I was able to compile my code with PortB pull-ups, I am able print Ready... on the LCD. I am testing my Keypad with EX_LCDKBD.c
:=
:=b) Yes I am running 16F877 at 5V, my crystal is 4MHz, I will change HS to XT as you have mention and complie it again.
:=
:=c)I have also notice some things Pin1 in the keypad is always low when I turn power on and Pin6 continue to pulse with tied low at pwr up. I am holding my logic prob to notice that. I am not sure why it is doing that. And over all thank you for helping me.
----------------------------------------------------------
I just got my test board running. It uses the CCS example code.
As a test, I then modifed the #define statements to use the
"0b00000001" notation for the bitmasks. It still works.
I compared your keypad code that you posted, to the CCS code
that I used. I noticed a few changes that you did, to allow
use of 4 columns, instead of 3. Those changes look good.
So, I wonder why it doesn't work ? I searched the net, and
tried to find a data sheet for the Velleman 4x4 keypad.
I couldn't find one. I checked the website here,
<a href="http://www.velleman.be/" TARGET="_blank"> <a href="http://www.velleman.be/" TARGET="_blank">http://www.velleman.be/</a></a>
and they don't list the keypad as a separate product, and
they have no data sheets available.
I wanted to confirm the pinout of the keypad. I know that
you posted the pinout in an earlier message, but what if it's
not correct. Then the Row and Column connections won't be
correct, and the keypad might not work.
I'm trying to think of things that could cause the problem.
The description that you gave above, of strange pulses, makes
me wonder if there is a wiring error. I think you should
check all the connections carefully. Make sure you have good
+5v and ground connections, and make sure the keypad pinout
is correct.
--
I guess I have one more question. You said there are strange
pulses on one pin. Are you using the ICD debugger ?
That unit uses pins B6 and B7. You're using those pins for
the keypad. I don't think you can use them for the project
if you're using ICD.
This FAQ from the old Advanced Transdata website, has a chart
that shows B6 and B7 are always used by the ICD.
<a href="http://www.adv-transdata.com/ICD_comparison.htm" TARGET="_blank">http://www.adv-transdata.com/ICD_comparison.htm</a>
(The "serial" ICD is the one that most people have).
---
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12729 |
|
|
mehmet eryilmaz Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Sun Mar 16, 2003 8:10 am |
|
|
I also experienced the same problem.
I coudn't solve it.
And this was the reason which made me to choose another compiler (FED C) when I had to switch from 16F877 to 18F452.
My old project still doesn't work.
I would appreciate any solution.
Best Regerds
Mehmet
:=<font face="Courier New" size=-1>:=This is how I set it up,
:=:=#include <16F877.h>
:=:=#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT
:=:=#use delay(clock=4000000)
:=:=
:=:=a) I was able to compile my code with PortB pull-ups, I am able print Ready... on the LCD. I am testing my Keypad with EX_LCDKBD.c
:=:=
:=:=b) Yes I am running 16F877 at 5V, my crystal is 4MHz, I will change HS to XT as you have mention and complie it again.
:=:=
:=:=c)I have also notice some things Pin1 in the keypad is always low when I turn power on and Pin6 continue to pulse with tied low at pwr up. I am holding my logic prob to notice that. I am not sure why it is doing that. And over all thank you for helping me.
:=----------------------------------------------------------
:=
:=I just got my test board running. It uses the CCS example code.
:=As a test, I then modifed the #define statements to use the
:="0b00000001" notation for the bitmasks. It still works.
:=
:=I compared your keypad code that you posted, to the CCS code
:=that I used. I noticed a few changes that you did, to allow
:=use of 4 columns, instead of 3. Those changes look good.
:=
:=So, I wonder why it doesn't work ? I searched the net, and
:=tried to find a data sheet for the Velleman 4x4 keypad.
:=I couldn't find one. I checked the website here,
:= <a href="http://www.velleman.be/" TARGET="_blank"> <a href="http://www.velleman.be/" TARGET="_blank"> <a href="http://www.velleman.be/" TARGET="_blank">http://www.velleman.be/</a></a></a>
:=and they don't list the keypad as a separate product, and
:=they have no data sheets available.
:=I wanted to confirm the pinout of the keypad. I know that
:=you posted the pinout in an earlier message, but what if it's
:=not correct. Then the Row and Column connections won't be
:=correct, and the keypad might not work.
:=
:=I'm trying to think of things that could cause the problem.
:=The description that you gave above, of strange pulses, makes
:=me wonder if there is a wiring error. I think you should
:=check all the connections carefully. Make sure you have good
:=+5v and ground connections, and make sure the keypad pinout
:=is correct.
:=
:=--
:=
:=I guess I have one more question. You said there are strange
:=pulses on one pin. Are you using the ICD debugger ?
:=That unit uses pins B6 and B7. You're using those pins for
:=the keypad. I don't think you can use them for the project
:=if you're using ICD.
:=This FAQ from the old Advanced Transdata website, has a chart
:=that shows B6 and B7 are always used by the ICD.
:= <a href="http://www.adv-transdata.com/ICD_comparison.htm" TARGET="_blank"> <a href="http://www.adv-transdata.com/ICD_comparison.htm" TARGET="_blank">http://www.adv-transdata.com/ICD_comparison.htm</a></a>
:=(The "serial" ICD is the one that most people have).
:=
:=
:=
:=
:=
:=---
:=</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12735 |
|
|
slahiri Guest
|
Re: Keypad 4x4 code "not working" |
Posted: Sun Mar 16, 2003 8:13 am |
|
|
:=<font face="Courier New" size=-1>:=This is how I set it up,
:=:=#include <16F877.h>
:=:=#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT
:=:=#use delay(clock=4000000)
:=:=
:=:=a) I was able to compile my code with PortB pull-ups, I am able print Ready... on the LCD. I am testing my Keypad with EX_LCDKBD.c
:=:=
:=:=b) Yes I am running 16F877 at 5V, my crystal is 4MHz, I will change HS to XT as you have mention and complie it again.
:=:=
:=:=c)I have also notice some things Pin1 in the keypad is always low when I turn power on and Pin6 continue to pulse with tied low at pwr up. I am holding my logic prob to notice that. I am not sure why it is doing that. And over all thank you for helping me.
:=----------------------------------------------------------
:=
:=I just got my test board running. It uses the CCS example code.
:=As a test, I then modifed the #define statements to use the
:="0b00000001" notation for the bitmasks. It still works.
:=
:=I compared your keypad code that you posted, to the CCS code
:=that I used. I noticed a few changes that you did, to allow
:=use of 4 columns, instead of 3. Those changes look good.
:=
:=So, I wonder why it doesn't work ? I searched the net, and
:=tried to find a data sheet for the Velleman 4x4 keypad.
:=I couldn't find one. I checked the website here,
:= <a href="http://www.velleman.be/" TARGET="_blank"> <a href="http://www.velleman.be/" TARGET="_blank"> <a href="http://www.velleman.be/" TARGET="_blank">http://www.velleman.be/</a></a></a>
:=and they don't list the keypad as a separate product, and
:=they have no data sheets available.
:=I wanted to confirm the pinout of the keypad. I know that
:=you posted the pinout in an earlier message, but what if it's
:=not correct. Then the Row and Column connections won't be
:=correct, and the keypad might not work.
:=
:=I'm trying to think of things that could cause the problem.
:=The description that you gave above, of strange pulses, makes
:=me wonder if there is a wiring error. I think you should
:=check all the connections carefully. Make sure you have good
:=+5v and ground connections, and make sure the keypad pinout
:=is correct.
:=
:=--
:=
:=I guess I have one more question. You said there are strange
:=pulses on one pin. Are you using the ICD debugger ?
:=That unit uses pins B6 and B7. You're using those pins for
:=the keypad. I don't think you can use them for the project
:=if you're using ICD.
:=This FAQ from the old Advanced Transdata website, has a chart
:=that shows B6 and B7 are always used by the ICD.
:= <a href="http://www.adv-transdata.com/ICD_comparison.htm" TARGET="_blank"> <a href="http://www.adv-transdata.com/ICD_comparison.htm" TARGET="_blank">http://www.adv-transdata.com/ICD_comparison.htm</a></a>
:=(The "serial" ICD is the one that most people have).
:=
:=
:=
:=
:=
:=---
:=</font>
I am not using ICD debugger. I found Velleman 16 keyPad pin out and they are correct. I was wondering if you run my code with your test circuit and see if you could get it to work, or if you could post code or email me your code so that I can take look at. I have check my connection they looks good to me. I will keep trouble shooting this, I don't know what else to do. I appreciate your help.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12736 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Keypad 4x4 code "not working" |
Posted: Sun Mar 16, 2003 4:08 pm |
|
|
:=if you could post code or email me your code so that I can take look at.
-------------------------------------------------------------
I'll just post the code. I don't know what else to do.
The following code is nearly the same as the CCS example
code, except I removed all the excess comments at the
top of the files. I changed one or two things, such
as the LCD init. But those changes are noted in the files.
I only have a 12 key keypad, so I don't have a COL3.
<PRE>
// EX_LCDKB.C
<BR>
#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600,xmit=PIN_C6, rcv=PIN_C7, errors)
<BR>
#include "lcd.c"
#include "kbd.c"
<BR>
//----------------------
main()
{
char k;
<BR>
lcd_init();
kbd_init();
<BR>
lcd_putc("\fReady !\n");
<BR>
while (TRUE) {
k=kbd_getc();
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
}
}
<BR>
//==============================================
<BR>
// LCD.C
<BR>
// The pin connection from Port D to the LCD is as follows:
//
// D0 enable
// D1 rs
// D2 rw
// D4 D4
// D5 D5
// D6 D6
// D7 D7
//
// LCD pins D0-D3 are not used and PIC pin D3 is not used.
<BR>
struct lcd_pin_map
{
boolean enable;
boolean rs;
boolean rw;
boolean unused;
int data : 4;
} lcd;
<BR>
#byte lcd = 8 // Assign the above structure to Port D
<BR>
#define set_tris_lcd(x) set_tris_d(x)
<BR>
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
<BR>
#define lcd_line_two 0x40 // LCD RAM address for the second line
<BR>
// These bytes need to be sent to the LCD to start it up.
byte CONST LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// The following structures are used for setting
// the I/O port direction register.
<BR>
// For write mode all pins are outputs.
STRUCT lcd_pin_map const LCD_WRITE = {0,0,0,0,0};
<BR>
// For read mode data pins are inputs.
STRUCT lcd_pin_map const LCD_READ = {0,0,0,0,15};
<BR>
byte lcd_read_byte() {
byte low,high;
set_tris_lcd(LCD_READ);
lcd.rw = 1;
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}
void lcd_send_nibble( byte n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
<BR>
void lcd_send_byte( byte address, byte n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
lcd.rw = 0;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
<BR>
void lcd_init() {
byte i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
<BR>
// Note:
// My LCD did not work if the last byte in the init
// table was sent to it (last byte = 0x06). So I changed
// the count in the for() statement, so it would only
// send the first 3 bytes in the init table.
<BR>
for(i=0;i<=2;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
<BR>
void lcd_gotoxy( byte x, byte y) {
byte address;
<BR>
if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
<BR>
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}
<BR>
char lcd_getc( byte x, byte y) {
char value;
<BR>
lcd_gotoxy(x,y);
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
<BR>
//=====================================================
// KBD.C
<BR>
#byte kbd = 6 // on to port B (at address 6)
<BR>
#define set_tris_kbd(x) set_tris_b(x)
<BR>
/*
#define COL0 (1 << 0)
#define COL1 (1 << 1)
#define COL2 (1 << 2)
#define ROW0 (1 << 4)
#define ROW1 (1 << 5)
#define ROW2 (1 << 6)
#define ROW3 (1 << 7)
*/
// The following bitmasks are the same as the above,
// but written in a different format.
#define COL0 0b00000001
#define COL1 0b00000010
#define COL2 0b00000100
// Note: My keypad is only 12 keys, so it doesn't
// have a COL3 pin.
#define ROW0 0b00010000
#define ROW1 0b00100000
#define ROW2 0b01000000
#define ROW3 0b10000000
<BR>
<BR>
#define ALL_ROWS (ROW0|ROW1|ROW2|ROW3)
#define ALL_PINS (ALL_ROWS|COL0|COL1|COL2)
<BR>
// Keypad layout:
char const KEYS[4][3] = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
<BR>
// Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second
#define KBD_DEBOUNCE_FACTOR 33
<BR>
void kbd_init()
{
port_b_pullups(TRUE);
}
<BR>
char kbd_getc( ) {
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;
<BR>
byte kchar;
byte row;
kchar='\0';
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) {
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;
}
<BR>
if(kbd_down) {
if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
kbd_down=false;
kchar=last_key;
last_key='\0';
}
} else {
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;
last_key =KEYS[row][col];
kbd_down = true;
} else {
++col;
if(col==3)
col=0;
}
}
kbd_call_count=0;
}
set_tris_kbd(ALL_PINS);
return(kchar);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12750 |
|
|
|
|
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
|