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

Map pins into a struct.

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



Joined: 22 Feb 2006
Posts: 65

View user's profile Send private message

Map pins into a struct.
PostPosted: Mon Sep 24, 2007 2:22 am     Reply with quote

Hi everyone.
I have a small question.
I need to make an array of structs.
Code:

MY_STRUCT_TYPE array_of_structs[2];

Code:
typedef struct
{
    UNSIGNED_8 member_1;
    UNSIGNED_16 member_2;
    A PIN FROM A PORT the_pin;
}
MY_STRUCT_TYPE;

I have an init function where I will set up some initial values of both structs.
But how can I set-up in one struct to have access to a pin to have something like this:

Code:
void DoSomething(UNSIGNED_8 index)
{
    MY_STRUCT_TYPE* pointer;
    pointer = &array_of_structs[index];
    if(pointer->the_pin == TRUE)
    {
         printf("Pin is High\r\n");
    }
}

Is this possible?
Thank you.
Ttelmah
Guest







PostPosted: Mon Sep 24, 2007 4:02 am     Reply with quote

First question, what compiler version?.
If you are using a V4 compiler, then the 'pin numbers' for functions like input_pin, can be variables. So you can have:
Code:

typedef struct
{
    UNSIGNED_8 member_1;
    UNSIGNED_16 member_2;
    int16 the_pin;
}
MY_STRUCT_TYPE;
//Then with the array declared define the pins using something like:

array_of_structs[0].the_pin=PIN_B0;
array_of_structs[1].the_pin=PIN_B1;
//etc.

//Which can then be accessed, with:

if (input(pointer->the_pin))

The same basic construction, can be used in older compilers, by 'emulating' the variable based functions. Code for this has been published here in the past. A search for the keyword 'procedures', should fid the version published by PCM_programmer to do this.
You can 'map' a variable directly 'onto' a port, or bit, but you can't do this for a single pin inside a structure.

Best Wishes
tavioman



Joined: 22 Feb 2006
Posts: 65

View user's profile Send private message

PostPosted: Mon Sep 24, 2007 4:42 am     Reply with quote

Thanks!
I will try your solution.
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