As we have discussed earlier, that the delay length depends on the 3 factors- (a) number of clock per machine; (b) Crystal oscillator value and; (c) C compiler. You know the 12 MHz crystal oscillator is applied externally to the 8051 microntroller XTAL pins as the timer in delay works with a clock frequency of 1/12 of the XTAL frequency. It means when you select a crystal oscillator, it will be divided by 12 internally irrespective of the manufacture IC design.
Therefore, if use 11.0592 MHz crystal oscillator with XTAL pins of the microcontroller, we have 11.0592 MHz / 12 = 921.6 kHz as the timer frequency. As a result, each clock has a period of T = 1/921.6kHz = 1.085µs. In other words, Timer 0 counts up each 1.085 us resulting in delay = number of counts × 1.085µs.
2. In DECIMAL:- Convert YYXX values of the TH, TL register to decimal to get a NNNNN decimal, then (65536 - NNNN) × 1.085 µs.
For Example:
- Write an 8051 C program to toggle all the bits of port P1 continuously with some delay in between.
In DECIMAL- 3500H= 13568 in decimal. Now, 65536-13568=51968 and multiply it with 1.085 µs .i.e 51968*1.085=56385.28 µs= 56.384 ms is the approximate delay.
Therefore, if use 11.0592 MHz crystal oscillator with XTAL pins of the microcontroller, we have 11.0592 MHz / 12 = 921.6 kHz as the timer frequency. As a result, each clock has a period of T = 1/921.6kHz = 1.085µs. In other words, Timer 0 counts up each 1.085 us resulting in delay = number of counts × 1.085µs.
The Time delay generated by the timer can be calculated in 2 ways:
1. In HEX:- (FFFF – YYXX + 1) × 1.085 us, where YYXX are TH, TL initial values respectively. Notice that value YYXX are in hex.2. In DECIMAL:- Convert YYXX values of the TH, TL register to decimal to get a NNNNN decimal, then (65536 - NNNN) × 1.085 µs.
For Example:
- Write an 8051 C program to toggle all the bits of port P1 continuously with some delay in between.
#include "REG52.h" void T0Delay(void); void main(void) { while (1) { P1=0x55; T0Delay(); P1=0xAA; T0Delay(); } } void T0Delay(){ TMOD=0x01; TL0=0x00; TH0=0x35; TR0=1; while (TF0==0); TR0=0; TF0=0; }Calculate:- In HEX- FFFFH – 3500H (value of TH0 and TL0) = CAFFH = 51967 + 1 = 51968 51968 × 1.085 ?s = 56.384 ms is the approximate delay.
In DECIMAL- 3500H= 13568 in decimal. Now, 65536-13568=51968 and multiply it with 1.085 µs .i.e 51968*1.085=56385.28 µs= 56.384 ms is the approximate delay.
Comments
Post a Comment