Generation of 2 kHz Square Waveform

To generate a square waveform of 2 kHz frequency using Timer 1 Mode 2 in assembly language and C language.

C program:

 #include <reg51.h>
 sbit mybit = P1^5;
 void T1M2Delay();
 void main()
 {
 while (1)
 {
 mybit = ~ mybit;
 T1M2Delay();
 }
 }
 void T1M2Delay()
 {
 TMOD = 0x20;
 TH1 = 0x1B;
 TR1 = 1;
 while(TF1==0)
 {}
 TR1 = 0;
 TF1 = 0;
 }

Check waveform using Logic Analyzer window in Keil µVision C51.

Advertisements
%d bloggers like this: