View previous topic :: View next topic |
Author |
Message |
pblais
Joined: 08 Apr 2005 Posts: 1
|
Array of functions???? |
Posted: Fri Apr 08, 2005 9:01 am |
|
|
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
|
|
Posted: Fri Apr 08, 2005 11:18 am |
|
|
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
|
|
Posted: Fri Apr 08, 2005 12:02 pm |
|
|
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
|
|
Posted: Fri Apr 08, 2005 12:28 pm |
|
|
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
|
|
Posted: Fri Apr 08, 2005 1:43 pm |
|
|
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.... |
|
|
Guest
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Apr 08, 2005 2:26 pm |
|
|
Well, that's what he said. |
|
|
Guest
|
|
Posted: Tue Apr 12, 2005 10:20 am |
|
|
Ahhh... See what happens when someone tries to make a little conversation. |
|
|
|