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 CCS Technical Support

FLOAT / 24LC256

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



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message

FLOAT / 24LC256
PostPosted: Sun Oct 15, 2006 7:10 pm     Reply with quote

Hi, this a lsmall code for test a var FLOAT with the 24LC256. I write

19.508016 and read 19.508018 Somebody can help me ?


#include <18F452.h>
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT,NOCPD,NOWRT
#use delay(clock=20000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <24256>

float lat1=19.508016;

WRITE_FLOAT_EXT_EEPROM(long int n, float data);

float READ_FLOAT_EXT_EEPROM(long int n);

float leitura;

long int end=20;

INT8 CONT=0;

//***********************************************************
// Fun��o principal
//***********************************************************

void main()
{


init_ext_eeprom();

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
// setup_comparator(NC_NC_NC_NC);
// setup_vref(VREF_LOW|-2);
// setup_low_volt_detect(FALSE);
// setup_oscillator(False);

ext_int_edge(2,H_TO_L);
// enable_interrupts(INT_EXT2);
// enable_interrupts(GLOBAL);


while (1)

{


IF(CONT < 7 )

{

WRITE_FLOAT_EXT_EEPROM(end,lat1);

delay_ms(500);

leitura = READ_FLOAT_EXT_EEPROM(end);

printf("Dado e %f\n\r",leitura);
CONT++;

}
}
}


//***********************************************************
//***********************************************************


WRITE_FLOAT_EXT_EEPROM(long int n, float data)

{
int i;

for (i = 0; i < 4; i++)
write_ext_eeprom(i + n, *(&data + i) ) ;

}


float READ_FLOAT_EXT_EEPROM(long int n)

{
int i;
float data;

for (i = 0; i < 4; i++)
*(&data + i) = read_ext_eeprom(i + n);

return(data);
}

//***********************************************************


Thanks

Orcino
hfelton



Joined: 07 Sep 2006
Posts: 2

View user's profile Send private message

Re: FLOAT / 24LC256
PostPosted: Mon Oct 16, 2006 12:13 am     Reply with quote

Orcino wrote:
Hi, this a lsmall code for test a var FLOAT with the 24LC256. I write

19.508016 and read 19.508018 Somebody can help me ?



yes - floats only have around 6-digits of precision. look up and/or think about how this data is stored.

also, please use code-tags around any code-posting you will do in the future.
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