You are on page 1of 2

#ifndef GLOBAL_DATA_TYPE_INIT //(Include this section only once for each source file) #define GLOBAL_DATA_TYPE_INIT #define CONSTANT

const //Define used fo r this as some compilers require an additional qualifier such as 'rom' to signif y that a constant should be stored in program memory #undef #undef #undef #undef #undef #undef #undef #undef #undef BOOL TRUE FALSE BYTE SIGNED_BYTE WORD SIGNED_WORD DWORD SIGNED_DWORD

//BOOLEAN - 1 bit: typedef enum _BOOL { FALSE = 0, TRUE } BOOL; //BYTE - 8 bit unsigned: typedef unsigned char BYTE; //SIGNED_BYTE - 8 bit signed: typedef signed char SIGNED_BYTE; //WORD - 16 bit unsigned: typedef unsigned int WORD; //SIGNED_WORD - 16 bit signed: typedef signed int SIGNED_WORD; //DWORD - 32 bit unsigned: typedef unsigned long DWORD; //SIGNED_DWORD - 32 bit signed: typedef signed long SIGNED_DWORD; //BYTE BIT ACCESS: typedef union _BYTE_VAL { struct { unsigned char b0:1; unsigned char b1:1; unsigned char b2:1; unsigned char b3:1; unsigned char b4:1; unsigned char b5:1; unsigned char b6:1; unsigned char b7:1; } bits; BYTE Val; } BYTE_VAL; //WORD ACCESS typedef union _WORD_VAL { WORD Val; struct { BYTE LSB; BYTE MSB;

} byte; BYTE v[2]; } WORD_VAL; #define LSB(a) #define MSB(a)

((a).v[0]) ((a).v[1])

//DWORD ACCESS: typedef union _DWORD_VAL { DWORD Val; struct { BYTE LOLSB; BYTE LOMSB; BYTE HILSB; BYTE HIMSB; } byte; struct { WORD LSW; WORD MSW; } word; BYTE v[4]; } DWORD_VAL; #define LOWER_LSB(a) ((a).v[0]) #define LOWER_MSB(a) ((a).v[1]) #define UPPER_LSB(a) ((a).v[2]) #define UPPER_MSB(a) ((a).v[3]) //EXAMPLE OF HOW TO USE THE DATA TYPES:// WORD_VAL variable_name; // variable_name = 0xffffffff; // variable_name.LSW = 0xffff; o the lower word // variable_name.LOLSB = 0xff; the low word least significant byte // variable_name.v[0] = 0xff; byte 0 (least significant byte) //Define the variable //Writing 32 bit value //Writing 16 bit value t //Writing 8 bit value to //Writing 8 bit value to

#endif

//GLOBAL_DATA_TYPE_INIT

You might also like