If you use bitwise operators to get the low and high bytes of a word, this should work the same on all microcontollers...
x&0xff is the least significant byte of x,
and (x>>8)&0xff is the next lowest byte,
and (x>>16)&0xff is the next lowest byte, etc..
HOWEVER, there is an important gotcha that must be dealt with especially when transferring data between Intel and Freescale processors... ENDIANNESS.
In Freescale microcontroller, a 16 bit word is stored in memory with the most significant byte first.
For example, the decimal number 12345 (0x3039 hex) would be stored in memory as
0x30 0x39 . This is known as "Big Endian."
In many Intel based environments, a 16 bit word's bytes are stored in memory BACKWARDS with the least significant byte first! This is known as "Little Endian"
For example, the decimal number 12345 (0x3039 hex) would be stored in memory as
0x39 0x30 .
Please consider this code:
void foo(void)
{
unsigned short x=12345;
unsigned char MH,ML,H,L;
H=(x>>8)&0xFF; // get most significant byte of x
L=x&0xFF; // get least significant byte of x
MH=*(unsigned char *)(&x); // get first byte of x in memory
ML=*(unsigned char *)(&x+1); // get second byte of x in memory
}
on a freescale processor, at the end of this function, H will equal MH, and L will equal ML.
on an intel processor, H will equal ML and L will equal MH!
On projects what involve data transfer between a freescale device and a windows-based controller, you will need to flip a word's bytes around to convert between big endian and little endian formats!
I hope this helps.
Regards,
Craig