iam writing program in Hi-tech c,i have gone through the datasheets.my calibration values are stored in a variable.i have 4 channels and have 8 calibration values .iam not getting how to write the values in the variable to eprom.Is this correct.i am not getting how to read from eeprom and feel iam missing many things in this code.calibration.m&calibration.c are where i receive my calibration values of M and C.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <htc.h>
#include "Rserial.h"
void int_EEPROM_putc(unsigned char address, unsigned char data);
unsigned char int_EEPROM_getc(unsigned char address);
extern double channel_value;
void readtemp(void);
extern double temp_value;
void int_EEPROM_putc(unsigned char address, unsigned char data)
{
unsigned char INTCON_SAVE;
EEADR = address;
EEDATA = data;
EEPGD= 0; // 0 = Access data EEPROM memory
CFGS = 0; // 0 = Access Flash program or DATA EEPROM memory
WREN = 1; // enable writes to internal EEPROM
INTCON_SAVE=INTCON; // Save INTCON register contents
INTCON=0; // Disable interrupts
EECON2=0x55; // Required sequence for write to internal EEPROM
EECON2=0xaa; // Required sequence for write to internal EEPROM
WR=1; // begin write to internal EEPROM
INTCON=INTCON_SAVE; // enable interrupts
while (EEIF==0)//Wait till write operation complete
{
}
WREN=0; // Disable writes to EEPROM on write complete
EEIF=0; //Clear EEPROM write complete flag.
}
void eprom_write()
{
int i;
for ( i = 0; i < 3; i ++ )
{
int_EEPROM_putc(calibration.m,0x55 + i ); //Write m to EEPROM address 0x55, 0x57, 0x59, 0x5b
int_EEPROM_putc(calibration.c,0x55 + ++i ); //Write c to EEPROM address 0x56, 0x58, 0x5a, 0x5c
}
}
unsigned char int_EEPROM_getc(unsigned char address)
{
EEADR=address;
EEPGD= 0; // 0 = Access data EEPROM memory
CFGS = 0; // 0 = Access Flash program or DATA EEPROM memory
RD = 1; // EEPROM Read
return EEDATA; // return data
}