Tuesday, December 18, 2012

Programming Timer and Counter in AT89S51/52 Part 2

Figure 1. Timer 1 in Work Mode 2

Robometricschool. - We will to continue our discussion about programming timer and counter in AT89S51/52 in part 2. In programming timer and counter in AT89S51/52 part 1, we discussed about basically, features, work mode, and register timer and counter in AT89S51/52. In part 2, we will continue to discuss programming timer and counter about how to setting timer and counter in AT89S51/52.

Lets to attention figure 1 above, figure 1 is a schematic circuit arrangement that could happen to Timer 1 is complete, also described the relationships forming and control registers Timer 1. This figure applies to Timer 0.
In actual use, the circuit consumes only part of a complete, in accordance with the purposes of the system is built. Desired circuit formed by setting registers TMODE, while the work of the timer is controlled through register TCON.
After MCS51 register is reset 00H TMOD value, this means:
  • bit C / T * = '0 ', according to Figure 42 situation makes the switch S1 to the top, the source pulse signal from the crystal oscillator whose frequency is divided by 12, which is formed by a binary counter TL1 and TH1 serves as a timer. If you really want a system that is designed to work as a timer Timer 1 then bits C / T * do not need to be set again. But if the system is designed calls for Timer 1 works as a counter to count the pulses coming through kakai T1 (P3.5), the position of the switch S1 must to down by making bits C / T * to '1 '. 
  • GATE bit = '0 ', it makes the output of the OR gate is always '1' is not influenced state '0 'or '1' on foot INT1 (P3.3). In these circumstances, the switch S2 is only controlled through TR1 bit in TCON register. If TR1 = '1 'switch S2 is closed so that the signal is transmitted to the pulse of the S1 counter binary system, the pulse signal flow will be stopped if TR = '0'. Conversely, if the bit GATE = '1 ', the output of the OR gate will follow the state of INT1 feet, when INT1 = '0' bit TR1 whatever the state of the AND gate output is always = '0 'and switch S1 is always open, so that the switch can be closed S1 foot INT1 and TR1 bit must = '1 'simultaneously. 
If the job requires a system designed from the timer / counter control of signals from outside the chip, then it should be made into the GATE bit '1 'bits M1 and M0 = '0', the TL1 and TH1 compiled into 13-bit binary counter (Mode 0 ), if desired Timer 1 works in mode 1 as shown in figure 1, the bit M1 should be made into a '0 'and bits M0 be '1 '.

The time delay is widely used in  microcontroller programming to generate pulses, generating a periodic signal with a certain frequency, to eliminate the effect of vibration scalar in making key pad (simple keyboard) and others.

The time delay can be generated simply by running instructions implementation time can be calculated with precision. To get a long delay time, do not use the above but use the timer. The time delay is formed by both methods is highly dependent on the microcontroller operating frequency, the following examples are considered microcontroller works at a frequency of 12 MHz. These instructions can be used to generate pulses '0 'with a width of 3 micro-seconds on foot P1.0.

01: CLR P1.0
02: NOP              ; 1 micro-second
03: NOP              ; 1 micro-second
04: SETB P1.0   ; 1 micro-second

The first line of the instructions make the early P1.0 '1 'to '0', the implementation of the NOP instruction takes 1 micro-second (if MCS51 works at a frequency of 12 MHz), P1.0 SETB instruction also takes 1 micro-second , total time before P1.0 back to '1 'is 3 micro-seconds (lines 2, 3 and 4).

From this discuss you can improve your ability to use timer and counter in AT89S51/52 to other application.


Post a Comment

Thank's for your visiting and reading this article, please share your idea with comment here