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 support@ccsinfo.com

Switch Statement

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



Joined: 15 Feb 2021
Posts: 49

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

Switch Statement
PostPosted: Fri Apr 16, 2021 9:22 am     Reply with quote

How would this switch statement look in CCS C? Thanks

Quote:


// key1 0x50 to Toggle relay 1 // these are command of the IR remote control which i have
// key2 0xD8 to Toggle relay 2
// key3 0xF8 to Toggle relay 3
// key4 0x30 to Toggle relay 4
// key5 0xB0 to Turn off all the relays

switch(command) // swich on
{
case 0x50: RELAY1 = !RELAY1; //Toggle relay 1
break;
case 0xD8: RELAY2 = !RELAY2; //Toggle relay 2
break;
case 0xF8: RELAY3 = !RELAY3; //Toggle relay 3
break;
case 0x30: RELAY4 = !RELAY4; //Toggle relay 4
break;
case 0xB0: RELAY1 = 0; //Turn off all the relay
RELAY2 = 0;
RELAY3 = 0;
RELAY4 = 0;
break;
default :
break;
}

allenhuffman



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 16, 2021 9:31 am     Reply with quote

From my experience, the CCS compiler handles switch/case like a normal C compiler.

The directives to toggle a relay might be different -- either mapping to a specific I/O pin (is that what your RELAY is?) or using output_high/output_low/etc.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19226

View user's profile Send private message

PostPosted: Fri Apr 16, 2021 9:38 am     Reply with quote

Assuming you are talking a PIC16/18, then if you don't have a 'default', and
there are a reasonable number of 'cases', it'll code as a jump table, rather
than tests. If you add a default, it switches to using tests, and will use tests
if there are less than about half a dozen cases.
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