0
8.1kviews
Write C language program to generate square wave of frequency 5 KHz on p3.5 pin of mc 89c51. Use timer 1, mode 1 to generate delay. Assume XTAL = 11.0592 MHz.
1 Answer
1
431views

*Crystal frequency= 11.0592 MHz*

I/Pclock=11.0592 X 106 =11.0592MHz

1/12x11.0592Mhz= 921.6Khz

Tin =1.085μsec

For5 kHzsquarewave

Fout = 5KHz

$Tout =1/5 \times 10^3$

Tout =200μsec

Consider half ofit=Tout = 100μ sec

N =Tout / Tin =100/1.085= 92.16

65536-92= 65444(10)=FFA5 H

Program

#include< reg51.h>

void delay(void);

sbit p=P3^5;

void main (void)

{

    while (1)

    {

        $\ \ \ $ p=~p;

        delay();

    }

}

void delay()

{

    TMOD=0X10; $\ \ \ \ \ \ \ \ \ $//set timer 1 in mode 1 i.e. 16 bit number

    TL0=0XA5H; $\ \ \ \ \ \ \ \ \ $//load TL register with LSB of count

    TH0=0XFFH ; $\ \ \ \ \ \ \ \ \ $//Load TH register with MSB of count

    TR1 =1 ; $\ \ \ \ \ \ \ \ \ $//Start timer 0

    While(TF1==0) $\ \ \ \ \ \ \ \ \ $//wait until timer rolls over

    TR1=0; $\ \ \ \ \ \ \ \ \ $//Stop timer 0

    TF1=0; $\ \ \ \ \ \ \ \ \ $//Clear timer flag 0

}
Please log in to add an answer.