该程序参考TI的电量方案程序ESP文件:
在ESP430.h文件中申明结构体
struct ts_parameters{
float VRatio;
float IRatio;
float EnergyRatio;
int pSET_PHASECORR1;
int pSET_PHASECORR2;
unsigned int pSET_GAINCORR1;
unsigned int pSET_GAINCORR2;
int pSET_V1OFFSET;
int pSET_I1OFFSET;
int pSET_I2OFFSET;
unsigned int pSET_ADAPTI1;
unsigned int pSET_ADAPTI2;
unsigned int pSET_STARTCURR_INT;
unsigned int pSET_STARTCURR_FRAC;
union tu_ulong_word pSET_INTRPTLEVL;
unsigned long ulTempGain;
unsigned long ulTempOffset;
union ts_long_word pSET_POFFSET1;
union ts_long_word pSET_POFFSET2;
#ifdef ESP_V2
unsigned int pSET_CORRCOMP;
#endif
};
在ESP430.C文件中定义结构体变量
struct ts_parameters s_parameters;
#ifdef __IAR_SYSTEMS_ICC__
#if __VER__ < 200
#pragma memory=constseg(INFOA)
#else
#pragma constseg=INFOA
#endif
#endif
#ifdef __CROSSWORKS_MSP430
#pragma constseg("INFO")
#endif
#ifdef __TI_COMPILER_VERSION__
#pragma DATA_SECTION(s_parameters_flash, ".infoA")
#endif
/**********************将参数信息放置到FLASH中***************/
//---------说明:以下参数如defSET_V1OFFSET,其实是实数值
const struct ts_parameters s_parameters_flash =
{
defVRatio,
defIRatio,
defEnergyRatio,
defSET_PHASECORR1,
defSET_PHASECORR2,
defSET_GAINCORR1,
defSET_GAINCORR2,
defSET_V1OFFSET,
defSET_I1OFFSET,
defSET_I2OFFSET,
defSET_ADAPTI1,
defSET_ADAPTI2,
defSET_STARTCURR_INT,
defSET_STARTCURR_FRAC,
{defSET_INTRPTLEVL_LO,
defSET_INTRPTLEVL_HI},
defTempGain,
defTempOffset,
0, // P1Offset
0, // P2Offset
#ifdef ESP_V2
0 // CORRCOMP CMRR
#endif
};
上述程序是对该结构体变量s_parameters_flash 直接附初值,该变量时存储在FLASH 信息段A中的
如图所示:
当我们需要赋值给变量s_parameters
if (flashvars) s_parameters = s_parameters_flash;
结果如图:
科技成就生活,创新源自智拓
文章评论(0条评论)
登录后参与讨论