Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how to save calibration values in PIC eprom

Status
Not open for further replies.

rems

New Member
could anyone help me on how to save the calibration values on pic eprom.iam using PIC16f1937.
 
iam sending my temperture value from PIC to PC using serial port.In my C# program i am giving calibration values M and C .i need to store those calibration values in my PIC EEPROM.
 
Section 11 of the datasheet covers the eeprom. There are code samples for reading and writing data to the eeprom section.

Is that what you need? Or do you need help in determining what the calibration values need to be?
 
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
}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top