int

HKC coloman50mail at axelero.hu
Sun Mar 28 11:11:02 CEST 2004


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