How to generate one second and one minute delay using timer in 8051?

In 8051 using 11.0592MHZ crystal, we can able to generate a maximum delay of 65536x1.08us=0.07 sec only.

By using 8051, we cannot able to obtain the delay which is greater than 0.07 sec. So, to obtain the delay greater than 0.07 sec we need to call millisecond or microsecond delay for a certain amount of time.

Supposed I want to generate a delay of one second.To obtain this delay, it is necessary to convert one second into a millisecond or microsecond.

We know that,

1 second = 1000 msec

We can rewrite the 1000 milliseconds as follows:

50msec*20 = 1000msec

Now, according to the calculation mentioned above first, we need to generate a delay of 50 msec and then we need to call this delay 20 times. By doing this we can able to obtain a delay of 1 sec.By calling one second delay 60 times I have generated one minute delay.

-----------------------------------------------------------------------------------

I have written a program to blink the LED for one minute.In between ON/OFF interval of LED I have kept one second delay.

SOFTWARE: KEIL MICRO VISION 4

SIMULATOR: PROTEUS 8.0

CIRCUIT DIAGRAM:

PROGRAM:

#include<reg51.h>

sbit led= P1^0;        //  LED at P1.0 pin

void delay(void);  // 50 msec delay function

void sec(void);   // 1 sec delay function

void main()

{

int i=60;

while(i>0){        // led blinking for 60 times=60 secs(1 minute)

led=0 ;//led on

sec();       // one second delay

led=1; //led off

i--;

}

while(1);

}

void delay (void) // 50 msec delay function

{

TMOD=0X01;  // timer 0 mode 1

TL0=0X28;  // delay of 50msec

TH0=0x4b;

TR0=1;     // start the timer

while(TF0==0); // wait for overflow

TR0=0;        // stop the timer

TF0=0;    // clear overflow flag

}

void sec(void) // one second delay function

{

int i;

for(i=0;i<20;i++)

{

delay(); // calling 50 msec delay 20 times

}

}

PROGRAM DESCRIPTION:

First, the LED gets turned ON and after the delay of one second, it will get turned OFF. This process will get continued for one minute. For this, I have used timer 0 in mode 1.

I have generated one second delay by calling 50 msec delay 20 times.

By calling one second delay 60 times I have generated one minute delay.

Ideally LED should be blink for one minute but practically it is not possible as instruction execution takes some time. For more understanding please watch the below video.

Calculation of timer value to be loaded in TH0 and TL0 register:

I have taken the micro-controller with a crystal frequency of 11.0592MHZ frequency.So the calculation is

1.   (11.0592 MHZ) / 12 = 921600 HZ.

2.   1 / (921600) = 1.08*10^-6 sec.

3.   Count= Required time / Processor time

4.   Here the required time is 50 msec

5.   Count = (50*10^-3) / (1.08*10^-6)

6.   Count = 46296.296=46296(decimal)

7.   Value to be loaded in timer register:

        65536 - 46296 = 19240= 4b28(hex)  

    8. So in TH0 = 0x4b and TL0 = 0x28.


VIDEO:



Note:

1.Please refer the below link to know about TMOD,TCON and timer registers of 8051.

https://embeddedprojects222.blogspot.com/2020/08/timer-registers-of-8051.html

2.Please refer the below link to know about timer interfacing with 8051.
https://embeddedprojects222.blogspot.com/2020/08/timer-interfacing-with-8051.html




Comments

Popular posts from this blog

Digital Thermometer using 8051 and ADC 0808 Interfacing With 8051

how to display numbers on lcd?

Introduction of IODIR,PINSEL,IOSET and IOCLR Registers