/** ****************************************************************************** * @file : PLCfunctions.h * @brief : Header for PLCfunctions.c file. * This file contains the user functions defines of the application. ****************************************************************************** */ #ifndef __PLCFUNCTIONS_H__ #define __PLCFUNCTIONS_H__ #include "GlobalDef.h" #include "KMachine.h" #define TOTAL_WDFS (16) //Total DF Count #define TOTAL_CurVAL (8) // //extern unsigned short X[256]; //extern unsigned short Y[256]; //extern unsigned short R[256]; #define TOTALTIMERS (64) #define TICK_OF_MS (10) //1ms #define TICK_OF_RS (100) //10mS #define TICK_OF_XS (1000) //100mS #define TICK_OF_YS (10000) //1S #pragma anon_unions typedef struct tagTimerStat { unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S unsigned short nType:1; //0 : timer 1:counter ; unsigned short nDir:1; //0 : count down. 1 count up; unsigned short nInited:1; unsigned short bSet:1; unsigned short bTon:1; }stTimerStat; typedef struct tagTimer { unsigned short SV; unsigned short EV; unsigned int LastActTime; union { unsigned short StatByte; struct { unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S unsigned short nType:1; //0 : timer 1 : counter ; unsigned short nDir:1; //0 : count down. 1 count up; unsigned short nInited:1; unsigned short bSet:1; unsigned short bTon:1; }; // stTimerStat Stat; }; }stTimer; typedef struct tagPLCPROG { unsigned char OP; unsigned char AddrType; unsigned short Addr; }stPLCPROG; extern stPLCPROG const prog1[]; extern int nSizeProg1; //extern unsigned char CurVAL; //extern unsigned char CurVALs[TOTAL_CurVAL]; //extern unsigned short DFs[TOTAL_WDFS]; //extern unsigned short WX[13]; //extern unsigned short WY[13]; //extern unsigned short WR[64]; //extern unsigned short DT[256]; //extern unsigned short SDT[256]; extern const unsigned short bitMasks[16]; //extern stTimer Timers[TOTALTIMERS]; typedef struct tagPLCMem { unsigned short WDFs[TOTAL_WDFS]; unsigned char CurVALs[TOTAL_CurVAL]; unsigned char CurVAL; stTimer Timers[TOTALTIMERS]; }stPLCMem; extern stPLCMem PLCMem; int InitTimer(int nIndex, int nType); int StartTimer(int nIndex , int SV); int StopTimer(int nIndex); int ResetTimer(int nIndex); int SetTimerValue(int nIndex, int bSet, int SV); int ProcessTimer(int nIndex); int IsTimerOn(int nIndex); int GetTimerSV(int nIndex); int GetTimerEV(int nIndex); int PushInVal(void); int PopOutVal(void); enum enPLCOPs { OP_None =0, OP_ST=1, OP_ST_=2, OP_AN=3, OP_AN_=4, OP_OR=5, OP_OR_=6, OP_NOT=7, OP_PSHS =8, OP_RDS = 9, OP_POPS =10, OP_ANS=11, OP_ORS=12, OP_OUT=16, OP_SET=17, OP_RESET=18, OP_DF=19, OP_DF_=20, OP_TML=0xC8, OP_TMR=0xDC, OP_TMX=0xDD, OP_TMY=0xFA, }; enum enAddrTypes { Addr_None =0, Addr_X =1, Addr_Y =2, Addr_R =3, Addr_T =4, Addr_L =5, Addr_ =6, }; int ProcessPLCPROG(const stPLCPROG * prog,int nSize); #endif /* __PLCFUNCTIONS_H__ */