int
Szabó László
laci at apaczai.hu
Sun Mar 28 11:06:09 CEST 2004
Ez vajon miért nem müködik??
// Procedure to retrieve a floating point double value from nvram and
return the value.
// address is the location of the double.
double read_double_1306(unsigned char address)
{
double dbl;
*(unsigned char*)&dbl = read_1306(address++);
*((unsigned char*)&dbl+1) = read_1306(address++);
*((unsigned char*)&dbl+2) = read_1306(address++);
*((unsigned char*)&dbl+3) = read_1306(address);
return dbl;
}
// Procedure to write a floating point double value to nvram at address.
void write_double_1306(double value, unsigned char address)
{
write_1306(address++, *(unsigned char*)&value);
write_1306(address++, *((unsigned char*)&value+1));
write_1306(address++, *((unsigned char*)&value+2));
write_1306(address, *((unsigned char*)&value+3));
}
-----Original Message-----
From: elektro-bounces at tesla.hu [mailto:elektro-bounces at tesla.hu] On
Behalf Of HKC
Sent: Sunday, March 28, 2004 11:11 AM
To: Szabó László
Subject: Re: int
Hello ,
Sunday, March 28, 2004, 7:32:30 AM, you wrote:
SL> Sziasztok!
SL> Szeretnék int tipusu változot EEPROM -ban tárolni. Hogyan tudom
SL> szétszedni két char -ra? (C -ben)
SL> Köszönöm: Laci
Hi-tech C-ben:
/*
given variable of any type (char, uchar, int, uint, long) it modifies
the unsigned char residing at that memory location
for ints, byte1 is msb, byte0 is lsb
for longs byte3 is msb, byte0 is lsb
ie: sample C code
unsigned int myint=0x4321;
long mylong=0x87654321;
//for myint byte1(myint)=0x43; (msb) and byte0(myint)=0x21;
(lsb)
//for mylong byte3(mylong)=0x87; (msb), byte2(mylong)=0x65;
byte2(mylong)=0x43; and byte0(mylong)=0x21; (lsb)
note: to avoid fixup overflow errors add bankX if the target
variable
resides in banks 1, 2 or 3
*/
#define byte0(x) (unsigned char)(*(((unsigned char
*)&x)+0))
#define byte1(x) (unsigned char)(*(((unsigned char
*)&x)+1))
#define byte2(x) (unsigned char)(*(((unsigned char
*)&x)+2))
#define byte3(x) (unsigned char)(*(((unsigned char
*)&x)+3))
INT esetében egyszer a byte0(INTváltozó) majd a byte1(INTváltozó)
makróval hivatkozol az INTváltozó-d megfelelő részére, és lepakolod az
EEPROM-ba
Vagy:
definiálsz strukturát
struct two_bytes
{
unsigned char low;
unsigned char high;
};
definiálod a változódat
struct INTváltozó
hivatkozol rá:
INTváltozó.low
INTváltozó.high
--
Best regards,
Kálmán mailto:el.engineer at axelero.hu
More information about the Elektro
mailing list