Hello there!
I'm trying to read the value of a timer on the MSC1211, but I'm getting something estrange for me. Look what I did:
//# for starting Timer0 as a 16-bit timer: TMOD = 0x01; TR0 = 1; //#for reading it: //#First I've defined and declared an union variable like this: union { unsigned char t[2]; unsigned int temp; } time; //#Then, time.t[0] = TH0; time.t[1] = TL0;
To press, in hex, the value of both TH0 and TL0 and the proper time (TH0TL0), I'm doing something like this:
printf ("TH0 = 0x%x, TL0 = 0x%x and time = 0x%x", time.t[0], time.t[0], time.temp);
Because each register is an 8-bit , I waited something like: TH0 = 0xHH, TL0 = 0xLL and time = 0xHHLL
But, I'm obtaining something like: TH0 = 0xHHHH, TL0 = 0xLLLL and time = 0xHHHH
LL and HH are hex numbers.
It suggested me it's been read a 16-bit register, even I've declared it as a char. And the value in time.temp is just TH0.
Anyone could tell me what is happening? And what I'm doing wrong?
Later I will exchange this value in sec, msec and usec. Has anyone some function or just a code for this?
Thanks in advance. Eliasibe Luis