You are on page 1of 4

Experiment No.

2
Aim: Write a program to generate square wave of 50% duty cycle having frequency 5 KHz at
port pin P2.1 using timer 1 in mode 2. Modify program to generate pulse waveform of 70% duty
cycle using timer on the same pin.

Circuit Diagram

Fig.1 Circuit diagram for generating the 50% duty cycle pulse having 5 kHz frequency on P2.1 pin

Worksheet 2
1) Modify program for 80% duty cycle
Hint: Use separate delay loop for ON time and OFF time. Total time is 200 s, so use 160 s for
ON time and 40 s for OFF time. You can also prepare delay subroutine of 10 s. Call delay
subroutine 16 times for ON time and 4 times for OFF time.
2) Execute following C program in Keil and measure frequency of the square
wave.
# include <reg51.h>
#include<stdio.h>
sbit wave_pin P1^0;
void sqdelay(unsigned int);
void main(void)
{
while(1)
{
wave_pin=1;
sqdelay(100);
wave_pin=0;
sqdelay(100);
}
}
void sqdelay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1000;j++);
}

Draw waveform (show on time and off time)


3) modifications you suggest in above program to reduce frequency of
square wave to half and increase it to double.
4) Suggest modification in the program to achieve duty cycle 60% without
Changing frequency of the square wave.
5) Calculate the delay length using Timers (8-bit, 16-bit).
6) Write a program to generate a square wave of 3 kHz and 0.5 kHz individually on
pin P1.1
a) Using timer 0 and Timer 1
7) WAP to toggle only pin P1.5 continuously for every 220 ms. Use Timer 0 and
mode 2.
8) WAP to toggle all bits of port P1 continuously with 10 ms delay in between.
9) Why crystal frequency in divided by 12 in 8051?
10) Explain TMOD register?
11) A switch is connected to pin P2.2.WAP to monitor the switch and create the
following frequency on P3.3:
SW=0

100Hz

SW=1

1KHz

You might also like