开发平台(Platform): 32bit/16bit MCU Ansi C
额外使用到的函数库(Library Used): 没有任何LIB
问题(Question):
State Machine写法
喂入的资料(Input):
预期的正确结果(Expected Output):
可以根据外面的状态变化,可以自动跳到任何状态.
错误结果(Wrong Output):
程式码(Code):
我的宣告如下
enum m_state
{
idle,PFC_ON, PSU_wake, PSU_RUN,
};
enum m_state PSU_sate;
int main(void)
{
unsigned int i = 0;
// Disable the JTAG function
INIT();
// P_FC_O=1;
// P_FC_O=0;
Init_PM_I2C2();
PMADDR_check();
// ClearCommandData(); /* Clear commands RAM locations */
// WrTestCommandData();
Init_PM_REG();
InitTMR1();
//InitTMR2(); running at Init(); funciton
Init_TMR3(); //Warring Timer3 for PMBUS Don't change it
InitTMR5();
for(i=0;i<256;i++) //Black box rom test
{
Black_BOX.ROM.EEPROM[i]=i;
//P_Debug_O= ~P_Debug_O;
}
Self_Test();
while( 1 )
{
if(global_flags.ready_to_copy == 1) /* Buffer ready to be copied? */
{
global_flags.ready_to_copy = 0;
CopyBufferInRam();
}
if(PSU_sate==PFC_ON)
{
}
else if(PSU_sate==idle)
{
}
else if(PSU_sate==PSU_wake)
{
}
else if(PSU_sate==PSU_RUN)
{
}
if(P_47_AC_I==IO_Low)
{
}
if(IO_FLAG.ADCDONE==1) //When get ADC value , convert ADC value to PBBUS
Stack
{
convert_adc();
}
if(IO_FLAG.CONVERTDONE==1)
{
Check_UVOP();
}
}
while( 1 );
}
补充说明(Supplement):
希望达到下面这一个sate_machine
http://ppt.cc/c5yr