📄 energy.h
字号:
#define PGA2_X16 0x80 //Gain = 16
//These bits define the current channel input gain
#define PGA1_X1 0x00 //Gain = 1
#define PGA1_X2 0x01 //Gain = 2
#define PGA1_X4 0x02 //Gain = 4
#define PGA1_X8 0x03 //Gain = 8
#define PGA1_X16 0x04 //Gain = 16
/*******************************************************************************
Definition of Energy Registers--CALMODE
*******************************************************************************/
//These bits define the current channel used for energy measurements.
#define SEL_ICH_AUTO 0x30 //Current channel automatically selected by the tampering condition
#define SEL_ICH_A 0x10 //Current channel connected to IA
#define SEL_ICH_B 0x20 //Current channel connected to IB
#define V_CH_SHORT 0x08 //short V channel to ground
#define I_CH_SHORT 0x04 //short I channel to ground
/*******************************************************************************
Definition of Energy Registers--MIRQSTL
*******************************************************************************/
#define IF_ADEIRQ 0x80 //This bit is set if any of ADE interrupt flags are set
#define IF_FAULTSIGN 0x20 //Logic one indicates that the Fault mode has changed.
#define IF_VARSIGN 0x10 //Logic one indicates that the reactive power sign changed.
#define IF_APSIGN 0x08 //Logic one indicates that the active power sign changed.
#define IF_VANOLOAD 0x04 //Logic one indicates that the apparent power no-load is detected.
#define IF_RNOLOAD 0x02 //Logic one indicates that the reactive power no-load is detected.
#define IF_APNOLOAD 0x01 //Logic one indicates that the active power no-load is detected.
/*******************************************************************************
Definition of Energy Registers--MIRQSTM
*******************************************************************************/
#define IF_CF2 0x80 //Logic one indicates that a pulse of CF2 has been issued.
#define IF_CF1 0x40 //Logic one indicates that a pulse of CF1 has been issued.
#define IF_VAEOF 0x20 //Logic one indicates that the VAHR register has overflowded.
#define IF_REOF 0x10 //Logic one indicates that the VARHR register has overflowded.
#define IF_AEOF 0x08 //Logic one indicates that the WATTHR register has overflowded.
#define IF_VAEHF 0x04 //Logic one indicates that the VAHR register is half full.
#define IF_REHF 0x02 //Logic one indicates that the VARHR register is half full.
#define IF_AEHF 0x01 //Logic one indicates that the WATTHR register is half full.
/*******************************************************************************
Definition of Energy Registers--MIRQSTH
*******************************************************************************/
#define IF_RESET 0x80 //Indicates the end of reset(for both software or hardware reset)
#define IF_WFSM 0x20 //Indicates new data is present in the waveform register
#define IF_PKI 0x10 //Indicates current channel has exceeded the IPKLVL value.
#define IF_PKV 0x08 //Indicates voltage channel has exceeded the VPKLVL value.
#define IF_CYCEND 0x04 //Indicates the end of the energy accumulation over an integer number
//of half line cycles.
#define IF_ZXTO 0x02 //Indicates no zero crossing on the line voltage happened for the
//last ZXTOUT half line cycles.
#define IF_ZX 0x01 //Indicates detection of a zero crossing in the voltage channel.
/*******************************************************************************
Definition of Energy Registers--MIRQENL
*******************************************************************************/
#define IE_FAULTSIGN 0x20 //1-the FAULTSIGN bit set creates a pending ADE interrupt.
#define IE_VARSIGN 0x10 //1-the VARSIGN bit set creates a pending ADE interrupt.
#define IE_APSIGN 0x08 //1-the APSIGN bit set creates a pending ADE interrupt.
#define IE_VANOLOAD 0x04 //1-the VANOLOAD bit set creates a pending ADE interrupt
#define IE_RNOLOAD 0x02 //1-the RNOLOAD bit set creates a pending ADE interrupt
#define IE_APNOLOAD 0x01 //1-the APNOLOAD bit set creates a pending ADE interrupt
/*******************************************************************************
Definition of Energy Registers--MIRQENM
*******************************************************************************/
#define IE_CF2 0x80 //1-a CF2 pulse issued creates a pending ADE interrupt
#define IE_CF1 0x40 //1-a CF1 pulse issued creates a pending ADE interrupt
#define IE_VAEOF 0x20 //1-the VAEOF flag set creates a pending ADE interrupt
#define IE_REOF 0x10 //1-the REOF flag set creates a pending ADE interrupt
#define IE_AEOF 0x08 //1-the AEOF flag set creates a pending ADE interrupt
#define IE_VAEHF 0x04 //1-the VAEHF flag set creates a pending ADE interrupt
#define IE_REHF 0x02 //1-the REHF flag set creates a pending ADE interrupt
#define IE_AEHF 0x01 //1-the AEHF flag set creates a pending ADE interrupt
/*******************************************************************************
Definition of Energy Registers--MIRQENH
*******************************************************************************/
#define IE_WFSM 0x20 //1-the WFSM flag set creates a pending ADE interrupt
#define IE_PKI 0x10 //1-the PKI flag set creates a pending ADE interrupt
#define IE_PKV 0x08 //1-the PKV flag set creates a pending ADE interrupt
#define IE_CYCEND 0x04 //1-the CYCEND flag set creates a pending ADE interrupt
#define IE_ZXTO 0x02 //1-the ZXTO flag set creates a pending ADE interrupt
#define IE_ZX 0x01 //1-the ZX flag set creates a pending ADE interrupt
/*******************************************************************************
Macro Definition of Accessing Energy SFRs and Registers
*******************************************************************************/
//This macro is used for getting a 3-byte value from energy SFRs,
//sfrname should be one of:VRMS,IRMS,EIRQEN,EIRQST,WAV1,WAV2
//the 3-byte value will be saved in AdeReg
#define GetEnergySFR(sfrname,DataL,DataM,DataH) \
{\
DataH = sfrname##H;\
DataM = sfrname##M;\
DataL = sfrname##L;\
}
//------------------------------------------------------------------------------
//This macro is used for getting a value from energy registers,
//the return value will be saved in AdeReg
#define GetEnergyReg(regaddr,DataL,DataM,DataH)\
{\
MADDPT = regaddr;\
DataL = MDATL;\
DataM = MDATM;\
DataH = MDATH;\
}
//------------------------------------------------------------------------------
//This macro is used for setting a 2-byte energy register,
//regaddr should be a r/w register.
#define SetEnergyReg2(regaddr,DataL,DataM)\
{\
MDATL = DataL;\
MDATM = DataM;\
MADDPT= regaddr | 0x80;\
SomeNops();\
}
//------------------------------------------------------------------------------
//This macro is used for setting a 1-byte energy register,
//regaddr should be a r/w register.
#define SetEnergyReg1(regaddr,DataL)\
{\
MDATL = DataL;\
MADDPT= regaddr | 0x80;\
SomeNops();\
}
/*******************************************************************************
Definition of Globe Routines
*******************************************************************************/
extern void EnergyInit(void);
extern void MeasureAll(void);
extern void ClearWatchdog(void);
extern void EnergyReload(void);
extern void EnergySave(void);
extern void SomeNops(void);
/*******************************************************************************
Definition of Globe Variables
*******************************************************************************/
//extern ADE_REGS AdeReg;
extern __idata unsigned int Irms;
extern __idata unsigned int Vrms;
extern __idata unsigned int ActivePower;
extern __idata unsigned int ReactivePower;
extern __idata unsigned int ApparentPower;
extern __idata unsigned int PowerFactor;
extern __idata unsigned int Frequency;
extern __idata unsigned int Temperature;
extern __idata EEDATA EEData;
//#define Date (EEData.DD)
//#define Month (EEData.MM)
//#define Year (EEData.YY)
#define CF1Counter (EEData.CF1)
#define ActiveEnergy (EEData.AE)
#define CF2Counter (EEData.CF2)
#define ReactiveEnergy (EEData.RE)
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -