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

keypad lock and unlock

 
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

keypad lock and unlock
PostPosted: Sat Jul 12, 2008 1:40 pm     Reply with quote

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
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sun Jul 13, 2008 4:17 am     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 13, 2008 2:57 pm     Reply with quote

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
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Oct 01, 2008 3:03 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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