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

string array

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







string array
PostPosted: Fri Dec 04, 2009 6:36 pm     Reply with quote

Compiler Version 4.099 PCM

I think what I want to do is a string array, but I can't get one declared. Here's what I want to do:

Say I define 8 active high relays:

Code:
#define Relay0 PIN_C0
#define Relay1 PIN_C1
#define Relay2 PIN_C2
#define Relay3 PIN_C3
#define Relay4 PIN_C4
#define Relay5 PIN_C5
#define Relay6 PIN_C6
#define Relay7 PIN_C7


Can I then declare a string array:

Code:
string strarray[8] = {"Relay0", "Relay1", "Relay2", "Relay3", "Relay4", "Relay5", "Relay6", "Relay7"};


And activate Relay 0 with:

Code:
OUTPUT_HIGH(strarray[0]);


Is this a legal move?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 04, 2009 7:44 pm     Reply with quote

The i/o functions don't take strings as parameters. They take numbers
as parameters. Declare it as an array of integers, and initialize it to
the "Relay0" names, etc., but without the quotes on the names.

You didn't post your PIC. If you're using a 16F, then declare the array
as 'int8'. If you're using an 18F PIC, then declare it as 'int16'.
mbradley



Joined: 11 Jul 2009
Posts: 118
Location: California, USA

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

PostPosted: Tue Dec 08, 2009 8:25 pm     Reply with quote

As mentioned above, will work, I have also done the same, but not predefined.

I have done this:

Code:

int16  outputs[8] = {PIN_C0, PIN_C1, PIN_C2, PIN_C3,
                             PIN_B0, PIN_B1, PIN_B2, PIN_B3};

output_high(outputs[0]);



But predefining like you did does look cleaner when needed to edit, or port.
_________________
Michael Bradley
www.mculabs.com
Open Drivers and Projects
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