View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Mon Jun 23, 2008 11:51 am |
|
|
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
|
|
Posted: Mon Jun 23, 2008 12:01 pm |
|
|
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
|
|
Posted: Mon Jun 23, 2008 12:33 pm |
|
|
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 regards |
|
|
darren
Joined: 08 Jul 2008 Posts: 4
|
|
Posted: Wed Jul 09, 2008 9:57 pm |
|
|
#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
|
|
Posted: Wed Jul 09, 2008 10:58 pm |
|
|
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
|
|
Posted: Wed Jul 09, 2008 11:44 pm |
|
|
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 |
|
|
|