|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
help with keypad change |
Posted: Mon Dec 11, 2006 2:46 pm |
|
|
Hi PCM & All
I need your help to modify the Flexible Keypad Driver to work as follows
when you pressed a key for the character to be displayed instead of how it works now where when you press a key the character is only displaced when you release your finger from the switch.
I know its a stupid request its only that when i was given this task to do the user just want to press a switch then activity takes place only for me to find out that they ony want to use 3 switches SW1,SW2 & SW3 as just normally open contacts were when the contacts is closed then activity takes place .
( Note i have not got access to the hardware if not i would have just made some hardware changes like putting 3 pull-down resistors on 3 port pins
then use his contact to pull the voltage up to +5v but i can do that as
i am not allowed to make any hardware changes.
Please Help
Amina
so please i need some help from you
I AM USING THE EXAMPLE BELOW
Code: |
Code:
//=============================
//Keypad connection:
#define row0 PIN_B4
#define row1 PIN_B5
#define row2 PIN_B6
#define row3 PIN_B7
#define col0 PIN_B0
#define col1 PIN_B1
#define col2 PIN_B2
#define col3 PIN_B3
// 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()
{
//set_tris_b(0xF0);
//output_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_high(col1);
output_high(col2);
output_high(col3);
break;
case 1:
output_high(col0);
output_low(col1);
output_high(col2);
output_high(col3);
break;
case 2:
output_high(col0);
output_high(col1);
output_low(col2);
output_high(col3);
break;
case 3:
output_high(col0);
output_high(col1);
output_high(col2);
output_low(col3);
break;
}
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==4)
col=0;
}
}
kbd_call_count=0;
}
return(kchar);
}
//===========================
void main()
{
char k;
kbd_init();
printf("\r\Starting ...");
while(TRUE)
{
k=kbd_getc();
if(k!=0)
{
if(k=='*')
printf("%c", '*');
else
printf("%c", k);
if (k=='1')
{
Do sw1;
}
if (k=='2')
{
Do sw2;
}
if (k=='3')
{
Do sw3;
}
}
}
}
|
|
|
|
BOB_SANTANA
Joined: 16 Oct 2006 Posts: 110 Location: HOVE, EAST SUSSEX
|
|
Posted: Tue Dec 12, 2006 4:51 pm |
|
|
Hi Amina
If you only want to use just SW1 -Sw3
you can do it without portb change interupt
you can something like this
1. Enable PORTB pull-ups
2. Set PORTB lines low to read buttons
3. Set TRISB to 0xf0 ' Enable all buttons
Code: |
while (1)
{
' Then just Check any button pressed
If (! input(PIN_B4) //sw1
{
delay_ms(50); // debounce
If (! input(PIN_B4) //sw1
{
DO SW1;
}
}
If (! input(PIN_B5) //sw2
{
delay_ms(50); // debounce
If (! input(PIN_B5) //sw2
{
DO SW2;
}
}
If (! input(PIN_B6) //sw3
{
delay_ms(50); // debounce
If (! input(PIN_B8) //sw3
{
DO SW3;
}
}
}
| _________________ BOB_Santana |
|
|
Guest
|
|
Posted: Wed Dec 13, 2006 9:54 am |
|
|
Thanks Bob
I didn't think it would work but its working
Amina |
|
|
|
|
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
|