Write a program to generate a square wave of 100Hz using timers | Using Keil C – AT89C51| C Language|

Calculation:

We know that

T=1/f

f=100Hz

T=1/100Hz

T=0.01

Divided by 2 for to make it half ON and half Off

T=0.01/2

T=5msec

Now,

Count For 5mSec=  x5x10-3=4608.29

Now for MODE1=16-bits=210 =65536

Counter initial value = 65536 -4608.29=60927.71

In hex =THTL=EE00

TH0=EE

TL0=00

Source code:

#include <reg51.h>

void ms_delay();

void main()

{

TMOD =0x01; //

while(1)

{

P1=0xFF;

ms_delay();

P1=0x00;

ms_delay();

}

}

void ms_delay()

{

TL0=0X00;

TH0=0X0EE;

 

TR0=1;

 

while(!TF0);

 

TR0=0;

TF0=0;

}

Result:









Post a Comment

0 Comments