read and write float values eeprom [ccs c compiler]

Status
Not open for further replies.

armghan11

Member level 1
Joined
Oct 9, 2012
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,557
here is the program i am using to read and write 8bit values.... but how can i read and write float values in eeprom

Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#rom 0x2100 = { 7, 39 }
#include <lcd2.c>

void main() {
   int8 value,value1;
   lcd_init();
   value = read_eeprom (0x2100);
   value1= read_eeprom (0x2101);
   delay_ms(6);
   lcd_gotoxy(1,1);
   printf(lcd_putc,"Hammad Armghan");
   lcd_gotoxy(1,2);
   printf(lcd_putc,"D1=%u",value);
   lcd_gotoxy(9,2);
   printf(lcd_putc,"D2=%u",value1);
   
   
   
   while(TRUE)
   {
   
   
   
   }
}
 

The following is an example of how to read and write a floating point number from/to EEPROM.

n is an offset into the EEPROM.
For floats you must increment it by 4.
For example, if the first float is at 0, the second one should be at 4, and the third at 8.

WRITE_FLOAT_EXT_EEPROM( long int n, float data) {
int i;
for (i = 0; i < 4 ; i++)
write_ ext_ eeprom(i + n, *(((int 8 *)&data + i) ) ;
}

float READ_FLOAT_EXT_EEPROM( long int n) {
int i;
float data;
for (i = 0; i < 4; i++)
*(((int 8 *)&data) + i) = read_ ext_ eeprom(i + n);
return(data);
}
 


Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…