#Microcontrollers 8051 LED Toggling using Timer Generated Delay


#include <reg51.h>

void delay(void);

void main()

{

  int k;

P3 = 0x00;

while(1)

{

P3 = 0x00;

for(k=0;k<4;k++)

{

delay();

}

P3 = 0xFF;

for(k=0;k<4;k++)

delay();

}

}


void delay()

{

TMOD = 0x10;        //select the timer mode by the registers//

TH1 = 0x00;        // store the delay time in higher bit//

TL1 = 0x00;        // store the delay time in low

TR1 = 1;

while(TF1==0);           //decrement the value of the timer till it is zero//

TF1 = 0;            //clear the timer flag //

TR1 = 0;            //OFF the timer//

}

Comments