If i'm using that the decimal value which to store into the timer for example: in Assembly code we are writing as TIMER_0 EQU -1027 but in the C, how can we actually extract this -1027 to TL0 = -3 and TH0 = -5? thanx
I tend to think of timer values as unsigned. For that matter, almost all values I use in embedded programming are unsigned. TL0 is the least significant byte of a 16-bit value. TH0 is the most significant byte. So, the question is really just how to get these values. This can be as simple as:
U16 timerVal = (U16)-1027; TL0 = timerVal; TH0 = timerVal >> 8;
typedef struct { U8 msb; // Keil C stores ints big-endian U8 lsb; } U16AsBytes; typedef union { U16 u16; U16AsBytes asBytes; U8 array[2]; } ByteAccess16; ByteAccess16 timerVal; timerVal.u16 = -1027; TL0 = timerVal.asBytes.lsb; TH0 = timerVal.asBytes.msb; TL0 = timerVal.array[1]; TH0 = timerVal.array[0];
Thank u for solving this problem for me...:)