0
Write C language program to generate a square wave of 2 KHz frequency on P1.1 pin by using timer 0 and mode 1. Assume XTAL frequency is 11.0592 MHz.
c program • 4.6k  views
0
0

Crystal frequency= 11.0592 MHz
I/P clock = 11.0592 X 106 = 11.0592MHz
1/12x11.0592Mhz = 921.6 Khz
Tin = 1.085μ sec
For 2 kHz square wave
Fout = 2 KHz
Tout = 1/2 X 103
Tout = 500μ sec

Consider half of it = Tout = 250μ sec
N = Tout / Tin = 250/1.085= 230
65536-230= (65306p10 ) =FF1A

Program

#include<reg51.h>  
void delay(void);  
sbit p=P1^5;  
void main (void)  
{ 
    while (1)  
    {  
         p=~p;  
         delay();  
    }  
}  
void delay()  
{  
     TMOD=0X01; //set timer 0 in mode 1 i.e. 16 bit number  
     TL0=0X1AH; //load TL register with LSB of count  
     TH0=0XFFH ; //Load TH register with MSB of count  
     TR0 =1 //Start timer 0  
     While(TF0==0) //wait until timer rolls over  
     TR0=0; //Stop timer 0  
     TF0=0; //Clear timer flag 0  
}
0
Please log in to add an answer.

Continue reading

Find answer to specific questions by searching them here. It's the best way to discover useful content.

Find more