|
|
View previous topic :: View next topic |
Author |
Message |
LittleMonica Guest
|
string array |
Posted: Fri Dec 04, 2009 6:36 pm |
|
|
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
|
|
Posted: Fri Dec 04, 2009 7:44 pm |
|
|
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
|
|
Posted: Tue Dec 08, 2009 8:25 pm |
|
|
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 |
|
|
|
|
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
|