 |
 |
| View previous topic :: View next topic |
| Author |
Message |
peachgirl Guest
|
|
Posted: Thu Jun 14, 2007 10:40 am |
|
|
| ???? |
|
 |
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Fri Jun 15, 2007 12:51 am |
|
|
Hello peachgirl,
Can you still have patience a few hours because I must cable a keyboard to test the program. It is now 9h and I do that at the beginning of afternoon.
Best regards,
dro. _________________ in médio virtus |
|
 |
peachgirl Guest
|
|
Posted: Fri Jun 15, 2007 1:07 am |
|
|
je suis émue...
thanks |
|
 |
inservi
Joined: 13 May 2007 Posts: 128
|
|
Posted: Fri Jun 15, 2007 9:04 am |
|
|
Hello,
here is the code KBDDT.C : | Code: |
#if defined(__PCH__)
#if defined use_portb_kbd
#byte kbd = 0xF81 // This puts the entire structure 0xF81 est l'adress de PORTB
#else
#byte kbd = 0xF83 // This puts the entire structure 0xF83 est l'adress de PORTD
#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
#define set_tris_kbd(x) set_tris_b(x)
//Keypad connection: (for example column 0 is B5)
// Bx:
#define COL0 (1 << 4)
#define COL1 (1 << 5)
#define COL2 (1 << 6)
#define COL3 (1 << 7)
#define ROW0 (1 << 3)
#define ROW1 (1 << 2)
#define ROW2 (1 << 1)
#define ROW3 (1 << 0)
#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','+'},
{'4','5','6','-'},
{'7','8','9','!'},
{'*','0','#','$'}};
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 == 0 ) {
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)) {
timePushed = ( (int16)sec * initSec ) + ( initSec - Sec100 ) ;
kbd_down=FALSE;
kchar=last_key;
last_key='\0';
kbd_call_count = initDebounce ;
}
}
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;
sec = 0 ;
sec100 = initSec;
kbd_call_count = initDebounce ;
} else {
++col;
if(col==4)
col=0;
}
}
}
set_tris_kbd(ALL_PINS);
return(kchar);
} |
and how to use it : | Code: |
...
#use delay(clock=20000000)
...
#define use_portb_kbd true
#define initSec 100
#define initDebounce 5 // 50mSec if interrupt is .. 10 ms at 20Mhz
char kbd_call_count;
short int kbd_down;
int16 timePushed = 0 ; // time pushed by 100em seconds
#define initSec 100
int8 sec100 = initSec ;
int8 sec = 0 ;
#include <kbdd.c>
#int_TIMER2
void TIMER2_isr(void) { // 10ms at 20Mhz
if ( kbd_call_count != 0 ) --kbd_call_count ; // efficient way to debounce
if ( kbd_down ) {
if ( --Sec100 == 0 ) {
sec100 = initSec ;
++sec ;
}
}
}
int8 getvalue() {
int8 value=0;
do {
value = kbd_getc(); // the function of the KBBD.C
}while( value == 0 ) ;
return ( value ) ;
}
void main()
{
char v1;
...
setup_timer_0(RTCC_INTERNAL);
//setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); // 13 ms at 20Mhz
setup_timer_2(T2_DIV_BY_16,196,16); // 10 ms at 20 Mhz
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
port_b_pullups (true);
while(true){
v1 = getvalue() ;
printf("Char %c Tp %Lu ", v1, timePushed );
}
} |
With 1/100 em sec resolution. The minimum time measurable is the debounce time. You can try with about 30mSec ( by changing 'initDebounce ' value ) for debounce depending on the quality of the switch. I chacked it and it look to working well.
Best regards,
dro. _________________ in médio virtus |
|
 |
peachgirl Guest
|
|
Posted: Mon Jun 18, 2007 1:44 am |
|
|
Thank you very much!
The program you posted is working.
Now, I'm trying to use it to do what I want......i hope I could receive, thanks.... |
|
 |
|
|
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
|