Generation of 50 Hz Square Waveform

To generate a square waveform of 50 Hz frequency using Timer 0 Mode 1 in C language.

C Program:
#include <reg51.h>
sbit mybit = P1^5;
void T0M1Delay();
void main()
{
while (1)
{
mybit = ~ mybit;
T0M1Delay();
}
}

void T0M1Delay()
{
TMOD = 0x01;
TL0 = 0xFF;
TH0 = 0xDB;
TR0 = 1;
while(TF0==0)
{}
TR0 = 0;
TF0 = 0;
}

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

Advertisements