Don't know about the 8051 (and it probably varies between the dozens of
8051 families - it pays to be specific in questions), but timer peripherals all work in pretty much the same way for simple interrupts. The reference clock (6 MHz here) passes through a divide-by-power-of-two prescaler, which may be fixed or configurable (see your specific chip's datasheet), and clocks a counter. The counter may be 8-bit or 16-bit (or more, for some micros) - I'm guessing you have a 16-bit timer here. The counter either counts up to a set value and interrupts on overflow, or counts down from the set value and interrupts on underflow. Either way, the counter target value is calculated in the same way - take your reference frequency, divide it by the prescaler, and then by your target frequency, to get the counter value. E.g., for a prescaler of 4, this would give you: 6,000,000 / 4 /
1,000 = 1500. Put (1500 div 256) = 5 in the high register, and (1500 mod 256) = 220 in the low register. For some timers, you should use one less that this count value if you are being precise - check your datasheet.
You also have to set up the prescaler, start the timer, enable interrupts, and so on.
has all the 8051/2 info you will ever need. A timer tutorial is located at
formatting link
mmmKay
--
========================================================================
Michael Kesti | "And like, one and one don't make
| two, one and one make one."
mrkesti at comcast dot net | - The Who, Bargain
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.