CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

writing and reading float to eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
group9



Joined: 07 Dec 2006
Posts: 3

View user's profile Send private message

writing and reading float to eeprom
PostPosted: Wed May 02, 2007 9:07 am     Reply with quote

hello
i am trying to write and read some float values to the 16f877a internal eeprom. and it does not seem to work. iread some junk values back if anyone could help that would be great.
thx

CCS PCM C Compiler, Version 3.212, 26318

#include <16F877A.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NODEBUG,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#include<lcd.c>
#include <kbd.c>
#use fast_io(A)

float WRITE_FLOAT_EEPROM(long int ad, float data);
float READ_FLOAT_EEPROM(long int ad);
void main (void)
{
long int k,m;
float res[];
float val[10]={0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
lcd_init();

for(m=0;m<10;m++)
{
WRITE_FLOAT_EEPROM(m,val[m]);
res[m]=READ_FLOAT_EEPROM(m);
printf(LCD_PUTC, "\fval=%1.3f\n",res[m]);
delay_ms(500);
}



}


float WRITE_FLOAT_EEPROM(long int ad, float data) {
int i;

for (i = 0; i < 4; i++)
write_eeprom(i + ad, *((int8*)&data + i) ) ;
}

float READ_FLOAT_EEPROM(long int ad) {
int i;
float data;

for (i = 0; i < 4; i++)
*((int8*)&data+ i) = read_eeprom(i + ad);

return(data);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 02, 2007 10:55 am     Reply with quote

Quote:
I am trying to write and read some float values to the 16f877a internal
eeprom. and it does not seem to work. I read some junk values back.

#include <16F877A.h>
#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NODEBUG,NOLVP,NOCPD,NOWRT
#use delay(clock=20000000)
#include
#include
#use fast_io(A)

float WRITE_FLOAT_EEPROM(long int ad, float data);
float READ_FLOAT_EEPROM(long int ad);
void main (void)
{
long int k,m;
float res[];
float val[10]={0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
lcd_init();

for(m=0;m<10;m++)
{
WRITE_FLOAT_EEPROM(m,val[m]);
res[m]=READ_FLOAT_EEPROM(m);
printf(LCD_PUTC, "\fval=%1.3f\n",res[m]);
delay_ms(500);
}


022 kbd_getc.last_key
023 kbd_getc.col
024-025 MAIN.k
026-027 MAIN.m
028-029 MAIN.res
02A-051 MAIN.val
052 lcd_init.i
052 MAIN.@SCRATCH
053 lcd_init.@SCRATCH

Look at your array declaration for 'res'. Look at the amount of RAM
allocated for it, as shown in the symbol table above. What will happen
when your code writes to the 'res' array ? What change should you
make to your 'res' array declaration to fix this ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group