View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
keypad lock and unlock |
Posted: Sat Jul 12, 2008 1:40 pm |
|
|
Hi
I would like know how I can make one program with keypad where I put for example number "1" and it active an relay but if I press key number "1" for second time it deactivate same relay.
I have this code...but this only active ".... OFF" if I give one signal on PIN_C3:
I like active or deactivate all with keypad.
Code: |
void card()
{
int8 c, ctemp;
int a;
a=input(PIN_C3);
do
{
c = kbd_getc();
if ((c=='0') || (c=='1') || (c=='2') || (c=='3') || (c=='4') || (c=='5') || (c=='6') || (c=='7') || (c=='8') || (c=='9'))
ctemp=c;
if(c!=0) {
lcd_gotoxy(6,3);
lcd_putc(ctemp);
}
}while(c!='#');
lcd_gotoxy(1,3);
if (ctemp=='1')
{
if (a==0) lcd_putc("PC_ON ");
if (a==1) lcd_putc("PC_OFF ");
}
if (ctemp=='2')
{
if (a==0) lcd_putc("INVERSOR ON ");
if (a==1) lcd_putc("INVERSOR OFF ");
}
}
void main ()
{
int8 c;
lcd_init();
kbd_init();
while(TRUE)
{
c = kbd_getc();
if(c!=0)
if((c=='*') || (c=='#'))
{
if(c=='*')
{
lcd_gotoxy(1,3);
lcd_putc("Insert key: ");
ast();
}
if(c=='#')
{
lcd_gotoxy(1,3);
lcd_putc("code: ");
card();
}
}
}
}
|
best regards |
|
![](templates/subSilver/images/spacer.gif) |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sun Jul 13, 2008 4:17 am |
|
|
some one can help for make one program where I dont need switch on PIN_C3 for change for example "PC_ON" to "PC_OFF"
best regards |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 13, 2008 2:57 pm |
|
|
Create a variable (int8) and call it 'relay_state'. Initialize it to 'FALSE':
Code: | int8 relay_state = FALSE; |
Then, when the '1' key is pressed, toggle the 'relay_state' variable
to the opposite state:
Code: | relay_state = !relay_state; |
Immediately after doing that, set the relay to the same state as
the 'relay_state' variable:
Code: | if(relay_state)
output_high(RELAY_PIN); // Relay = on
else
output_low(RELAY_PIN); // Relay = off |
|
|
![](templates/subSilver/images/spacer.gif) |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Oct 01, 2008 3:03 am |
|
|
hi,
is possible put 2 keypads in parallel connected to the pic for we can insert code in two diferents places? or I need use two PICs?
best regards, filipe abrantes |
|
![](templates/subSilver/images/spacer.gif) |
|