|
/******************************************************************************
|
* Copyright (C) 2014-2015 HangZhou SiZhu Co.,LTD.
|
*
|
*-----------------------------------------------------------------------------
|
* File: CFWRRD.c
|
* Description: compressibility factor write into flash or read from flash operation code
|
* Author: Lishoujian (867693272@qq.com)
|
* Date: Jan 8, 2015
|
*****************************************************************************/
|
|
/* ----------------------- Platform includes --------------------------------*/
|
|
#include "CFWRRD.h"
|
#include "w25x40bv.h"
|
#include "pressure.h"
|
#include "temperature.h"
|
#include "factortab.h"
|
#include "delay.h"
|
|
|
|
|
void Factor_store(void)
|
{
|
uint8 tep_addr,table_addr;
|
uint32 wr_address;
|
for(table_addr=0;table_addr<Table_Num;table_addr++)
|
for(tep_addr=0;tep_addr<3;tep_addr++)
|
{
|
wr_address=(table_addr<<14)|((tep_addr)<<8);
|
Flash_Write((uint8*)factor_tab1,wr_address,152);
|
}
|
}
|
|
|
uint32 Factor_read(void)
|
{
|
uint16 tep_vol,pre_vol,pre,tep_addr,pre_addr;
|
int16 tep;
|
vuint8 tab_addr,tempfactor[2];
|
uint32 rd_addr,factor;
|
|
// tep_vol = Get_temperature_volt();
|
// pre_vol = Get_pressure_volt();
|
// pre = Get_pressure(pre_vol);
|
// tep = Get_temperature(tep_vol);
|
pre_addr=pre-10;
|
if(pre%2==1)
|
pre_addr = pre_addr-1;
|
if((tep+100)%10<5)
|
tep_addr = (tep+100)/10;
|
else
|
tep_addr = (tep+100)/10+1;
|
Flash_Read((uint8*)&tab_addr,0x40000,1);
|
rd_addr = (tab_addr<<14) | (tep_addr<<8) | (pre_addr);
|
Flash_Read((uint8*)tempfactor,rd_addr,2);
|
factor = 90000+tempfactor[0]*100+tempfactor[1];
|
|
return factor;
|
}
|