Circuit Diagram :
Source code :
#include <reg52.h>
#include <stdio.h>
sbit LED = P1^0; // Defining LED pin
static unsigned long overflow_count = 0;
bit flag=0;
void timer0_ISR (void) interrupt 1
{
overflow_count++; /* Increment the overflow count */
if(overflow_count>=10){ // for 500ms seconds loop
if(flag==1){LED=1;flag=0;}
else if(flag==0){LED=0;flag=1;}
overflow_count=0;
}
TF0=0; // clear timer interrupt
}
void main (void)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B; // load Calculated value for 50ms delay
ET0 = 1; /* Enable Timer 0 Interrupts */
TR0 = 1; /* Start Timer 0 Running */
EA = 1; /* Global Interrupt Enable */
while (1)
{
}
}
Source code :
#include <reg52.h>
#include <stdio.h>
sbit LED = P1^0; // Defining LED pin
static unsigned long overflow_count = 0;
bit flag=0;
void timer0_ISR (void) interrupt 1
{
overflow_count++; /* Increment the overflow count */
if(overflow_count>=10){ // for 500ms seconds loop
if(flag==1){LED=1;flag=0;}
else if(flag==0){LED=0;flag=1;}
overflow_count=0;
}
TF0=0; // clear timer interrupt
}
void main (void)
{
TMOD=0x01;
TL0=0xFD;
TH0=0x4B; // load Calculated value for 50ms delay
ET0 = 1; /* Enable Timer 0 Interrupts */
TR0 = 1; /* Start Timer 0 Running */
EA = 1; /* Global Interrupt Enable */
while (1)
{
}
}