Friday, 26 May 2017

8051timer0Mode_1(16Bit mode)

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)
  {
  }
}


Simulation Link : https://youtu.be/70hKILTVs1M


No comments:

Post a Comment

ESP8266 Multiple Timer

ESP8266 Maximum upto 7 OS_Timer Source code : #include <Arduino.h> extern "C" { #include "user_interface.h...