Aim:
To Write a C program to generate a square waveform having equal duty cycles of
20ms using timer 1 mode 1 operation without the use of pointers. Assume crystal frequency
24 MHz.

Generation of a square waveform without pointer 
Algorithm:

Step1. Calculate the content of timer 1 register.
i. Calculate the clock frequency of timer using crystal frequency.
ii. Calculate the time period of each clock pulse using clock frequency.
iii. Calculate the values of TL1 and TH1 and load the values in timer 1.
iv. Find the value of TMOD register for the selection of timer 1 and mode 1.
v. Find the value of Interrupt Enable register (IE) for enabling the timer 1 interrupt.
Step 2. Include the header file for 8051 microcontroller.
Step 3. For getting the square wave output choose port 2 and 5th pin.
Step 4. Declare the timer 1 function to toggle the waveform.
Step 5. Define the TH1, TL1, TMOD, IE values in main function in order to get the square
waveform with equal duty cycle of 20 ms in timer 1 mode 1
Step 6. Use while of one to get the continuous square wave output in 5th pin of port 2.
Step 7. Execute the program and check the output in port 2 as well as in logic analyser. 

Keil C program for generation of a square waveform without pointer.
#include <reg51.h>
sbit WAVE =P2^5;
void timer1(void) interrupt 3
{
WAVE=~WAVE;
}
void main()
{
TMOD=0x10;
TL1=0x0C0;
TH1=0x63;
IE=0x88;
TR1=1;
while(1)
{}

Generation of a square waveform with pointer
Algorithm:
Step 1. Calculate the content of timer 1 register.
i.
Calculate the clock frequency of timer using crystal frequency.
ii.
Calculate the time period of each clock pulse using clock frequency.
iii.
Calculate the values of TL1 and TH1 and load the values in timer 1.
iv.
Find the value of TMOD register for the selection of timer 1 and mode 1.
v.
Find the value of Interrupt Enable register (IE) for enabling the timer 1 interrupt.
Step 2. Include the header file for 8051 microcontroller.
Step 3. Initialize pointer variable.
Step 3. For getting the square wave output choose port 2 and 5th pin.
Step 4. Declare the timer 1 function to toggle the waveform.
Step 5. Define the TH1, TL1, IE values and pointer variable in TMOD register in main function
to get the square waveform with equal duty cycle of 20 ms in timer 1 mode 1.
Step 6. Use while of one to get the continuous square wave output in 5th pin of port 2.
Step 7. Execute the program and check the output in port 2 as well as in logic analyser.
Keil C program for generation of a square waveform with pointer.
#include <reg51.h>
Int a=0x10;
Int *txp=&a;
Sbit WAVE =P2^5;
Void timer1(void) interrupt 3
{
WAVE=~WAVE;
}
Void main()
{
TMOD=*txp;
TL1=0x0C0;
TH1=0x63;
TE=0x88;
TR1=1;
While(1)
}