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

velleman 16 keys keyboard - matrix type 4x4

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







velleman 16 keys keyboard - matrix type 4x4
PostPosted: Thu Jun 17, 2004 9:29 pm     Reply with quote

I have a this keypad and managed to get the keyboard working with the following codes, however I am not able to get the 4th column. ie A,B,C,D

Hope someone can help Rolling Eyes


#byte kbd = 0xF81 // This puts the entire structure


#define set_tris_kbd(x) set_tris_b(x)



//Keypad connection: (for example column 0 is B2)
// Bx:


#define COL0 (1 << 0) //1
#define COL1 (1 << 1) //10
#define COL2 (1 << 2) //100
#define COL3 (1 << 3) //1000

#define ROW0 (1 << 4) //10000
#define ROW1 (1 << 5) //100000
#define ROW2 (1 << 6) //1000000
#define ROW3 (1 << 7) //10000000

// The following bitmasks are the same as the above,

// but written in a different format.




#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 22 // 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() {
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_kbd(ALL_PINS&~COL3);
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;
if(col==4)
col=0;
}
}
kbd_call_count=0;
}
set_tris_kbd(ALL_PINS);
return(kchar);
}
Guest








PostPosted: Thu Jun 17, 2004 10:11 pm     Reply with quote

Have you checked with an oscilloscope or meter that the corresponding row goes low on this column when key pressed? The column may not be connected.
Cloud
Guest







PostPosted: Tue Jun 22, 2004 7:43 pm     Reply with quote

Very Happy Very Happy

You are right.

Thanks. The code is okay.
Guest
Guest







PostPosted: Thu Nov 18, 2004 6:36 am     Reply with quote

I´ve tried to use this code with the ex_lcdkb.c included with the compiler, and it doesn´t work. I´ve changed the portb_pullups as I thought it could be the reason, but still doesn´t work. The LCD displays Ready... all the time!.

I´m using a 16f877 at 4Mhz, the lcd in port D and a 4x4 keypad on port B, know why can this be?

Thanx.
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