Приложение г
Листинг результирующей программы
#pragma DB OE SB CD OR LC LA
#pragma ot(9, SIZE)
#include "xa0.h"
#ifndef __isheader
#define __global
#define __comment /##/
#else
#define __global extern
#define _at_ ;/##/
#define __comment
#endif
#ifdef __isheader
#include <cF120.h>
#ifndef STRINGHINCLUDED
#define STRINGHINCLUDED
#include <string.h>
#endif
#define CodeAddr(x) 0x50##x
#define CalibrAddr(x) 0xe4##x
#define ModemAddr(x) 0xe##x##00
#define ModemBufAddr(x) 0xa##x
#define _RAMSavedLoc 0x100
#define _ROMSavedLoc 0xf000
#define _ZFSavedBytes 0x60
#define FFLOATBLANK BlankSpace.FloatBlank
#define IINTBLANK BlankSpace.IntBlank
#define BBOOLBLANK BlankSpace.BoolBlank
#define false 0
#define true 1
#define FALSE 0
#define TRUE 1
#define NULL 0
#define DEVICE_MC8_125
#endif
__global xdata union{
float FloatBlank;
int IntBlank;
unsigned char BoolBlank;
}BlankSpace;
__global xdata char _INNUM;
__global xdata char _OUTNUM;
__global xdata unsigned char begram _at_ 0x0;
__global data char NullFuncReserve1[40] _at_ 0x0;
__global data char NullFuncReserve2[77] _at_ 0x30;
// Analog inputs
__global xdata float AI[8] _at_ 0x01;
__comment #define AI(x) AI[x]
__global code float Ureference _at_ CalibrAddr(18);
__global code float Coefs[8][5] _at_ CalibrAddr(1c);
__comment #define T50 0
__comment #define T1000 1
__comment #define T10k 2
__comment #define C20 3
__comment #define V10 4
// Analog outputs
__comment #define _DACCount 2
__global xdata float AO[_DACCount] _at_ 0xc14;
__comment #define AO(x) AO[x]
__global xdata unsigned char _MANUALAO _at_ 0x104;
__comment #define DACManual _MANUALAO
__global xdata float DACLimits[_DACCount][2] _at_ 0x105;
__global xdata unsigned int dacs[_DACCount] _at_ 0x5e4;
__global code float DACSet[_DACCount][4] _at_ CalibrAddr(bc);
__global xdata float DACf[_DACCount] _at_ 0xc00;
__global xdata unsigned char DI[4] _at_ 0xc08;
__global xdata unsigned char DO[8] _at_ 0xc0c;
__global xdata unsigned char ManualOnMask _at_ 0x102;
__global xdata unsigned char ManualOffMask _at_ 0x103;
__global xdata unsigned char DigOutsManual[2] _at_ 0x102;
__global xdata unsigned char calendar[7] _at_ 0x4d;
__global xdata unsigned int WatchDogAlg _at_ 0x66;
__global xdata unsigned char _CycleInterval _at_ 0x155;
__comment #define _CYCLE (((float)_CycleInterval)/100.0)
__comment #define _CYCLEINT _CycleInterval
__comment #define temtba 0x1feb
__comment #define temtra 0x1fff
__global code unsigned char ModemParTable _at_ ModemAddr(0);
__global code unsigned char ModemErrTable _at_ ModemAddr(1);
__comment #define _PARPAGELOC CodeAddr(01)
__global code unsigned short AddrPlannerStruct _at_ CodeAddr(06);
__global xdata char NeZanimat[1792] _at_ 0x500;
__comment #define TempZoneSize 5092
__global xdata char TempZone[1] _at_ 0xc1c;
__global bdata char Dinputs _at_ 0x22;
__global bdata char Doutputs _at_ 0x23;
__global bdata char _INIT_BITS _at_ 0x28;
#ifndef __isheader
sbit ED = P3 ^ 5;
sbit SLAVE = P3 ^ 7;
// Digital inputs
#define DI(x) Dinput_##x
sbit Dinput_0 = Dinputs^0;
sbit Dinput_1 = Dinputs^1;
sbit Dinput_2 = Dinputs^2;
sbit Dinput_3 = Dinputs^3;
//Digital outputs
#define DO(x) Doutput_##x
sbit Doutput_0 = Doutputs^0;
sbit Doutput_1 = Doutputs^1;
sbit Doutput_2 = Doutputs^2;
sbit Doutput_3 = Doutputs^3;
sbit Doutput_4 = Doutputs^4;
sbit Doutput_5 = Doutputs^5;
sbit Doutput_6 = Doutputs^6;
sbit Doutput_7 = Doutputs^7;
sbit _Inited = _INIT_BITS^0;
sbit _UART1_Inited = _INIT_BITS^1;
sbit _10ms_Inited = _INIT_BITS^2;
data int _Save_Command _at_ 0x38;
data unsigned char *getptr _at_ 0x30;
data unsigned char *copyptr _at_ 0x33;
void DACNorm(unsigned char OutputNum, float inp)
{
if(!(DACManual & 1<<OutputNum))
DACf[OutputNum] = inp;
}
void _DACService()
{
#define xdata
unsigned char i;
for(i = 0; i < _DACCount; i++)
DACNorm(i, AO(i));
}
xdata float xdata* FFLOATPTR;
xdata unsigned int xdata* IINTPTR;
xdata unsigned char xdata* BBOOLPTR;
#endif
#ifdef __isheader
struct Timers{
unsigned char Status;
unsigned long Delay;
};
struct TPWMConfig{
unsigned char CoupleNum :4;
unsigned char Open :1;
unsigned char Close :1;
unsigned char Stop :1;
unsigned char Used :1;
unsigned long delay;
long sum;
unsigned int pulsetime;
unsigned int backlash :9;
unsigned int pause :1;
unsigned int up :1;
unsigned int down :1;
unsigned int st :1;
unsigned int rt :1;
unsigned int OldOpen :1;
unsigned int OldClose :1;
};
#endif
xdata char RAMCheckByte _at_ 0x1dff;
#define VOLATILE(x) ((x < 0xb6) || (x >= (0xb6 + 50)))
__comment #define BOOLCOUNTO 36
__global xdata unsigned char BOOLARRO[36] _at_ 0xc1c;
__comment #define INTCOUNTO 11
__global xdata int INTARRO[11] _at_ 0xc40;
__comment #define FLOATCOUNTO 21
__global xdata float FLOATARRO[21] _at_ 0xc56;
__comment #define PWM2COUNTO 1
__global xdata unsigned char PWM2ARRO[1] _at_ 0xcaa;
__comment #define BOOLCOUNTAO 1
__global xdata unsigned char BOOLARRAO[1] _at_ 0xcab;
__comment #define _ALLTHESTATICS 0
__comment #define _ALLTHERETAINS 0
__global xdata unsigned char _ARR0[12];
__global xdata unsigned char _ARR1[9];
__global xdata float X53327236_TIME;
__global xdata unsigned char X53327236_STATE;
__global xdata float X53376856_YIN_1;
__global xdata float X53376856_XN_1;
__global xdata float X53376856_YD1N_1;
__global xdata float X53376856_YAN_1;
__global xdata float X53376856_YULM;
__global xdata unsigned char X53700776_PREVIOUS;
__global xdata unsigned char X34078064_FAUL;
__global xdata float X34078064_INPUTN_1;
__global xdata float X34078064_STORAGE;
__global xdata unsigned char X34078064_FLAG;
__global xdata unsigned char X34078064_EXCN_1;
__global xdata unsigned char X25528264_FAUL;
__global xdata float X25528264_INPUTN_1;
__global xdata float X25528264_STORAGE;
__global xdata unsigned char X25528264_FLAG;
__global xdata unsigned char X25528264_EXCN_1;
__global xdata int X53634564_COUNT;
__global xdata int X53610812_COUNT;
__global xdata int X53797644_COUNT;
__global xdata int X53831064_COUNT;
__global xdata int X53412616_BLOCKID;
__global xdata int X53414548_BLOCKID;
__global xdata int X53415124_BLOCKID;
__global xdata int X48414408_BLOCKID;
__global xdata int X53741192_BLOCKID;
__global xdata int X53460520_BLOCKID;
__global xdata int X48422568_BLOCKID;
__global xdata int X48436796_BLOCKID;
__global xdata int X48438080_BLOCKID;
__global xdata int X48453704_BLOCKID;
__global xdata int X48503916_BLOCKID;
__global xdata int X48585676_BLOCKID;
__global xdata int X48577916_BLOCKID;
__global xdata int X48395640_BLOCKID;
__global xdata int X48450212_BLOCKID;
__global xdata int X53604948_COUNT;
__global xdata int X53516744_COUNT;
__global xdata int X53568164_COUNT;
__global xdata float X53536616_TIME;
__global xdata unsigned char X53536616_ZN_1;
#define IS_SLAVE false
//--------------Piecewise-linear approximation--------------
#ifndef USEPIECEWISE
#define USEPIECEWISE
void _PIECEWISE(float CurrentX, float* Y, char* XS, char* YS)
{
#define xdata
float Result;
unsigned char Count;
float *Xtable, *Ytable;
unsigned char Amount, XAmount, YAmount;
XAmount = XS[0];
YAmount = YS[0];
Amount = (XAmount < YAmount) ? XAmount : YAmount;
Xtable = (float*)&XS[1];
Ytable = (float*)&YS[1];
if (CurrentX<Xtable[0]) {*Y = Ytable[0]; return;}
if (CurrentX>=Xtable[Amount-1]) {*Y = Ytable[Amount-1]; return;}
for (Count=0; Count<Amount-1; Count++)
{
if ((CurrentX>=Xtable[Count])&&(CurrentX<Xtable[Count+1]))
{
Result=((Ytable[Count+1]-Ytable[Count])*(CurrentX-Xtable[Count]))/(Xtable[Count+1]-Xtable[Count])+Ytable[Count];
break;
}
}
*Y = Result;
}
#endif
#ifndef USEPULSESFLUS
#define USEPULSESFLUS
xdata float _PULSESFLUS_TIME;
xdata unsigned char _PULSESFLUS_STATE;
void _PULSESFLUS(unsigned char Q, unsigned char* Z, float X, float T)
{
#define xdata
float realx;
if(X > 100)
X = 100;
if(X < 0)
X = 0;
if(!_Inited) {
_PULSESFLUS_TIME = 0;
_PULSESFLUS_STATE = false;
}
if(Q) {
if(_PULSESFLUS_TIME > 0)
_PULSESFLUS_TIME -= _CYCLE;
else {
realx = (_PULSESFLUS_STATE) ? 100-X : X;
_PULSESFLUS_TIME = T * realx / 100;
_PULSESFLUS_STATE = !_PULSESFLUS_STATE;
if(_PULSESFLUS_TIME > 0)
*Z = _PULSESFLUS_STATE;
}
}
else{
*Z = _PULSESFLUS_STATE = false;
_PULSESFLUS_TIME = 0;
}
}
#endif
//-------------------------------------------------
// Period - mS
// Analog - %
//-------------------------------------------------
#ifndef USEPWM2
#define USEPWM2
xdata float _PWM2_TIME;
xdata unsigned char _PWM2_STATE;
void _PWM2(float PeriodF, float Analog, unsigned char* Copy)
{
_PULSESFLUS_TIME = _PWM2_TIME;
_PULSESFLUS_STATE = _PWM2_STATE;
_PULSESFLUS(true, Copy, Analog, PeriodF);
_PWM2_TIME = _PULSESFLUS_TIME;
_PWM2_STATE = _PULSESFLUS_STATE;
}
#endif
//-------------------------------------------------
#ifndef USEUNBALANSE
#define USEUNBALANSE
#define _UNBALANSE(X1, X2, Y) Y=X1-(X2)
#endif
//-----------Filter Block------------------------------------
#ifndef USEFILTER
#define USEFILTER
void _FILTER(float INPUT, float* OUTPUT, float TF)
{
if(!_Inited)
*OUTPUT = INPUT;
else{
if(TF > _CYCLE)
{
(*OUTPUT) += ((INPUT - (*OUTPUT))*_CYCLE)/(TF + _CYCLE);
}
else
(*OUTPUT) = INPUT;
}
}
#endif
//-----------------------------------------------------------
#ifndef USEVALUEVAR
#define USEVALUEVAR
#define _VALUEVAR(x, y) y=x
#endif
//-----------PDD' Block--------------------------------------
#ifndef USEPDD
#define USEPDD
xdata float _PDD_XN_1, _PDD_YD1N_1, _PDD_YAN_1;
void _PDD(float YIN, float INPUT, unsigned char MANUAL, float* OUTPUT, float KP, float TI, float D, float YDN, float YUP)
{
#define xdata
float Xn;
float Yp;
float Yd;
float Yan;
float Yd1n;
float Yd2;
float Td;
if(TI < 1) TI = 1;
if(D < 0) D = 0;
Xn = KP*INPUT;
if(!_Inited)
{
_PDD_YD1N_1 = _PDD_YAN_1 = 0;
_PDD_XN_1 = Xn;
}
if(MANUAL)
{
Yp = Yd = 0;
_PDD_XN_1 = Xn;
Yan = 8.0*Xn;
_PDD_YD1N_1 = 0;
}
else{
if (YIN > YUP) {
if (KP > 0)
Yp = (INPUT > 0) ? 0 : (Xn*_CYCLE)/TI;
else
Yp = (INPUT < 0) ? 0 : (Xn*_CYCLE)/TI;
}
else if(YIN < YDN) {
if (KP > 0)
Yp = (INPUT < 0) ? 0 : (Xn*_CYCLE)/TI;
else
Yp = (INPUT > 0) ? 0 : (Xn*_CYCLE)/TI;
}
else
Yp=(Xn*_CYCLE)/TI;
Yd = Xn - _PDD_XN_1;
Td = D*TI;
Yan = _PDD_YAN_1 + ((Xn*8.0 - _PDD_YAN_1)/(1.0 + Td/(_CYCLE*8.0)));
}
Yd1n = Xn*8.0 - Yan;
Yd2 = Yd1n - _PDD_YD1N_1;
(*OUTPUT) = Yp + Yd + Yd2;
_PDD_XN_1 = Xn;
_PDD_YAN_1 = Yan;
_PDD_YD1N_1 = Yd1n;
}
#endif
//------------Dead zone block--------------------------------
#ifndef USEDEADZONE
#define USEDEADZONE
void _DEADZONE(float INPUT, float* OUTPUT, float DEADZONE)
{
if(DEADZONE < 0) DEADZONE = 0;
if ((INPUT >= DEADZONE/2) || (INPUT <= (-DEADZONE)/2))
{
if (INPUT >= DEADZONE/2)
(*OUTPUT) = INPUT - DEADZONE/2;
if (INPUT <= (-DEADZONE)/2.0)
(*OUTPUT) = INPUT + DEADZONE/2;
}
else
(*OUTPUT) = 0;
}
#endif
//-----------Integrator Block--------------------------------
#ifndef USEINTEGRATOR
#define USEINTEGRATOR
xdata float _INTEGRATOR_YIN_1;
void _INTEGRATOR(float DYIN, float* YIN, unsigned char OFF)
{
if(!_Inited) {
#ifdef DEVICE_MC8_125
if (VOLATILE (YIN))
_INTEGRATOR_YIN_1 = 0;
else
_INTEGRATOR_YIN_1 = *YIN;
#else
_INTEGRATOR_YIN_1 = 0;
#endif
}
*YIN = _INTEGRATOR_YIN_1;
if(!OFF)
(*YIN) += DYIN;
_INTEGRATOR_YIN_1 = (*YIN);
}
#endif
//-----------Saturation Block--------------------------------
#ifndef USESATURATION
#define USESATURATION
void _SATURATION(float INPUT, float* OUTPUT, float YDN, float YUP)
{
if ( INPUT > YUP )
(*OUTPUT) = YUP;
else if ( INPUT < YDN )
(*OUTPUT) = YDN;
else
(*OUTPUT) = INPUT;
}
#endif
//-------------PID Regulator Block---------------------------
#ifndef USEPID2AOOVR
#define USEPID2AOOVR
xdata float _PID2AOOVR_YIN_1;
xdata float _PID2AOOVR_XN_1, _PID2AOOVR_YD1N_1, _PID2AOOVR_YAN_1;
xdata float _PID2AOOVR_YULM;
void _PID2AOOVR(float INPUT, float* OUTPUT, float* YULM, unsigned char ManualMode, float DEADZONE, float KP, float TI,
float D, float YDN, float YUP, unsigned char OWR, float SET)
{
code mask[4]={1,2,0x10,0x20};
#define xdata
float _DEADZONE_OUTPUT;
float _PDD_OUTPUT;
float ydn, yup;
unsigned char MANUAL, ExternManual;
if(!_Inited)
_PID2AOOVR_YULM = 0.0;
if (_OUTNUM >= 0) {
#if defined DEVICE_MC5
ydn = DACLimits [0];
yup = DACLimits [1];
#elif defined DEVICE_MC8_125
if(_OUTNUM<2)
{
ydn = DACLimits [_OUTNUM][0];
yup = DACLimits [_OUTNUM][1];
}
else
{
ydn = 0;
yup = 100;
}
#endif
}
else {
ydn = YDN;
yup = YUP;
}
ExternManual = (_OUTNUM >= 0) ? (_MANUALAO & mask[_OUTNUM]):false;
// ExternManual = (_OUTNUM >= 0) ? (_MANUALAO & (1<<_OUTNUM)):false;
MANUAL = ManualMode || ExternManual;
_DEADZONE(INPUT, &_DEADZONE_OUTPUT, DEADZONE);
_PDD_XN_1 = _PID2AOOVR_XN_1;
_PDD_YD1N_1 = _PID2AOOVR_YD1N_1;
_PDD_YAN_1 = _PID2AOOVR_YAN_1;
_PDD(_PID2AOOVR_YULM, _DEADZONE_OUTPUT, MANUAL, &_PDD_OUTPUT, KP, TI, D, ydn, yup);
_PID2AOOVR_XN_1 = _PDD_XN_1;
_PID2AOOVR_YD1N_1 = _PDD_YD1N_1;
_PID2AOOVR_YAN_1 = _PDD_YAN_1;
_INTEGRATOR_YIN_1 = _PID2AOOVR_YIN_1;
_INTEGRATOR(_PDD_OUTPUT, &_PID2AOOVR_YULM, OWR || ExternManual);
if(!ExternManual)
_PID2AOOVR_YIN_1 = OWR ? SET : _INTEGRATOR_YIN_1;
else
_PID2AOOVR_YIN_1 = DACf[_OUTNUM];
_SATURATION(_PID2AOOVR_YULM, OUTPUT, ydn, yup);
*YULM = _PID2AOOVR_YULM;
}
#endif
#ifndef USEMULT
#define USEMULT
void _MULT(unsigned char* X, float* Y)
{
#define xdata
int i;
float Result;
float xdata* InpArr;
if(X != NULL)
{
Result = 1;
InpArr = (float*)&X[1];
for(i = 0; i < X[0]; i++)
Result *= InpArr[i];
*Y = Result;
}
}
#endif
//-------conditional operator----------
#ifndef USECONDITIONAL
#define USECONDITIONAL
#define _CONDITIONAL(X1, X2, Q, Y) Y=Q?X1:X2
#endif
//-----------------------------------------------------------
#ifndef USEOR
#define USEOR
void _OR(unsigned char* X, unsigned char* Y)
{
#define xdata
int i;
unsigned char Result;
unsigned char* InpArr;
if(X != NULL)
{
Result = false;
InpArr = (unsigned char*)&X[1];
for(i = 0; i < X[0]; i++)
Result = Result||InpArr[i];
*Y = Result;
}
}
#endif
//-----------------------------------------------------------
#ifndef USEBOOLVAR
#define USEBOOLVAR
#define _BOOLVAR(x, y) y=x
#endif
//-------conditional operator----------
#ifndef USECONDB
#define USECONDB
#define _CONDB(X1, X2, Q, Y) Y=Q?X1:X2
#endif
#ifndef USEBUTTON
#define USEBUTTON
xdata char _BUTTON_PREVIOUS;
unsigned char _BUTTON(unsigned char Q, unsigned char *Z)
{
*Z = Q;
if(Q&&!_BUTTON_PREVIOUS)
{
Q = false;
_Save_Command = 0x5555;
}
_BUTTON_PREVIOUS=*Z;
return Q;
}
#endif
//------------------------------------------------------
#ifndef USESPLITFLOAT
#define USESPLITFLOAT
//------------------------------------------------------
struct FloatExpAndMan
{
short exponent;
float mantissa;
};
union FloatBitStruct
{
float value;
long bits;
};
void SplitFloat(float value, struct FloatExpAndMan *result)
{
#define xdata
union FloatBitStruct bitStruct;
bitStruct.value = value;
result->exponent = (short) ( ( bitStruct.bits >> 23) & 0x000000ff ) - 0x7e;
bitStruct.bits &= 0x807fffff;
bitStruct.bits |= 0x3f000000;
result->mantissa = bitStruct.value;
}
//------------------------------------------------------
#endif
//------------------------------------------------------
#ifndef USELN
#define USELN
void _LN (float x, float *y)
{
const float code a0 = -2.1724098;
const float code a1 = 4.1744959;
const float code a2 = -2.8551644;
const float code a3 = 8.5375156E-1;
const float code LN2 = 0.6931572;
struct FloatExpAndMan xdata xExpAndMan;
if(x <= 0)
{
*y = 0;
return;
}
SplitFloat(x, &xExpAndMan);
*y = (a0 + a1*xExpAndMan.mantissa +
a2*xExpAndMan.mantissa*xExpAndMan.mantissa +
a3*xExpAndMan.mantissa*xExpAndMan.mantissa*xExpAndMan.mantissa) +
LN2*xExpAndMan.exponent;
}
#endif
//---------------Thermister function-----------------------------------------------
#ifndef USETHERMISTOR
#define USETHERMISTOR
void _THERMISTOR(float INPUT, float* CEL, float* FAR, int TYPE)
{
#define ThermA2 1.129241E-3
#define ThermB2 2.341077E-4
#define ThermC2 8.775468E-8
#define ThermA3 1.028444E-3
#define ThermB3 2.392435E-4
#define ThermC3 1.562216E-7
#define xdata
float b;
xdata float RT;
float RealTemp;
float ThermA, ThermB, ThermC;
#ifdef DEVICE_MC8_125
PSBANK=0x21;
#endif
if (INPUT)
RT = Coefs[_INNUM][T10k]/(Ureference/INPUT - 1);
else
RT = 0;
#ifdef DEVICE_MC8_125
PSBANK=0x11;
#endif
if(TYPE==3)
{
ThermA = ThermA3;
ThermB = ThermB3;
ThermC = ThermC3;
}
else{
ThermA = ThermA2;
ThermB = ThermB2;
ThermC = ThermC2;
}
if(RT > 0.0)
{
_LN(RT, &b);
RealTemp = 1/(ThermA + ThermB*b + ThermC*b*b*b) - 273.16;
}
else
RealTemp = -273.16;
*CEL = RealTemp;
*FAR = RealTemp*1.8 + 32;
}
#endif
//---------------Thermister function-----------------------------------------------
#ifndef USETHERMISTORBR
#define USETHERMISTORBR
xdata unsigned char _THERMISTORBR_FAUL;
xdata float _THERMISTORBR_INPUTN_1;
xdata float _THERMISTORBR_STORAGE;
xdata unsigned char _THERMISTORBR_FLAG;
xdata unsigned char _THERMISTORBR_EXCN_1;
void _THERMISTORBR(float INPUT, float* CEL, float* FAR, unsigned char *FAULT, int TYPE)
{
#define xdata
float Temp;
float Speed;
unsigned char Faul;
unsigned char Exceeding;
float ShortCircuitLimit, BreakLimit;
#ifdef DEVICE_MC5
ShortCircuitLimit = 10;
BreakLimit = 0.95*Ureference;
#else
ShortCircuitLimit = 5;
BreakLimit = 2400;
#endif
#define _THERMISTORBR_MAX_SPEED 400
if (!_Inited) {
_THERMISTORBR_FAUL = false;
_THERMISTORBR_INPUTN_1 = INPUT;
_THERMISTORBR_STORAGE = 0;
_THERMISTORBR_FLAG = false;
_THERMISTORBR_EXCN_1 = false;
}
Faul = (INPUT < ShortCircuitLimit) || (INPUT > BreakLimit);
Speed = (INPUT - _THERMISTORBR_INPUTN_1) / _CYCLE;
if (Speed < 0)
Speed = -1 * Speed;
Exceeding = (Speed > _THERMISTORBR_MAX_SPEED);
if (((Faul && !(_THERMISTORBR_FAUL & 0x1f)) && !Exceeding && !(_THERMISTORBR_EXCN_1 & 0x3)) ||
(Exceeding && !_THERMISTORBR_FLAG && !(_THERMISTORBR_FAUL & 0x1f))) {
if (Exceeding)
_THERMISTORBR_FLAG = true;
_THERMISTORBR_STORAGE = _THERMISTORBR_INPUTN_1;
}
if (!Exceeding || Faul)
_THERMISTORBR_FLAG = false;
if (_THERMISTORBR_FLAG || Faul || (_THERMISTORBR_EXCN_1 & 0x3) || (_THERMISTORBR_FAUL & 0x3))
Temp = _THERMISTORBR_STORAGE;
else
Temp = INPUT;
_THERMISTOR (Temp, CEL, FAR, TYPE);
*FAULT = Faul && (_THERMISTORBR_FAUL & 1);
_THERMISTORBR_INPUTN_1 = INPUT;
_THERMISTORBR_FAUL = _THERMISTORBR_FAUL << 1;
if (Faul)
_THERMISTORBR_FAUL |= 1;
_THERMISTORBR_EXCN_1 = _THERMISTORBR_EXCN_1 << 1;
if (Exceeding)
_THERMISTORBR_EXCN_1 |= 1;
}
#endif
//-----------Alarm forming function----------------
#ifndef USEALARMFORM
#define USEALARMFORM
xdata int _ALARMFORM_COUNT;
void _ALARMFORM(unsigned char Q, unsigned char* Z, int Increment,
int Decrement, int Limit, unsigned char Reset)
{
if(!_Inited || Reset)
_ALARMFORM_COUNT = 0;
if(Increment < 1)
Increment = 1;
if(Decrement < 0)
Decrement = 0;
if(Limit < 1)
Limit = 1;
if(Q)
{
_ALARMFORM_COUNT += Increment;
if(_ALARMFORM_COUNT >= Limit)
{
*Z = !Reset;
_ALARMFORM_COUNT = Limit;
}
else if(Reset)
*Z = false;
}
else{
_ALARMFORM_COUNT -= Decrement;
if(_ALARMFORM_COUNT <= 0)
{
*Z = false;
_ALARMFORM_COUNT = 0;
}
}
}
#endif
#ifndef USERSTRIGGER
#define USERSTRIGGER
void _RSTRIGGER(unsigned char Set, unsigned char Reset, unsigned char* Y)
{
if(Set)
*Y = true;
if(Reset)
*Y = false;
}
#endif
//-------------------------------------------------
#ifndef USENOT
#define USENOT
#define _NOT(Q, Z) Z=!Q
#endif
//------------------------------------------------------------
#ifndef USEAND
#define USEAND
void _AND(unsigned char* X, unsigned char* Y)
{
#define xdata
int i;
unsigned char Result;
unsigned char* InpArr;
if(X != NULL)
{
Result = true;
InpArr = (unsigned char*)&X[1];
for(i = 0; i < X[0]; i++)
Result = Result&&InpArr[i];
*Y = Result;
}
}
#endif
#ifndef USEPC485SERVICE
#define USEPC485SERVICE
#ifndef STDIOHINCLUDED
#define STDIOHINCLUDED
#include <stdio.h>
#endif
#ifndef STDLIBHINCLUDED
#define STDLIBHINCLUDED
#include <stdlib.h>
#endif
#define PROTOCESSORFFP485_1AR "DA_AV_02"
#define PROTOCESSORFFP485_2AR "DA_BV_02"
#define PROTOCESSORFFP485_WF true
#define PROTOCESSORFFP485_RF false
#define PROTOCESSORFFP485_WERR -2
#define PROTOCESSORFFP485_LERR -1
xdata unsigned char TimeoutCounter;
xdata unsigned int CommandOK;
xdata unsigned int BlocksCount;
xdata unsigned char uart1obuf [256] _at_ 0xa00;
xdata unsigned char uart1ibuf [256] _at_ 0xb00;
unsigned char *uart1optr;
unsigned char *uart1iptr;
unsigned char uart1ocount;
unsigned char uart1icount;
//-------------------------------------------------------------------------
void _PC485SERVICE(void)
{
if (SCON1&1)
{
*uart1iptr++=SBUF1;
uart1icount++;
SCON1&=0xfc;
}
if (SCON1&2)
{
SCON1&=0xfd;
if (uart1ocount)
{
SBUF1=*uart1optr++; uart1ocount--;
}
}
}
//---------------------------------------------------------------------------
unsigned char SendToProtocessorFFP485 (unsigned char OutBytes)
{
if (!TimeoutCounter) {
memset (uart1ibuf, 0, 100);
uart1optr = &uart1obuf; uart1iptr = &uart1ibuf; uart1icount = 0;
uart1ocount = OutBytes;
SFRPAGE=1; SBUF1 = *uart1optr++; uart1ocount--; SFRPAGE=0;
}
TimeoutCounter++;
if (uart1icount > 0 && uart1ibuf[uart1icount - 1] == 0x0D)
return true;
}
//---------------------------------------------------------------------------
void FormQueryFrame (unsigned char Wr, unsigned char Destination, int Offset, const void *Data, unsigned char *Format, unsigned char *OutBytes)
{
uart1obuf[0] = ':'; uart1obuf[1] = Wr ? 'W' : 'R'; uart1obuf[2] = 'D';
uart1obuf[3] = '-'; uart1obuf[4] = 'N'; uart1obuf[5] = 'A';
uart1obuf[6] = ':';
*OutBytes = 7;
switch (Destination) {
case 1: memcpy (&uart1obuf[7], PROTOCESSORFFP485_1AR, strlen (PROTOCESSORFFP485_1AR));
(*OutBytes) += strlen (PROTOCESSORFFP485_1AR);
break;
case 2: memcpy (&uart1obuf[7], PROTOCESSORFFP485_2AR, strlen (PROTOCESSORFFP485_2AR));
(*OutBytes) += strlen (PROTOCESSORFFP485_2AR);
break;
default: break;
}
uart1obuf[(*OutBytes)++] = ',';
uart1obuf[(*OutBytes)++] = 'O';
uart1obuf[(*OutBytes)++] = 'F';
uart1obuf[(*OutBytes)++] = ':';
(*OutBytes) += sprintf (&uart1obuf[*OutBytes], "%d", Offset);
if (Wr) {
uart1obuf[(*OutBytes)++] = ',';
uart1obuf[(*OutBytes)++] = 'V';
uart1obuf[(*OutBytes)++] = 'A';
uart1obuf[(*OutBytes)++] = ':';
switch (Format[0]) {
case 'D': (*OutBytes) += sprintf (&uart1obuf[*OutBytes], "%d", *((int *)Data));
break;
case 'U': (*OutBytes) += sprintf (&uart1obuf[*OutBytes], "%u", *((unsigned int *)Data));
break;
case 'F': (*OutBytes) += sprintf (&uart1obuf[*OutBytes], "%f", *((float *)Data));
break;
default: (*OutBytes) += sprintf (&uart1obuf[*OutBytes], "%d", (int)*((unsigned char *)Data));
break;
}
}
switch (Format[0]) {
case 'D': uart1obuf[(*OutBytes)++] = ',';
uart1obuf[(*OutBytes)++] = 'F';
uart1obuf[(*OutBytes)++] = 'M';
uart1obuf[(*OutBytes)++] = 'T';
uart1obuf[(*OutBytes)++] = ':';
uart1obuf[(*OutBytes)++] = 'D';
break;
case 'U': uart1obuf[(*OutBytes)++] = ',';
uart1obuf[(*OutBytes)++] = 'F';
uart1obuf[(*OutBytes)++] = 'M';
uart1obuf[(*OutBytes)++] = 'T';
uart1obuf[(*OutBytes)++] = ':';
uart1obuf[(*OutBytes)++] = 'U';
break;
case 'F': uart1obuf[(*OutBytes)++] = ',';
uart1obuf[(*OutBytes)++] = 'F';
uart1obuf[(*OutBytes)++] = 'M';
uart1obuf[(*OutBytes)++] = 'T';
uart1obuf[(*OutBytes)++] = ':';
uart1obuf[(*OutBytes)++] = 'F';
break;
default: break;
}
uart1obuf[(*OutBytes)++] = 0x0D;
}
//-------------------------------------------------------------
/*void ResetOut (unsigned char *Format, void *Out)
{
switch (Format[0]) {
case 'D':
case 'U':
*((int *)Out) = 0;
break;
case 'F': *((float *)Out) = 0;
break;
default: *((unsigned char *)Out) = 0;
break;
}
}*/
//-------------------------------------------------------------
void DecodeResponse (unsigned char Wr, int *Error, unsigned char *Format, void *Out)
{
if (!strncmp(uart1ibuf, ":ERR", 4)) {
*Error = atoi (&uart1ibuf[4]);//sscanf (&uart1ibuf[4], "%d", Error);
// ResetOut (Format, Out);
return;
}
if (Wr) {
if (strncmp(uart1ibuf, ":OK", 3) && !*Error) {
*Error = PROTOCESSORFFP485_WERR;
}
return;
}
switch (Format[0]) {
case 'D': *((int *)Out) = atoi (&uart1ibuf[1]);//sscanf (&uart1ibuf[1], "%d", ((int *)Out));
break;
case 'U': *((int *)Out) = atoi (&uart1ibuf[1]);//sscanf (&uart1ibuf[1], "%u", ((unsigned int *)Out));
break;
case 'F': *((float *)Out) = atof (&uart1ibuf[1]);//sscanf (&uart1ibuf[1], "%f", ((float *)Out));
break;
default: *((unsigned char *)Out) = atoi (&uart1ibuf[1]);//sscanf (&uart1ibuf[1], "%c", ((unsigned char *)Out));
break;
}
}
#endif
#ifndef USEPC485INIT
#define USEPC485INIT
void _PC485INIT(void)
{
BlocksCount = 1; TimeoutCounter=0; CommandOK=0; SFRPAGE=1; SCON1=0x10; SFRPAGE=0; CKCON=1; TH1=0x70; //CycleCnt=0;
}
#endif
#ifndef USEPC485WRITEANALOG
#define USEPC485WRITEANALOG
xdata unsigned int _PC485WRITEANALOG_BLOCKID;
void _PC485WRITEANALOG(int Offset, float Data, unsigned char Wrpr, int *Error)
{
#define xdata
unsigned char result = false;
unsigned char Outbytes;
if (!_Inited)
_PC485WRITEANALOG_BLOCKID = BlocksCount++;
if (Wrpr && CommandOK != _PC485WRITEANALOG_BLOCKID)
return;
if (CommandOK == 0 || CommandOK == _PC485WRITEANALOG_BLOCKID) {
CommandOK = _PC485WRITEANALOG_BLOCKID;
FormQueryFrame (PROTOCESSORFFP485_WF, 1, Offset, (void *)&Data, "F", &Outbytes);
result = SendToProtocessorFFP485 (Outbytes);
if (result) {
*Error = 0;
DecodeResponse (PROTOCESSORFFP485_WF, Error, "F", NULL);
TimeoutCounter = 0;
CommandOK = 0;
}
if (TimeoutCounter > 10) {
TimeoutCounter = 0;
CommandOK = 0;
*Error = PROTOCESSORFFP485_LERR;
}
}
}
#endif
#ifndef USEPC485READANALOG
#define USEPC485READANALOG
xdata unsigned int _PC485READANALOG_BLOCKID;
void _PC485READANALOG(int Offset, float *Out, int *Error)
{
#define xdata
unsigned char result = false;
unsigned char Outbytes;
if (!_Inited)
_PC485READANALOG_BLOCKID = BlocksCount++;
if (CommandOK == 0 || CommandOK == _PC485READANALOG_BLOCKID) {
CommandOK = _PC485READANALOG_BLOCKID;
FormQueryFrame (PROTOCESSORFFP485_RF, 1, Offset, NULL, "F", &Outbytes);
result = SendToProtocessorFFP485 (Outbytes);
if (result) {
*Error = 0;
DecodeResponse (PROTOCESSORFFP485_RF, Error, "F", (void *)Out);
TimeoutCounter = 0;
CommandOK = 0;
}
if (TimeoutCounter > 10) {
TimeoutCounter = 0;
CommandOK = 0;
*Error = PROTOCESSORFFP485_LERR;
}
}
}
#endif
#ifndef USEEQUALI
#define USEEQUALI
#define _EQUALI(X1,X2,Z) Z=(X1==(X2))
#endif
//-------------------------------------------------------------
#ifndef USENOR
#define USENOR
void _NOR(unsigned char* X, unsigned char* Y)
{
#define xdata
int i;
unsigned char Result;
unsigned char* InpArr;
if(X != NULL)
{
Result = false;
InpArr = (unsigned char*)&X[1];
for(i = 0; i < X[0]; i++)
Result = Result||InpArr[i];
*Y = !Result;
}
}
#endif
#ifndef USEPC485READBIT
#define USEPC485READBIT
xdata unsigned int _PC485READBIT_BLOCKID;
void _PC485READBIT(int Offset, unsigned char *Out, int *Error)
{
#define xdata
unsigned char result = false;
unsigned char Outbytes;
if (!_Inited)
_PC485READBIT_BLOCKID = BlocksCount++;
if (CommandOK == 0 || CommandOK == _PC485READBIT_BLOCKID) {
CommandOK = _PC485READBIT_BLOCKID;
FormQueryFrame (PROTOCESSORFFP485_RF, 2, Offset, NULL, NULL, &Outbytes);
result = SendToProtocessorFFP485 (Outbytes);
if (result) {
*Error = 0;
DecodeResponse (PROTOCESSORFFP485_RF, Error, NULL, (void *)Out);
TimeoutCounter = 0;
CommandOK = 0;
}
if (TimeoutCounter > 10) {
TimeoutCounter = 0;
CommandOK = 0;
*Error = PROTOCESSORFFP485_LERR;
}
}
}
#endif
#ifndef USEPC485WRITEBIT
#define USEPC485WRITEBIT
xdata unsigned int _PC485WRITEBIT_BLOCKID;
void _PC485WRITEBIT(int Offset, unsigned char Data, unsigned char Wrpr, int *Error)
{
#define xdata
unsigned char result = false;
unsigned char Outbytes;
if (!_Inited)
_PC485WRITEBIT_BLOCKID = BlocksCount++;
if (Wrpr && CommandOK != _PC485WRITEBIT_BLOCKID)
return;
if (CommandOK == 0 || CommandOK == _PC485WRITEBIT_BLOCKID) {
CommandOK = _PC485WRITEBIT_BLOCKID;
FormQueryFrame (PROTOCESSORFFP485_WF, 2, Offset, (void *)&Data, NULL, &Outbytes);
result = SendToProtocessorFFP485 (Outbytes);
if (result) {
*Error = 0;
DecodeResponse (PROTOCESSORFFP485_WF, Error, NULL, NULL);
TimeoutCounter = 0;
CommandOK = 0;
}
if (TimeoutCounter > 10) {
TimeoutCounter = 0;
CommandOK = 0;
*Error = PROTOCESSORFFP485_LERR;
}
}
}
#endif
//-----------------------------------------------------------
#ifndef USEDECODER
#define USEDECODER
void _DECODER(int X, unsigned char* Z)
{
#define xdata
int i;
unsigned char* OutArr = &Z[1];
for(i = 0; i < Z[0]; i++)
OutArr[i] = ( (X & (1 << i)) != false );
}
#endif
#ifndef USESANTISHORT
#define USESANTISHORT
xdata float _ANTISHORT_TIME;
xdata unsigned char _ANTISHORT_ZN_1;
void _ANTISHORT (unsigned char Q, float MinOn, float MinOff, unsigned char *Z)
{
if (!_Inited) {
_ANTISHORT_TIME = 0;
_ANTISHORT_ZN_1 = false;
}
_ANTISHORT_TIME -= _CYCLE;
if (_ANTISHORT_TIME <= 0)
*Z = Q;
if (*Z && !_ANTISHORT_ZN_1)
_ANTISHORT_TIME = MinOn;
if (!(*Z) && _ANTISHORT_ZN_1)
_ANTISHORT_TIME = MinOff;
_ANTISHORT_ZN_1 = *Z;
}
#endif
//------------------------------------------------------------
void _10ms_func()
{
#define xdata
char _SAVE_INNUM, _SAVE_OUTNUM;
_10ms_Inited = true;
}
//--------------------------------------------------------
void TENMS()
{
_10ms_func();
}
//-------------------------------------------------
#if defined(DEVICE_ME20) || defined(DEVICE_MC5) || defined(DEVICE_MC6) || defined(DEVICE_MR8M)
xdata unsigned char _int_1ms_count;
#endif
void _1ms_func()
{
#define xdata
char _SAVE_INNUM, _SAVE_OUTNUM;
#if defined(DEVICE_ME20) || defined(DEVICE_MC5) || defined(DEVICE_MC1) || defined(DEVICE_MR8M)
_int_1ms_count++;
if(_int_1ms_count >= 10)
{
_int_1ms_count = 0;
quasi_10ms_func();
}
#endif
}
//---------------------------------------------------------
void ONEMS()
{
_1ms_func();
}
//------------------------------------------------------
void UART1_func()
{
_PC485SERVICE();
SCON1 &= 0xfc;
}
//--------------------------------------------------------
void UART1()
{
UART1_func();
}
//-----------Initialization unit----------------
#ifndef STRINGHINCLUDED
#define STRINGHINCLUDED
#include <string.h>
#endif
void INIT_func()
{
#define xdata
int _counter;
#ifdef _TimesCount
struct Timers xdata *TimersPtr;
#endif
/* #ifdef BOOLCOUNTO
for(_counter = 0; _counter < BOOLCOUNTO; _counter++)
BOOLARRO[_counter] = 0;
#endif
#ifdef BOOLCOUNTN
for(_counter = 0; _counter < BOOLCOUNTN; _counter++)
BOOLARRN[_counter] = 0;
#endif
#ifdef INTCOUNTO
for(_counter = 0; _counter < INTCOUNTO; _counter++)
INTARRO[_counter] = 0;
#endif
#ifdef INTCOUNTN
for(_counter = 0; _counter < INTCOUNTN; _counter++)
INTARRN[_counter] = 0;
#endif
#ifdef FLOATCOUNTO
for(_counter = 0; _counter < FLOATCOUNTO; _counter++)
FLOATARRO[_counter] = 0;
#endif
#ifdef FLOATCOUNTN
for(_counter = 0; _counter < FLOATCOUNTN; _counter++)
FLOATARRN[_counter] = 0;
#endif
#ifdef TIMECOUNTO
for(_counter = 0; _counter < TIMECOUNTO; _counter++)
TIMEARRO[_counter] = 0;
#endif
#ifdef TIMECOUNTN
for(_counter = 0; _counter < TIMECOUNTN; _counter++)
TIMEARRN[_counter] = 0;
#endif
#ifdef DATECOUNTO
for(_counter = 0; _counter < DATECOUNTO; _counter++)
DATEARRO[_counter] = 0;
#endif
#ifdef DATECOUNTN
for(_counter = 0; _counter < DATECOUNTN; _counter++)
DATEARRN[_counter] = 0;
#endif
#ifdef BOOLCOUNTAO
for(_counter = 0; _counter < BOOLCOUNTAO; _counter++)
BOOLARRAO[_counter] = 0;
#endif
#ifdef BOOLCOUNTAN
for(_counter = 0; _counter < BOOLCOUNTAN; _counter++)
BOOLARRAN[_counter] = 0;
#endif
#ifdef INTCOUNTAO
for(_counter = 0; _counter < INTCOUNTAO; _counter++)
INTARRAO[_counter] = 0;
#endif
#ifdef INTCOUNTAN
for(_counter = 0; _counter < INTCOUNTAN; _counter++)
INTARRAN[_counter] = 0;
#endif
#ifdef FLOATCOUNTAO
for(_counter = 0; _counter < FLOATCOUNTAO; _counter++)
FLOATARRAO[_counter] = 0;
#endif
#ifdef FLOATCOUNTAN
for(_counter = 0; _counter < FLOATCOUNTAN; _counter++)
FLOATARRAN[_counter] = 0;
#endif
#ifdef DATECOUNTAO
for(_counter = 0; _counter < DATECOUNTAO; _counter++)
DATEARRAO[_counter] = 0;
#endif
#ifdef DATECOUNTAN
for(_counter = 0; _counter < DATECOUNTAN; _counter++)
DATEARRAN[_counter] = 0;
#endif
#ifdef TIMECOUNTAO
for(_counter = 0; _counter < TIMECOUNTAO; _counter++)
TIMEARRAO[_counter] = 0;
#endif
#ifdef TIMECOUNTAN
for(_counter = 0; _counter < TIMECOUNTAN; _counter++)
TIMEARRAN[_counter] = 0;
#endif*/
memset(TempZone, 0, TempZoneSize);
#ifdef _TimesCount
TimersPtr = &begram + AddrTimerStruct;
for(_counter = 0; _counter < _TimesCount; _counter++)
{
TimersPtr->Status = 0;
TimersPtr->Delay = 0;
TimersPtr++;
}
#endif
#ifdef _DACCount
for(_counter = 0; _counter < _DACCount; _counter++)
AO(_counter)=0;
#endif
_INNUM = -1;
_OUTNUM = -1;
_PC485INIT();
#if defined(DEVICE_MC8)
#ifdef IS_SLAVE
SLAVE = IS_SLAVE;
#endif
#endif
_Inited = false;
_10ms_Inited = false;
}
//----------------------------------------------------
void INIT()
{
INIT_func();
}
//----------Getting Digital Inputs--------------------
void _GETDIS()
{
DI[0] = Dinput_0;
DI[1] = Dinput_1;
DI[2] = Dinput_2;
DI[3] = Dinput_3;
}
//-------------------------------------------------------------------
typedef void (*MagicFuncTyp)(void);
#include <intrins.h>
xdata int CheckAllTheFloats_i;
xdata unsigned char CheckAllTheFloats_ch_res;
xdata MagicFuncTyp CheckAllTheFloats_MagicFunc;
xdata unsigned char CheckAllTheFloats_Counter;
xdata unsigned char CheckAllTheFloats_OK;
void CheckAllTheFloats()
{
if(!_Inited)
CheckAllTheFloats_Counter = 0;
CheckAllTheFloats_OK = true;
#ifdef FLOATCOUNTO
for(CheckAllTheFloats_i=0; CheckAllTheFloats_i<FLOATCOUNTO;CheckAllTheFloats_i++)
{
CheckAllTheFloats_ch_res = _chkfloat_(FLOATARRO[CheckAllTheFloats_i]);
if(!(CheckAllTheFloats_ch_res==0 || CheckAllTheFloats_ch_res==1))
{
if(CheckAllTheFloats_Counter > 100)
{
CheckAllTheFloats_MagicFunc = 0;
CheckAllTheFloats_MagicFunc();
}
else{
FLOATARRO[CheckAllTheFloats_i] = 0;
if(CheckAllTheFloats_OK)
CheckAllTheFloats_Counter++;
}
CheckAllTheFloats_OK = false;
}
}
if(CheckAllTheFloats_OK)
CheckAllTheFloats_Counter = 0;
#endif
#ifdef FLOATCOUNTL
for(CheckAllTheFloats_i=0; CheckAllTheFloats_i<FLOATCOUNTL;CheckAllTheFloats_i++)
{
CheckAllTheFloats_ch_res = _chkfloat_(FLOATARRL[CheckAllTheFloats_i]);
if(!(CheckAllTheFloats_ch_res==0 || CheckAllTheFloats_ch_res==1))
{
if(CheckAllTheFloats_Counter > 100)
{
CheckAllTheFloats_MagicFunc = 0;
CheckAllTheFloats_MagicFunc();
}
else{
FLOATARRL[CheckAllTheFloats_i] = 0;
if(CheckAllTheFloats_OK)
CheckAllTheFloats_Counter++;
}
CheckAllTheFloats_OK = false;
}
}
if(CheckAllTheFloats_OK)
CheckAllTheFloats_Counter = 0;
#endif
#ifdef FLOATCOUNTN
for(CheckAllTheFloats_i=0;CheckAllTheFloats_i<FLOATCOUNTN;CheckAllTheFloats_i++)
{
CheckAllTheFloats_ch_res = _chkfloat_(FLOATARRN[CheckAllTheFloats_i]);
if(!(CheckAllTheFloats_ch_res==0 || CheckAllTheFloats_ch_res==1))
FLOATARRN[CheckAllTheFloats_i] = 0;
}
#endif
#ifdef FCELLCOUNT
for(CheckAllTheFloats_i=0;CheckAllTheFloats_i<FCELLCOUNT;CheckAllTheFloats_i++)
{
CheckAllTheFloats_ch_res = _chkfloat_(FLOATCELLS[CheckAllTheFloats_i]);
if(!(CheckAllTheFloats_ch_res==0 || CheckAllTheFloats_ch_res==1))
FLOATCELLS[CheckAllTheFloats_i] = 0;
}
#endif
}
//-------------------------------------------------------------------
xdata unsigned int RestoreStatics_Counter;
#define _StaticsWithZF (_ALLTHESTATICS + _ZFSavedBytes)
xdata char _RAMSavedPtr[_StaticsWithZF] _at_ _RAMSavedLoc;
code char _ROMSavedPtr[_StaticsWithZF] _at_ _ROMSavedLoc;
void RestoreStatics()
{
xdata int i;
xdata unsigned char OK;
#ifdef DEVICE_MC8_125
PSBANK=0x21;
#endif
if(!_Inited)
RestoreStatics_Counter = 0;
OK = true;
for(i = 0; i < _StaticsWithZF; i++)
{
if(_RAMSavedPtr[i] != _ROMSavedPtr[i])
{
RestoreStatics_Counter++;
OK = false;
break;
}
}
if(OK)
RestoreStatics_Counter = 0;
if(RestoreStatics_Counter > (6000/_CYCLEINT))
{
for(i = 0; i < _StaticsWithZF; i++)
_RAMSavedPtr[i] = _ROMSavedPtr[i];
RestoreStatics_Counter = 0;
}
#ifdef DEVICE_MC8_125
PSBANK=0x11;
#endif
}
//-------------------------------------------------------------------
#if _ALLTHERETAINS>0
xdata char _RAMRetainPtr[_ALLTHERETAINS] _at_ _RAMSavedLoc;
code char _ROMRetainPtr[_ALLTHERETAINS] _at_ _ROMSavedLoc;
void SaveRetains()
{
#define xdata
int i;
#ifdef DEVICE_MC8_125
PSBANK=0x21;
#endif
for(i = 0; i < _ALLTHERETAINS; i++)
{
if(_RAMRetainPtr[i+_ALLTHESTATICS] != _ROMRetainPtr[i+_ALLTHESTATICS])
{
_Save_Command = 0x5555;
break;
}
}
#ifdef DEVICE_MC8_125
PSBANK=0x11;
#endif
}
#endif
//-------------------------------------------------------------------
void main_func()
{
#define xdata
char _SAVE_INNUM, _SAVE_OUTNUM;
static unsigned char CylclesPassed;
if(CylclesPassed < 3)
{
CylclesPassed++;
return;
}
#if _ALLTHESTATICS>0
RestoreStatics();
#endif
#if _ALLTHERETAINS>0
SaveRetains();
#endif
CheckAllTheFloats();
_GETDIS();
#ifdef DEVICE_MC5
_ADCService();
#endif
#ifdef DEVICE_MC1
_ADCService();
#endif
#ifdef DEVICE_MC6
_ADCService();
#endif
_CONDITIONAL(-1,1,FALSE,FLOATARRO[9]);
_BUTTON_PREVIOUS = X53700776_PREVIOUS;
_BUTTON(FALSE,&BOOLARRO[3]);
X53700776_PREVIOUS = _BUTTON_PREVIOUS;
_BOOLVAR(FALSE,BOOLARRO[4]);
_VALUEVAR(0,FLOATARRO[16]);
_VALUEVAR(0,FLOATARRO[17]);
_VALUEVAR(0,FLOATARRO[18]);
_VALUEVAR(0,FLOATARRO[19]);
_THERMISTORBR_FAUL = X34078064_FAUL;
_THERMISTORBR_INPUTN_1 = X34078064_INPUTN_1;
_THERMISTORBR_STORAGE = X34078064_STORAGE;
_THERMISTORBR_FLAG = X34078064_FLAG;
_THERMISTORBR_EXCN_1 = X34078064_EXCN_1;
_SAVE_INNUM = _INNUM;
_INNUM = 0;
_THERMISTORBR(AI(0),&FFLOATBLANK,&FFLOATBLANK,&BBOOLBLANK,0);
X34078064_FAUL = _THERMISTORBR_FAUL;
X34078064_INPUTN_1 = _THERMISTORBR_INPUTN_1;
X34078064_STORAGE = _THERMISTORBR_STORAGE;
X34078064_FLAG = _THERMISTORBR_FLAG;
X34078064_EXCN_1 = _THERMISTORBR_EXCN_1;
_INNUM = _SAVE_INNUM;
_THERMISTORBR_FAUL = X25528264_FAUL;
_THERMISTORBR_INPUTN_1 = X25528264_INPUTN_1;
_THERMISTORBR_STORAGE = X25528264_STORAGE;
_THERMISTORBR_FLAG = X25528264_FLAG;
_THERMISTORBR_EXCN_1 = X25528264_EXCN_1;
_SAVE_INNUM = _INNUM;
_INNUM = 1;
_THERMISTORBR(AI(1),&FLOATARRO[20],&FFLOATBLANK,&BOOLARRO[5],0);
X25528264_FAUL = _THERMISTORBR_FAUL;
X25528264_INPUTN_1 = _THERMISTORBR_INPUTN_1;
X25528264_STORAGE = _THERMISTORBR_STORAGE;
X25528264_FLAG = _THERMISTORBR_FLAG;
X25528264_EXCN_1 = _THERMISTORBR_EXCN_1;
_INNUM = _SAVE_INNUM;
_BOOLVAR(BOOLARRO[3],BOOLARRO[13]);
_PC485WRITEANALOG_BLOCKID = X53412616_BLOCKID;
_PC485WRITEANALOG(0,FLOATARRO[19],FALSE,&INTARRO[0]);
X53412616_BLOCKID = _PC485WRITEANALOG_BLOCKID;
_PC485READANALOG_BLOCKID = X53414548_BLOCKID;
_PC485READANALOG(0,&FFLOATBLANK,&INTARRO[1]);
X53414548_BLOCKID = _PC485READANALOG_BLOCKID;
_PC485WRITEANALOG_BLOCKID = X53415124_BLOCKID;
_PC485WRITEANALOG(0,FLOATARRO[18],FALSE,&INTARRO[2]);
X53415124_BLOCKID = _PC485WRITEANALOG_BLOCKID;
_EQUALI(INTARRO[0],0,BOOLARRO[19]);
_EQUALI(INTARRO[2],0,BOOLARRO[21]);
_PC485READBIT_BLOCKID = X48414408_BLOCKID;
_PC485READBIT(0,&BBOOLBLANK,&INTARRO[3]);
X48414408_BLOCKID = _PC485READBIT_BLOCKID;
_PC485READBIT_BLOCKID = X53741192_BLOCKID;
_PC485READBIT(0,&BBOOLBLANK,&INTARRO[4]);
X53741192_BLOCKID = _PC485READBIT_BLOCKID;
_PC485READBIT_BLOCKID = X53460520_BLOCKID;
_PC485READBIT(0,&BBOOLBLANK,&INTARRO[5]);
X53460520_BLOCKID = _PC485READBIT_BLOCKID;
_PC485READANALOG_BLOCKID = X48422568_BLOCKID;
_PC485READANALOG(0,&FFLOATBLANK,&INTARRO[6]);
X48422568_BLOCKID = _PC485READANALOG_BLOCKID;
_PC485WRITEBIT_BLOCKID = X48436796_BLOCKID;
_PC485WRITEBIT(0,FALSE,FALSE,&INTARRO[7]);
X48436796_BLOCKID = _PC485WRITEBIT_BLOCKID;
_PC485WRITEBIT_BLOCKID = X48438080_BLOCKID;
_PC485WRITEBIT(0,FALSE,FALSE,&INTARRO[8]);
X48438080_BLOCKID = _PC485WRITEBIT_BLOCKID;
_EQUALI(INTARRO[8],0,BOOLARRO[23]);
_EQUALI(INTARRO[3],0,BOOLARRO[26]);
_EQUALI(INTARRO[4],0,BOOLARRO[27]);
_PC485READANALOG_BLOCKID = X48503916_BLOCKID;
_PC485READANALOG(0,&FFLOATBLANK,&INTARRO[10]);
X48503916_BLOCKID = _PC485READANALOG_BLOCKID;
_EQUALI(INTARRO[5],0,BOOLARRO[28]);
_EQUALI(INTARRO[1],0,BOOLARRO[29]);
_EQUALI(INTARRO[6],0,BOOLARRO[30]);
_PC485WRITEANALOG_BLOCKID = X48585676_BLOCKID;
_PC485WRITEANALOG(0,0,FALSE,&IINTBLANK);
X48585676_BLOCKID = _PC485WRITEANALOG_BLOCKID;
_PC485WRITEBIT_BLOCKID = X48577916_BLOCKID;
_PC485WRITEBIT(0,FALSE,FALSE,&IINTBLANK);
X48577916_BLOCKID = _PC485WRITEBIT_BLOCKID;
_PC485READANALOG_BLOCKID = X48395640_BLOCKID;
_PC485READANALOG(0,&FFLOATBLANK,&IINTBLANK);
X48395640_BLOCKID = _PC485READANALOG_BLOCKID;
_PC485READBIT_BLOCKID = X48450212_BLOCKID;
_PC485READBIT(0,&BBOOLBLANK,&IINTBLANK);
X48450212_BLOCKID = _PC485READBIT_BLOCKID;
_NOT(BOOLARRO[4],BOOLARRO[31]);
_ARR0[0] = 1;
_DECODER(0,_ARR0);
BBOOLPTR = (unsigned char*)&_ARR0[1];
BOOLARRAO[0] = *BBOOLPTR;
_ALARMFORM_COUNT = X53604948_COUNT;
_SAVE_INNUM = _INNUM;
_INNUM = 1;
_ALARMFORM(DI(1),&BOOLARRO[32],0,0,0,BOOLARRO[3]);
X53604948_COUNT = _ALARMFORM_COUNT;
_INNUM = _SAVE_INNUM;
_ALARMFORM_COUNT = X53516744_COUNT;
_SAVE_INNUM = _INNUM;
_INNUM = 0;
_ALARMFORM(DI(0),&BOOLARRO[33],0,0,0,BOOLARRO[3]);
X53516744_COUNT = _ALARMFORM_COUNT;
_INNUM = _SAVE_INNUM;
_ALARMFORM_COUNT = X53568164_COUNT;
_SAVE_INNUM = _INNUM;
_INNUM = 2;
_ALARMFORM(DI(2),&BOOLARRO[34],0,0,0,BOOLARRO[3]);
X53568164_COUNT = _ALARMFORM_COUNT;
_INNUM = _SAVE_INNUM;
_ANTISHORT_TIME = X53536616_TIME;
_ANTISHORT_ZN_1 = X53536616_ZN_1;
_SAVE_INNUM = _INNUM;
_INNUM = 3;
_ANTISHORT(DI(3),0,0,&BOOLARRO[35]);
X53536616_TIME = _ANTISHORT_TIME;
X53536616_ZN_1 = _ANTISHORT_ZN_1;
_INNUM = _SAVE_INNUM;
_ARR0[0] = 1;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
_ARR1[0] = 1;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = 0;
_PIECEWISE(FLOATARRO[19],&FLOATARRO[2],_ARR0,_ARR1);
_VALUEVAR(FLOATARRO[2],FLOATARRO[5]);
_VALUEVAR(FLOATARRO[20],FLOATARRO[6]);
_ARR0[0] = 2;
BBOOLPTR = (unsigned char*)&_ARR0[1];
*BBOOLPTR = BOOLARRO[32];
BBOOLPTR = (unsigned char*)&_ARR0[2];
*BBOOLPTR = BOOLARRO[34];
_OR(_ARR0,&BOOLARRO[0]);
_CONDITIONAL(0,0,BOOLARRO[33],FLOATARRO[14]);
_ALARMFORM_COUNT = X53634564_COUNT;
_ALARMFORM(BOOLARRO[5],&BOOLARRO[6],0,0,0,BOOLARRO[13]);
X53634564_COUNT = _ALARMFORM_COUNT;
_ALARMFORM_COUNT = X53610812_COUNT;
_ALARMFORM(BOOLARRAO[0],&BOOLARRO[7],0,0,0,BOOLARRO[13]);
X53610812_COUNT = _ALARMFORM_COUNT;
_RSTRIGGER(BOOLARRO[6],BOOLARRO[13],&BOOLARRO[8]);
_RSTRIGGER(BOOLARRO[7],BOOLARRO[13],&BOOLARRO[9]);
_ALARMFORM_COUNT = X53797644_COUNT;
_ALARMFORM(BOOLARRO[32],&BOOLARRO[12],0,0,0,BOOLARRO[13]);
X53797644_COUNT = _ALARMFORM_COUNT;
_EQUALI(INTARRO[7],0,BOOLARRO[22]);
_PC485WRITEBIT_BLOCKID = X48453704_BLOCKID;
_PC485WRITEBIT(0,BOOLARRO[31],FALSE,&INTARRO[9]);
X48453704_BLOCKID = _PC485WRITEBIT_BLOCKID;
_EQUALI(INTARRO[9],0,BOOLARRO[24]);
_EQUALI(INTARRO[10],0,BOOLARRO[25]);
_FILTER(FLOATARRO[6],&FLOATARRO[4],2);
_RSTRIGGER(BOOLARRO[12],BOOLARRO[13],&BOOLARRO[10]);
_ARR0[0] = 11;
BBOOLPTR = (unsigned char*)&_ARR0[1];
*BBOOLPTR = BOOLARRO[19];
BBOOLPTR = (unsigned char*)&_ARR0[2];
*BBOOLPTR = BOOLARRO[21];
BBOOLPTR = (unsigned char*)&_ARR0[3];
*BBOOLPTR = BOOLARRO[22];
BBOOLPTR = (unsigned char*)&_ARR0[4];
*BBOOLPTR = BOOLARRO[23];
BBOOLPTR = (unsigned char*)&_ARR0[5];
*BBOOLPTR = BOOLARRO[24];
BBOOLPTR = (unsigned char*)&_ARR0[6];
*BBOOLPTR = BOOLARRO[25];
BBOOLPTR = (unsigned char*)&_ARR0[7];
*BBOOLPTR = BOOLARRO[26];
BBOOLPTR = (unsigned char*)&_ARR0[8];
*BBOOLPTR = BOOLARRO[27];
BBOOLPTR = (unsigned char*)&_ARR0[9];
*BBOOLPTR = BOOLARRO[28];
BBOOLPTR = (unsigned char*)&_ARR0[10];
*BBOOLPTR = BOOLARRO[29];
BBOOLPTR = (unsigned char*)&_ARR0[11];
*BBOOLPTR = BOOLARRO[30];
_NOR(_ARR0,&BOOLARRO[20]);
_UNBALANSE(FLOATARRO[5],FLOATARRO[4],FLOATARRO[3]);
_ARR0[0] = 2;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = FLOATARRO[3];
FFLOATPTR = (float*)&_ARR0[5];
*FFLOATPTR = FLOATARRO[9];
_MULT(_ARR0,&FLOATARRO[8]);
_ARR0[0] = 1;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
_ARR1[0] = 1;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = 0;
_PIECEWISE(FLOATARRO[3],&FLOATARRO[10],_ARR0,_ARR1);
_SAVE_OUTNUM = _OUTNUM;
_OUTNUM = 0;
_ARR0[0] = 2;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
FFLOATPTR = (float*)&_ARR0[5];
*FFLOATPTR = 100;
_ARR1[0] = 2;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = 0;
FFLOATPTR = (float*)&_ARR1[5];
*FFLOATPTR = FLOATARRO[10];
_PIECEWISE(FLOATARRO[17],&FLOATARRO[13],_ARR0,_ARR1);
_OUTNUM = _SAVE_OUTNUM;
AO(0) = FLOATARRO[13];
_ALARMFORM_COUNT = X53831064_COUNT;
_ALARMFORM(BOOLARRO[20],&BOOLARRO[15],0,0,0,BOOLARRO[13]);
X53831064_COUNT = _ALARMFORM_COUNT;
_ARR0[0] = 2;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
FFLOATPTR = (float*)&_ARR0[5];
*FFLOATPTR = 100;
_ARR1[0] = 2;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = FLOATARRO[14];
FFLOATPTR = (float*)&_ARR1[5];
*FFLOATPTR = FLOATARRO[10];
_PIECEWISE(FLOATARRO[18],&FLOATARRO[0],_ARR0,_ARR1);
_ARR0[0] = 2;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
FFLOATPTR = (float*)&_ARR0[5];
*FFLOATPTR = 100;
_ARR1[0] = 2;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = 0;
FFLOATPTR = (float*)&_ARR1[5];
*FFLOATPTR = 100;
_PIECEWISE(FLOATARRO[0],&FLOATARRO[1],_ARR0,_ARR1);
_PID2AOOVR_YIN_1 = X53376856_YIN_1;
_PID2AOOVR_XN_1 = X53376856_XN_1;
_PID2AOOVR_YD1N_1 = X53376856_YD1N_1;
_PID2AOOVR_YAN_1 = X53376856_YAN_1;
_PID2AOOVR_YULM = X53376856_YULM;
_PID2AOOVR(FLOATARRO[8],&FLOATARRO[7],&FFLOATBLANK,FALSE,0.5,2.5,300,0,0,100,BOOLARRO[0],0);
X53376856_YIN_1 = _PID2AOOVR_YIN_1;
X53376856_XN_1 = _PID2AOOVR_XN_1;
X53376856_YD1N_1 = _PID2AOOVR_YD1N_1;
X53376856_YAN_1 = _PID2AOOVR_YAN_1;
X53376856_YULM = _PID2AOOVR_YULM;
_ARR0[0] = 1;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
_ARR1[0] = 1;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = 0;
_PIECEWISE(FLOATARRO[7],&FLOATARRO[11],_ARR0,_ARR1);
_CONDITIONAL(FLOATARRO[11],0,BOOLARRO[4],FLOATARRO[12]);
_ARR0[0] = 1;
FFLOATPTR = (float*)&_ARR0[1];
*FFLOATPTR = 0;
_ARR1[0] = 1;
FFLOATPTR = (float*)&_ARR1[1];
*FFLOATPTR = 0;
_PIECEWISE(FLOATARRO[7],&FFLOATBLANK,_ARR0,_ARR1);
_RSTRIGGER(BOOLARRO[15],BOOLARRO[13],&BOOLARRO[11]);
_ARR0[0] = 4;
BBOOLPTR = (unsigned char*)&_ARR0[1];
*BBOOLPTR = BOOLARRO[8];
BBOOLPTR = (unsigned char*)&_ARR0[2];
*BBOOLPTR = BOOLARRO[9];
BBOOLPTR = (unsigned char*)&_ARR0[3];
*BBOOLPTR = BOOLARRO[10];
BBOOLPTR = (unsigned char*)&_ARR0[4];
*BBOOLPTR = BOOLARRO[11];
_OR(_ARR0,&BOOLARRO[14]);
_ARR0[0] = 2;
BBOOLPTR = (unsigned char*)&_ARR0[1];
*BBOOLPTR = BOOLARRO[14];
BBOOLPTR = (unsigned char*)&_ARR0[2];
*BBOOLPTR = FALSE;
_SAVE_OUTNUM = _OUTNUM;
_OUTNUM = 1;
_OR(_ARR0,&BOOLARRO[16]);
_OUTNUM = _SAVE_OUTNUM;
DO(1) = BOOLARRO[16];
_NOT(BOOLARRO[14],BOOLARRO[17]);
_ARR0[0] = 2;
BBOOLPTR = (unsigned char*)&_ARR0[1];
*BBOOLPTR = BOOLARRO[35];
BBOOLPTR = (unsigned char*)&_ARR0[2];
*BBOOLPTR = BOOLARRO[17];
_AND(_ARR0,&BOOLARRO[18]);
_PWM2_TIME = X53327236_TIME;
_PWM2_STATE = X53327236_STATE;
_PWM2(FLOATARRO[16],FLOATARRO[12],&PWM2ARRO[0]);
X53327236_TIME = _PWM2_TIME;
X53327236_STATE = _PWM2_STATE;
_BOOLVAR(BOOLARRO[18],BOOLARRO[1]);
_SAVE_OUTNUM = _OUTNUM;
_OUTNUM = 0;
_CONDB(PWM2ARRO[0],FALSE,BOOLARRO[1],BOOLARRO[2]);
_OUTNUM = _SAVE_OUTNUM;
DO(0) = BOOLARRO[2];
_SAVE_OUTNUM = _OUTNUM;
_OUTNUM = 1;
_CONDITIONAL(FLOATARRO[1],0,BOOLARRO[1],FLOATARRO[15]);
_OUTNUM = _SAVE_OUTNUM;
AO(1) = FLOATARRO[15];
#if defined(DEVICE_MC8) || defined(DEVICE_MC8_125) || defined(DEVICE_MC5) || defined(DEVICE_MC1) || defined(DEVICE_MC6) || defined(DEVICE_MR4)
_DACService();
#endif
_Inited = true;
}
//-------------------------------------------------------------
main()
{
main_func();
}
__global xdata char __RAMCheckByte;
#undef __global
#undef __comment
- Содержание
- 1 Анализ технического задания 10
- 2 Структурная схема 25
- 1 Анализ технического задания
- 1.1 Многоуровневая структура комплекса
- 1.1.1 Уровень диспетчеризации
- 1.1.2 Уровень автоматизации
- 1.2 Масштабируемость комплекса
- 1.3 Описания инженерных систем
- 1.3.1 Вентиляция
- 1.3.2 Кондиционирование
- 1.3.3 Холодоснабжение
- 1.4 Протокол lon
- 1.4.1 Введение
- 1.4.2 Уровни протокола LonTalk и основные функции
- 1.4.3 Физические каналы
- 1.4.4 Интерфейсный Neuron-кристалл
- 1.5 Выбор аппаратных и программных средств
- 1.6 Рекомендации по развитию комплекса
- 2 Структурная схема
- 3 Функциональная схема
- 4 Принципиальная схема
- 5 Конструктивное исполнение
- 6 Конфигурирование оборудования
- 6.1 Конфигурирование платы 33cntranlon
- 6.2 Конфигурирование шлюза dms504b1
- 6.3 Конфигурирование mcp3
- 7 Функциональный алгоритм kongraf
- 8 Технико-экономическое проектирование
- 8.1 Обоснование необходимости и актуальности разработки
- 8.2 Этапы производства
- 8.3 Расчёт заработной платы.
- 8.4 Затраты на сырьё и материалы
- 8.5 Сравнение с аналогом
- 8.6 Расчет экономической эффективности
- 8.7 Заключение
- 9 Безопасность и экологичность проекта
- 9.1 Системный анализ надежности при эксплуатации
- 9.2 Мероприятия по повышению надежности
- 9.3 Оценка напряженности процесса эксплуатации комплекса
- 9.4 Пожарная безопасность при эксплуатации щитов автоматизации комплекса.
- 9.5 Экологичность комплекса.
- Заключение
- Библиографический список
- Приложения Приложение а
- Приложение б
- Приложение в
- Приложение г