We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
You use printf().
Formatting character x is intended to print a int - not a character.
When you have issues with printf - don't you think the manual is a good source of extra information?
http://www.keil.com/support/man/docs/c51/c51_printf.htm
Have you considered what the manual says about the character 'b' for controlling the size of a number?
Hello Per Westermark!
I didn't remember consulting the manual. Now that my problem is solved.
Thank you very much for bringing to my mind that manual and the character 'b'.
o/