//EEPROM3.C
//Write float to EEPROM
//PIC16F628 EEPROM size 128 00-7Fh
//PIC16F648A EEPROM size 256 00-FFh
//#include <16F628.h>
#include <16F648A.h>
#use delay(clock=4000000)
#fuses XT,PUT,BROWNOUT,MCLR,NOWDT,NOPROTECT,NOLVP
#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1)
//PIC16 Write Internal EEPROM
#rom 0x2100={0,1,2,3,4}
void Write_eeppromf(byte adr,float fdat)
{
int i;
for(i=0;i<sizeof(float);i++)
write_eeprom(adr+i,*(&fdat+i));
}
float Read_eeppromf(byte adr)
{
int i;
float data;
for(i=0;i<sizeof(float);i++)
*(&data+i)=read_eeprom(i+adr);
return(data);
}
//*** MAIN ***
main()
{
float dat[4]={12.5,-33.9,0.1529,3.5},fdat;
int i;
delay_ms(200); //Delay for Hardware ready
printf("*** EEPROM DEMO3***\r\n");
for(i=0;i<4;i++)
Write_eeppromf(i*sizeof(float),dat[i]);
for(i=0;i<4;i++)
{
fdat=Read_eeppromf(i*sizeof(float));
printf("Read form EEPROM =%f\r\n",fdat);
}
while(1); //Loop here
}