Hello Jim,
I did some further tests with the value of TMOD limited, as you described. I also checked the HCS08, in addition to the HC908, to see if there were any differences.
For the HC908, the following code was tested:
word c;
volatile byte scratch_byte = 0x40;
TMOD = 0x00F0;
// Case 1:
c = TMODL * scratch_byte / 256;
TCH1 = c;
// Case 2:
TCH1 = TMODL * scratch_byte / 256;
The compiler generated the following code to write to TCH1.
Case 1:
STX 0x29 ; High byte first
STA 0x2A
Case 2:
STHX 0x29 ; This should also be OK
The equivalent code for the HCS08:
volatile word scratch_byte = 0x40;
word c;
TPM1MOD = 0x00F0;
// Case 1:
c = TPM1MODL * scratch_byte / 256;
TPM1C1V = c;
// Case 2:
TPM1C1V = TPM1MODL * scratch_byte / 256;
The compiler generated the following code to write to TPM1C1V.
Case 1:
STHX 0x29 ; OK
Case 2:
STA 0x2A ; Low byte first - OK for HCS08
CLR 0x29 ; High byte
In all the above cases, the expected result of the calculation was obtained.
Regards,
Mac