Update

One new tab added. Open in browser view if it is not visible. (25/08/2022 08:48)

Timer Interrupt Generation in 8051

Internal interrupt (Timer Interrupt)

8051 has two internal interrupts namely timer0 and timer1. Whenever Timer overflows, TFx (Timer overflow) flag is set.
This causes the PC to jump to the Vector address of the configured interrupt.

So for this to happen, Global interrupt has to be enabled. After that timer interrupt should be enabled.

 

1) Interrupt.c

//INTERRUPT GENERATE AND ISR USED TO TOGGLE LED
#include<reg51.h>
sbit led=P1^0;
//sbit sw=P3^3;

void intrpt_init()
{
        EA=1;
        //EX1=1;// ENABLE EXT INTERRUPT 0
        //IT1=1;// FALLING EDGE
        ET0=1;// ENABLE TIMER 0 INTERRUPT
}

void timer0(){
TMOD=0X01;    //    16 BIT MODE         TH0=0x4C;    //    50 MS DELAY
TL0=0x0B; 
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}

//ISR
void timer0_int() interrupt 1
{
led^=1;
}

void main()
{
        intrpt_init();
        while(1)
            {
timer0();
            }
}



No comments: