【正文】
mer settings tmod choose mainly depends on the value of register, its members are defined as follows: rank b7 b6 b5 b4 b3 b2 b1 b0bit symbols gate c / t m1 m0 gate c / t m1 m0Which, b0 ~ b3 used to control Timer 0 Road, b4 ~ b7 Road used to control a timer.gate gated bit for bit, the main way to start the timer to determine if gate = 0, then by tr0 (tr1) place to start on / off timer, if gate = 1, while outside the interrupt request signal (int0 or int1) to start timing browser.c / tbit count for the timing and choice of place, c / t = 0 for the regular way, c / t = 1 to count way.m0, m1 choice for the work placem1m0 = 00 ways 0m1m0 = 10 Mode 2m1m0 = 01 ways 1m1m0 = 11 means 3Select timer work, should be in accordance with the above provisions to be incorporated into the corresponding register in tmod few, such as setting 0 in the regular way timer mode 0, 1 road work in the way of a timer, it is the application of the following instruction set:mov tmod, 10h3 timer counting approach and calculation of initial valuemcs51 single chip using the timer count value in the work from time to time, the start timer, each cpu machine cycle automatically to the appropriate hardware counters 1, until the corresponding counter beyond the maximum that can occur timer overflow, the hardware automatically tf0 (tf1) digital home, users can query tf0 (tf1) bit to determine whether the overflow from time to time, if at this point interrupted from time to time in the open, will lead to the corresponding interrupt from time to time, mcs51 in response to disruption, according to the corresponding interrupt address (0 road regularly interrupted interrupted entrance is located at 000b, 1 Road 001b) the implementation of interrupt handling procedures.Regular programming, there are two basic ways, a way to query the way you start to close from time to time when the corresponding interrupt from time to time, and then the cycle detection tf0 (tf1) corresponding processing。 another way for the interruption of the way from time to time when to start opening up the appropriate timing interruption, and will deal with overflow from time to time for the interruption of programming procedures adopted in the form of disruption in the corresponding entries (000b, 001b) Jump to place orders regularly overflow into the process.The work of the selected timer mode, the timer overflow time of the initial value only depends on the counter, depending on the application need to determine how to counter the initial value, the timer is also an important issue in the application. Assumed that the singlechip machine cycle for k0, selected from time to time for the nbit counter mode, the timing to achieve the length of time for t, are:(2nx) k0 = t (1)One of the initial value x for the counter, according to 1 can be calculated initial value x as follows:x = 2n(t/k0) (2)4 Timer39。s programming step gathers with the general routine which each step gathers. The timer mainly divides into the following several steps using the programming to gather. The step 1 basis fixed time requests to ask the counting starting value x .First according to monolithic integrated circuit clock rate f determination monolithic integrated circuit machine cycle k0, namely: k0 = 12/ fs (3) In the practical application, monolithic integrated circuit clock rate f is generally 6mhz or 12mhz, therefore the monolithic integrated circuit machine cycle k0=2μs or 1μs, then basis designation39。s working determination counter figure n, obtained k0 and n substitution type 2, extracts the counting starting value x, and according to the counting way which chooses x value divides enters th0 (th1) and tl0 (tl1). Step 2 initialization procedures to prepareInitialization procedures and the way of regular programming, interrupt initialization procedure is as follows (Road Timer 0 as an example):mov tmod, n (regular work requirements)mov th0, n1 (set counter low)mov tl1, n2 (counter high settings)setb ea (open interruption)setb et0 (open regularly interrupted 0)setb tr0 (start timing)Query initialization procedure is as follows:mov tmod, n (regular work requirements)mov th0, n1 (set counter low)mov tl1, n2 (counter high settings)clr et0 (open regularly interrupted 0)setb tr0 (start timing)One n1 and n2 and x of the initial count, if we adopt the way of 2, n1 = n2, initialization procedures are all the way to Timer 0 as an example, if a road timer, it will process bit register and control the subscript 1 to 0. Step 3 preparation process from time to timeInterrupt handling procedures are as follows:org 000bjmp b1b1: clre amov th0, n1mov th1, n2Paragraph statement from time to time to deal withretiAmong them, the timer 0 for Road 000b, if the timer for 1 Road 001b, if the timer