#include <stdio.h>
#define u8 unsigned char
u8 PFC_value[2];
typedef union {
//volatile union {
struct
{
unsigned char HC1;
unsigned char HC2;
unsigned char CPR;
unsigned char DCR;
unsigned char ECH;
unsigned char ECL;
unsigned char EPR;
unsigned char CYH;
unsigned char CYL;
unsigned char EBS;
unsigned :16;
unsigned :8;
unsigned char DTI[3];
unsigned char DT2[3];
unsigned char PH2[3];
unsigned char DR2;
unsigned char DT3[3];
unsigned char PH3[3];
unsigned char DR3;
unsigned :16; //char notused2[2];
unsigned char ERC[160];
unsigned char Zero12VB[2];
unsigned char Zero12Is[2];
unsigned char Zero12Vs[2];
unsigned char Zero12VauxIs[2];
float Gain12VB;
float Gain12IS;
float Gain12Vs;
float Gain12VuaxIs;
unsigned char notuse[8];
unsigned char MFU[31];
unsigned char VER;
};
struct
{
unsigned char HC1;
unsigned char HC2;
unsigned char CPR;
unsigned char DCR;
unsigned char ECH;
unsigned char ECL;
unsigned char EPR;
unsigned char CYH;
unsigned char CYL;
unsigned char EBS;
unsigned :16;
unsigned :8;
unsigned char DTI[3];
unsigned char DT2[3];
unsigned char PH2[3];
unsigned char DR2;
unsigned char DT3[3];
unsigned char PH3[3];
unsigned char DR3;
unsigned :16; //char notused2[2];
unsigned char ERC[160];
u16 Zero12VB;
u16 Zero12Is;
u16 Zero12Vs;
u16 Zero12VauxIs;
float Gain12VB;
float Gain12IS;
float Gain12Vs;
float Gain12VuaxIs;
unsigned char notuse[8];
unsigned char MFU[31];
unsigned char VER;
}calibration;
struct
{
unsigned char EEPROM[256];
}ROM;
}EEPROM;
EEPROM Black_BOX;
void EEPageWriteI2C(unsigned int ControlByte, unsigned char *data,unsigned char Length)
{
int loop;
IdleI2C(); //Ensure Module is Idle
StartI2C(); //Generate Start COndition
WriteI2C(ControlByte); //Write Control byte
IdleI2C();
tempadd1= &data;
tempadd2= *data;
for(loop=0;loop<Length;loop++)
{
WriteI2C(&data); //Write Data
IdleI2C();
data++;
}
StopI2C(); //Initiate Stop Condition
Delay_mS(5);
}
//=================================================================================================
// Funciton : void LDByteWriteI2C(unsigned int ControlByte, unsigned int LowAdd, unsigned int data)
//
// input parameter:Control Byte, 8 - bit address, data.
//
// output parameter:NONE
//
// Description :Write a byte to low density device at address LowAdd
//=================================================================================================
void LDByteWriteI2C(unsigned int ControlByte, unsigned int LowAdd, unsigned int data)
{
IdleI2C(); //Ensure Module is Idle
StartI2C(); //Generate Start COndition
WriteI2C(ControlByte); //Write Control byte
IdleI2C();
WriteI2C(LowAdd); //Write Low Address
IdleI2C();
WriteI2C(data); //Write Data
IdleI2C();
StopI2C(); //Initiate Stop Condition
Delay_mS(5);
}
void main(void)
{
LDByteReadI2C(EE_ADDR,0x0001,&PFC_value,2);
EEPageWriteI2C(EE_ADDR, &Black_BOX.ROM.EEPROM, 3);
}