savetask.c
来自「cs5460a做功率表用 cs5460a做功率表用 cs5460a做功率表」· C语言 代码 · 共 206 行
C
206 行
/********************************************
公司名称:
文 件 名:SaveTask.c
版 本 号:
程序设计:
说 明:各种参数保存函数
完成日期:
修改日期:
功能摘要:
**********************************************/
#define _SaveTask
#include "includes.h"
uint8 AddrVal;
uint16 PtVal;
uint16 CtVal;
uint8 BaudAndData; //通信波特率设置和数据格式设置
uint16 H_Alarm;
uint16 L_Alarm;
uint8 AlarmSwitch; //报警选项
void SaveFunData(void); //保存设定参数,参数设定后常按set键
void LoadFunData(void); //加载设定参数,上电后初始化
void Save_Calibrate(void); //保存校验参数,校验以后常按set键
void LoadCalibration(void); //加载校验参数,上电后初始化
//---------------------------------------
void SaveFunData(void)
{
uint8 temp[11];
temp[0] = ((uchar *)&PtVal)[0];
temp[1] = ((uchar *)&PtVal)[1];
temp[2] = ((uchar *)&CtVal)[0];
temp[3] = ((uchar *)&CtVal)[1];
temp[4] = AddrVal;
temp[5] = BaudAndData;
temp[6] = ((uint8 *)&H_Alarm)[0];
temp[7] = ((uint8 *)&H_Alarm)[1];
temp[8] = ((uint8 *)&L_Alarm)[0];
temp[9] = ((uint8 *)&L_Alarm)[1];
temp[10] = AlarmSwitch;
Write_EEProm_block(temp,(uint *)0x30,11);
}
//--------------------------------------
void LoadFunData(void)
{
uint8 temp[11];
Read_EEProm_block(temp,(uint *)0x30,11);
((uchar *)&PtVal)[0] = temp[0];
((uchar *)&PtVal)[1] = temp[1];
((uchar *)&CtVal)[0] = temp[2];
((uchar *)&CtVal)[1] = temp[3];
AddrVal = temp[4];
BaudAndData = temp[5];
((uint8 *)&H_Alarm)[0] = temp[6];
((uint8 *)&H_Alarm)[1] = temp[7];
((uint8 *)&L_Alarm)[0] = temp[8];
((uint8 *)&L_Alarm)[1] = temp[9];
AlarmSwitch = temp[10];
if ((PtVal > 5000) || (PtVal == 0))
{ PtVal = 1; }
if ((CtVal > 2000) || (CtVal == 0))
{ CtVal = 1; }
if ((H_Alarm > 9999)|| (H_Alarm == 0))
{ H_Alarm = 1; }
if ((L_Alarm > 9999)|| (L_Alarm == 0))
{ L_Alarm = 1; }
if (AddrVal > 247 || AddrVal == 0)
{ AddrVal = 1; }
BaudAndData &= 0x13;
}
//-----------------------------------------
void Save_Calibrate(void)
{
uchar AD_Buf[4];
CS_AD_A = 0;
Rd5460A(AD_Buf,0x20); //读电流偏移校准寄存器
CS_AD_A = 1;
Write_EEProm_block(AD_Buf,(uint *)0x40,3);
CS_AD_A = 0;
Rd5460A(AD_Buf,0x04); //读电流增益校准寄存器
CS_AD_A = 1;
Write_EEProm_block(AD_Buf,(uint *)0x50,3);
//-----------------------------------------------
CS_AD_A = 0;
Rd5460A(AD_Buf,0x22); //读电压偏移校准寄存器
CS_AD_A = 1;
Write_EEProm_block(AD_Buf,(uint *)0x60,3);
CS_AD_A = 0;
Rd5460A(AD_Buf,0x08); //读电压增益校准寄存器
CS_AD_A = 1;
Write_EEProm_block(AD_Buf,(uint *)0x70,3);
//-----------------------------------------------
CS_AD_B = 0;
Rd5460A(AD_Buf,0x20); //读电流偏移校准寄存器
CS_AD_B = 1;
Write_EEProm_block(AD_Buf,(uint *)0x80,3);
CS_AD_B = 0;
Rd5460A(AD_Buf,0x04); //读电流增益校准寄存器
CS_AD_B = 1;
Write_EEProm_block(AD_Buf,(uint *)0x90,3);
//-------------------------------------------------
CS_AD_B = 0;
Rd5460A(AD_Buf,0x22); //读电压偏移校准寄存器
CS_AD_B = 1;
Write_EEProm_block(AD_Buf,(uint *)0xA0,3);
CS_AD_B = 0;
Rd5460A(AD_Buf,0x08); //读电压增益校准寄存器
CS_AD_B = 1;
Write_EEProm_block(AD_Buf,(uint *)0xB0,3);
}
//----------------------------------------------
void LoadCalibration(void)
{
uchar temp[4];
temp[0] = 0x60;
Read_EEProm_block(&temp[1],(uint *)0x40,3);
CS_AD_A = 0;
Wr5460A(temp,4);
CS_AD_A = 1;
temp[0] = 0x44;
Read_EEProm_block(&temp[1],(uint *)0x50,3);
CS_AD_A = 0;
Wr5460A(temp,4);
CS_AD_A = 1;
//--------------------------------------
temp[0] = 0x62;
Read_EEProm_block(&temp[1],(uint *)0x60,3);
CS_AD_A = 0;
Wr5460A(temp,4);
CS_AD_A = 1;
temp[0] = 0x48;
Read_EEProm_block(&temp[1],(uint *)0x70,3);
CS_AD_A = 0;
Wr5460A(temp,4);
CS_AD_A = 1;
//----------------------------------------------
temp[0] = 0x60;
Read_EEProm_block(&temp[1],(uint *)0x80,3);
CS_AD_B = 0;
Wr5460A(temp,4);
CS_AD_B = 1;
temp[0] = 0x44;
Read_EEProm_block(&temp[1],(uint *)0x90,3);
CS_AD_B = 0;
Wr5460A(temp,4);
CS_AD_B = 1;
//-------------------------------------------
temp[0] = 0x62;
Read_EEProm_block(&temp[1],(uint *)0xA0,3);
CS_AD_B = 0;
Wr5460A(temp,4);
CS_AD_B = 1;
temp[0] = 0x48;
Read_EEProm_block(&temp[1],(uint *)0xB0,3);
CS_AD_B = 0;
Wr5460A(temp,4);
CS_AD_B = 1;
//------------------------------------------
CS_AD_A = 0;
CS_AD_B = 0;
Wr_ADByte(0xe8); //启动CS5460A
CS_AD_A = 1;
CS_AD_B = 1;
}
//--------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?