| ??? 02/12/04 00:07 Read: times |
#64552 - RE: Timer 2 in auto reload mode Responding to: ???'s previous message |
Sandro, There are two obvious methods to load the timer: 1/ TH2 = 0xfc; TL2 = 0x17; here we're loading 8 bit values that we've precalculated. 2/ TH2 = (65535-1000)>>8; ????? TL2= (65535-1000); this is a more generic approach and using the compiler to do some calculation for us. The 1000 is the number of ticks we want to load but the timer is an up counter (normally) and interrupts when it overflows (65535). This explains the 65535 - 1000. These are 16 bit values - if we assign a 16 bit value to an 8 bit destination, the compiler will use only the low 8 bits which is ok for loading TL2. Therefore to load TH2 we have to shift the 16 bit result of our calculation right by 8 bits thus the >>8. Because the result is a constant, most compilers will generate the code in example 1. |



