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

How can i make here an subroutine to reduce code size?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

How can i make here an subroutine to reduce code size?
PostPosted: Mon Feb 27, 2006 7:35 am     Reply with quote

Code:
   while(TRUE) {
      k=kbd_getc();
      switch(k) {
         case '1' :   if(toggle1)
                        output_low(RELAIS_K1);
                     else
                        output_high(RELAIS_K1);
                        toggle1 =! toggle1;
                        break;
         case '2' :   if(toggle2)
                        output_low(RELAIS_K2);
                     else
                        output_high(RELAIS_K2);
                        toggle2 =! toggle2;
                        break;
         case '3' :   if(toggle3)
                        output_low(RELAIS_K3);
                     else
                        output_high(RELAIS_K3);
                        toggle3 =! toggle3;
                        break;
         case '4' :   if(toggle4)
                        output_low(RELAIS_K4);
                     else
                        output_high(RELAIS_K4);
                        toggle4 =! toggle4;
                        break;
      }
   }
}

Alex N



Joined: 10 Feb 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon Feb 27, 2006 7:48 am     Reply with quote

Try to use
Code:

case 'x':
    output_bit(RELAIS_Kx,!input(RELAIS_Kx));
    break;

where 1, 2, 3 and 4 should be instead of x.
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Feb 27, 2006 8:04 am     Reply with quote

This did not toggle the output pin

If i press the 1 key the output goes low, after i press the 1 key it will be low

It must go to high state
Alex N



Joined: 10 Feb 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon Feb 27, 2006 8:17 am     Reply with quote

[spam], if you press the 1 key and RELAIS_K1 is low, !input(RELAIS_K1) is high, which is placed to RELAIS_K1. Pay attention to !input.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 27, 2006 8:21 am     Reply with quote

Check to see if your compiler supports the output_toggle() function.

output_toggle(pin) where pin = PORT_A3 pin names

If not, XOR (~), the #BYTE and #BIT directives are your friends.

Code:
#byte LATCHA = 0xF89 //18F4520, your mileage may vary
#bit RELAY_K3 = LATCHA.1

RELAY_K3 = 1; // on
RELAY_K3 = 0; // off
RELAY_K3 ~= 1; // toggle

_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
The Puma



Joined: 23 Apr 2004
Posts: 227
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Feb 27, 2006 8:22 am     Reply with quote

This works

output_toggle(RELAIS_K1);

Thx for help


Last edited by The Puma on Mon Feb 27, 2006 8:51 am; edited 1 time in total
Alex N



Joined: 10 Feb 2006
Posts: 16

View user's profile Send private message

PostPosted: Mon Feb 27, 2006 8:32 am     Reply with quote

Rwyoung, thank you for the useful information. It turned out, that my compiler (as opposed to the help index) also supports output_toggle function.
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