提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file : PLCfunctions.h
|
|
4 |
* @brief : Header for PLCfunctions.c file.
|
|
5 |
* This file contains the user functions defines of the application.
|
|
6 |
******************************************************************************
|
|
7 |
*/
|
|
8 |
#ifndef __PLCFUNCTIONS_H__
|
|
9 |
#define __PLCFUNCTIONS_H__
|
|
10 |
#include "GlobalDef.h"
|
|
11 |
#include "KMachine.h"
|
|
12 |
|
|
13 |
|
|
14 |
#define TOTAL_WDFS (16) //Total DF Count
|
|
15 |
#define TOTAL_CurVAL (8) //
|
|
16 |
|
|
17 |
//extern unsigned short X[256];
|
|
18 |
//extern unsigned short Y[256];
|
|
19 |
//extern unsigned short R[256];
|
|
20 |
|
|
21 |
#define TOTALTIMERS (64)
|
|
22 |
#define TICK_OF_MS (10) //1ms
|
|
23 |
#define TICK_OF_RS (100) //10mS
|
|
24 |
#define TICK_OF_XS (1000) //100mS
|
|
25 |
#define TICK_OF_YS (10000) //1S
|
|
26 |
|
|
27 |
#pragma anon_unions
|
|
28 |
|
|
29 |
typedef struct tagTimerStat
|
|
30 |
{
|
|
31 |
unsigned short nScale:2;//Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
|
|
32 |
unsigned short nType:1; //0 : timer 1:counter ;
|
|
33 |
unsigned short nDir:1; //0 : count down. 1 count up;
|
|
34 |
unsigned short nInited:1;
|
|
35 |
unsigned short bSet:1;
|
|
36 |
unsigned short bTon:1;
|
|
37 |
|
|
38 |
}stTimerStat;
|
|
39 |
|
|
40 |
typedef struct tagTimer
|
|
41 |
{
|
|
42 |
unsigned short SV;
|
|
43 |
unsigned short EV;
|
|
44 |
unsigned int LastActTime;
|
|
45 |
union {
|
|
46 |
unsigned short StatByte;
|
|
47 |
struct
|
|
48 |
{
|
|
49 |
unsigned short nScale:2; //Time Scale, 0:1ms 1:10ms 2:100ms 3:1S
|
|
50 |
unsigned short nType:1; //0 : timer 1 : counter ;
|
|
51 |
unsigned short nDir:1; //0 : count down. 1 count up;
|
|
52 |
unsigned short nInited:1;
|
|
53 |
unsigned short bSet:1;
|
|
54 |
unsigned short bTon:1;
|
|
55 |
|
|
56 |
};
|
|
57 |
// stTimerStat Stat;
|
|
58 |
};
|
|
59 |
}stTimer;
|
|
60 |
|
|
61 |
typedef struct tagPLCPROG
|
|
62 |
{
|
|
63 |
unsigned char OP;
|
|
64 |
unsigned char AddrType;
|
|
65 |
unsigned short Addr;
|
|
66 |
}stPLCPROG;
|
|
67 |
|
|
68 |
extern stPLCPROG const prog1[];
|
|
69 |
extern int nSizeProg1;
|
|
70 |
|
|
71 |
|
|
72 |
//extern unsigned char CurVAL;
|
|
73 |
//extern unsigned char CurVALs[TOTAL_CurVAL];
|
|
74 |
//extern unsigned short DFs[TOTAL_WDFS];
|
|
75 |
|
|
76 |
//extern unsigned short WX[13];
|
|
77 |
//extern unsigned short WY[13];
|
|
78 |
//extern unsigned short WR[64];
|
|
79 |
//extern unsigned short DT[256];
|
|
80 |
//extern unsigned short SDT[256];
|
|
81 |
extern const unsigned short bitMasks[16];
|
|
82 |
//extern stTimer Timers[TOTALTIMERS];
|
|
83 |
|
|
84 |
|
|
85 |
typedef struct tagPLCMem
|
|
86 |
{
|
|
87 |
unsigned short WDFs[TOTAL_WDFS];
|
|
88 |
unsigned char CurVALs[TOTAL_CurVAL];
|
|
89 |
unsigned char CurVAL;
|
|
90 |
stTimer Timers[TOTALTIMERS];
|
|
91 |
|
|
92 |
}stPLCMem;
|
|
93 |
|
|
94 |
extern stPLCMem PLCMem;
|
|
95 |
|
|
96 |
int InitTimer(int nIndex, int nType);
|
|
97 |
int StartTimer(int nIndex , int SV);
|
|
98 |
int StopTimer(int nIndex);
|
|
99 |
int ResetTimer(int nIndex);
|
|
100 |
int SetTimerValue(int nIndex, int bSet, int SV);
|
|
101 |
int ProcessTimer(int nIndex);
|
|
102 |
int IsTimerOn(int nIndex);
|
|
103 |
int GetTimerSV(int nIndex);
|
|
104 |
int GetTimerEV(int nIndex);
|
|
105 |
|
|
106 |
int PushInVal(void);
|
|
107 |
int PopOutVal(void);
|
|
108 |
|
|
109 |
|
|
110 |
enum enPLCOPs
|
|
111 |
{
|
|
112 |
OP_None =0,
|
|
113 |
OP_ST=1,
|
|
114 |
OP_ST_=2,
|
|
115 |
OP_AN=3,
|
|
116 |
OP_AN_=4,
|
|
117 |
OP_OR=5,
|
|
118 |
OP_OR_=6,
|
|
119 |
OP_NOT=7,
|
|
120 |
|
|
121 |
OP_PSHS =8,
|
0aeaad
|
122 |
OP_RDS = 9,
|
Q |
123 |
OP_POPS =10,
|
bfc108
|
124 |
|
0aeaad
|
125 |
OP_ANS=11,
|
Q |
126 |
OP_ORS=12,
|
bfc108
|
127 |
|
Q |
128 |
OP_OUT=16,
|
|
129 |
OP_SET=17,
|
|
130 |
OP_RESET=18,
|
|
131 |
OP_DF=19,
|
|
132 |
OP_DF_=20,
|
|
133 |
|
|
134 |
OP_TML=0xC8,
|
|
135 |
OP_TMR=0xDC,
|
|
136 |
OP_TMX=0xDD,
|
|
137 |
OP_TMY=0xFA,
|
|
138 |
|
|
139 |
};
|
|
140 |
|
|
141 |
enum enAddrTypes
|
|
142 |
{
|
|
143 |
Addr_None =0,
|
|
144 |
Addr_X =1,
|
|
145 |
Addr_Y =2,
|
|
146 |
Addr_R =3,
|
|
147 |
Addr_T =4,
|
|
148 |
Addr_L =5,
|
|
149 |
Addr_ =6,
|
|
150 |
|
|
151 |
};
|
|
152 |
|
|
153 |
int ProcessPLCPROG(const stPLCPROG * prog,int nSize);
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
#endif /* __PLCFUNCTIONS_H__ */
|