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

Array of functions????

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



Joined: 08 Apr 2005
Posts: 1

View user's profile Send private message

Array of functions????
PostPosted: Fri Apr 08, 2005 9:01 am     Reply with quote

Hi...
I copied the following little program from Embedded Systems Programming magazine in my first attempt at using a PIC as a state machine.
Code:

#include <pic.h>

void InitializeLdgGearSM();
void GearDown();
void WtgForTakeoff();
void RaisingGear();
void GearUp();
void LoweringGear();


typedef enum {GEAR_DOWN = 0, WTG_FOR_TKOFF, RAISING_GEAR, GEAR_UP,
           LOWERING_GEAR} State_Type;

void (*state_table[]() = GearDown,WtgForTakeoff,RaisingGear,GearUp,
      LoweringGear);
      
   State_Type   curr_state;
   
      
main(void)
{
   InitializeLdgGearSM();
   while(1)
   {
      state_table[curr_state]();
   }
}

void InitializeLdgGearSM()
{
   curr_state = GEAR_DOWN;    //0
}

void GearDown()
{
   curr_state = WTG_FOR_TKOFF;  //1
}
   
void WtgForTakeoff()
{
   curr_state = RAISING_GEAR;  //2
}

void RaisingGear()
{
   curr_state = GEAR_UP;   //3
}

void GearUp()
{
   curr_state = LOWERING_GEAR;  //4
}

void LoweringGear()
{
   curr_state = GEAR_DOWN; //0
}


When I try to compile this with my Hi-Tech compiler, I get the following error

Error[000] D:\Projects\State Machine\States.C 17 : can't have array of functions
Error[000] D:\Projects\State Machine\States.C 17 : ) expected
Error[000] D:\Projects\State Machine\States.C 17 : { expected
Error[000] D:\Projects\State Machine\States.C 20 : probable missing '}' in previous block


Will the CCS compiler compile this code? If it does, put me down to purchase a copy...

Thanks
Pierre
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Apr 08, 2005 11:18 am     Reply with quote

There is a demo version of the compiler that you can download and try for yourself.
dyeatman



Joined: 06 Sep 2003
Posts: 1938
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Apr 08, 2005 12:02 pm     Reply with quote

Since we cannot see what is in PIC.h we dont know if the header code is right for the CCS compiler. If it is for HiTech C I would doubt it...

Matter of fact, if the code is for HiTech, it likely will not compile without a few changes in the initialization code at least.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Apr 08, 2005 12:28 pm     Reply with quote

dyeatman wrote:
Since we cannot see what is in PIC.h we dont know if the header code is right for the CCS compiler. If it is for HiTech C I would doubt it...

Matter of fact, if the code is for HiTech, it likely will not compile without a few changes in the initialization code at least.



What he is really asking (I believe) is whether or not CCS supports an array of function pointers. I am not sure without testing it. So that is why I left it up to him to do. I can tell you that the C18 compiler will do it though and I can even store the data as a constant.
dyeatman



Joined: 06 Sep 2003
Posts: 1938
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri Apr 08, 2005 1:43 pm     Reply with quote

good point, I guess I am being a little too absolute in my answers and I am in error by NOT assuming he knows what he is doing.... Wink
Guest








PostPosted: Fri Apr 08, 2005 2:25 pm     Reply with quote

Is this the mag. you found this code in?

http://www.magazines.com/ncom/mag?mid=0000007243&afd_number=4297&ovkey=Embedded+Systems+Programming+Magazine
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Apr 08, 2005 2:26 pm     Reply with quote

Anonymous wrote:
Is this the mag. you found this code in?

http://www.magazines.com/ncom/mag?mid=0000007243&afd_number=4297&ovkey=Embedded+Systems+Programming+Magazine


Well, that's what he said.
Guest








PostPosted: Tue Apr 12, 2005 10:20 am     Reply with quote

Ahhh... See what happens when someone tries to make a little conversation. Confused
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