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

Problem with 4x4 Keypad Scan (Without Pull-up)
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 11:51 am     Reply with quote

Hi

I'm a filjo and I write before reply what type is my keypad.

I try make this simple program for write on terminal numbers how I press on keypad but on terminal I only see "number:"

Quote:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=115200, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)

#include "filjoaKBD.C"

void main ()
{
int8 c;

while(1)
{
printf("number: ");
kbd_init();
c = kbd_getc();
fputc(c);
delay_ms(1000);
printf("\n\r");

}
}


some one can help me?

best regards, filipe Abrantes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 12:01 pm     Reply with quote

Look at the Ex_lcdkb.c file It shows how to call the keypad driver
functions, and how to check if a key has been pressed. You must
do it by method shown in this file:
Quote:
c:\Program Files\Picc\Examples\Ex_lcdkb.c
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Mon Jun 23, 2008 12:33 pm     Reply with quote

Hi
thanks

I make that:

Code:

void main ()
{
   int8 c;

kbd_init();

while(TRUE)
   {
   
   c = kbd_getc();
   if (c!=0)
      if(c=='*')
         putc('\r');
      else
         putc(c);
   
   }
}


now it work Wink regards
darren



Joined: 08 Jul 2008
Posts: 4

View user's profile Send private message

PostPosted: Wed Jul 09, 2008 9:57 pm     Reply with quote

#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)

#endif

#define ALL_ROWS (row0|row1|row2|row3)
#define ALL_PINS (ALL_ROWS|col0|col1|col2)
//keypad connection
#define row0 PIN_B0
#define row1 PIN_B1
#define row2 PIN_B2
#define row3 PIN_B3
#define col0 PIN_B4
#define col1 PIN_B5
#define col2 PIN_B6
// Keypad layout:
char const KEYS[4][3] = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};

#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() {
set_tris_b(0xF0);
port_b_pullups(TRUE);
}

short int ALL_ROWS(void)
{
if (input(row0)&input(row1)&input(row2)&input(row3))
return (0);
else
return (1);
}

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 : output_low(col0);
output_low(col1);
output_high(col2);
break;
case 1 : output_low(col0);
output_high(col1);
output_low(col2);
break;
case 2 : output_high(col0);
output_low(col1);
output_low(col2);
break;
case 3 : output_high(col0);
output_high(col1);
output_high(col2);
break;
case 4 : output_low(col0);
output_low(col1);
output_low(col2);

}

if(kbd_down) {
if(!ALL_ROWS()) {
kbd_down=FALSE;
kchar=last_key;
last_key='\0';
}
} else {
if(ALL_ROWS()) {
if(!input(row0))
row=0;
else if(!input(row1))
row=1;
else if(!input(row2))
row=2;
else if(!input(row3))
row=3;
last_key =KEYS[row][col];
kbd_down = TRUE;
}
else {
++col;
if(col==3)
col=0;
}
}
kbd_call_count=0;
}

return(kchar);
}

hi i'm also using keypad but mine is in 4x3 matrix keypad
I'm trying to use your programme but it doesn't work
the errors are: Expecting *
Expecting a declaration
Expecting close paren
A numeric expression must appear here..

please help me :-'(
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 09, 2008 10:58 pm     Reply with quote

This forum is supposed to be above the beginner level.
At your level, you can't even compile a program.

If we turn this forum into a beginner forum, where we answer
questions such as "help, where do I put a semi-colon ?" or
"help, where's my missing brace ?", then the "pros" begin to
get disgusted and they leave the forum. This has already
happened somewhat, over the last several months.

We don't want it to get worse.
You must learn C on another forum or take a class, or read a book.
We can't teach bonehead C on this forum and still have the forum
be worthwhile.
darren



Joined: 08 Jul 2008
Posts: 4

View user's profile Send private message

PostPosted: Wed Jul 09, 2008 11:44 pm     Reply with quote

it's ok.
I can't find any error that is made in my code so I only come here and search for the help.
Thanks for the reply
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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