Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Name: Devashish Gupta Date: 23/07/2021

Roll.No: J062 Subject: Embedded Systems

Experiment – 3

Roll no.: J062 Name: Devashish Gupta

Sem:- 7 Batch: Embedded Systems

Date of Experiment: 23/07/2021 Date of Submission: 01/08/2021

Aim: Using 8051 generate square wave having 50% and 75% duty cycle and
100Khz frequency
Theory:  The 8051 microcontroller has two independent 16 bit up counting timers
named Timer 0 and Timer 1 and this experiment is about generating time delays using
the 8051 timers. Generating delay using pure software loops are poor in accuracy and
cannot be used in sensitive applications. Delay using timer is the most accurate and
surely the best method.
A timer can be generalized as a multi-bit counter which increments/decrements itself on
receiving a clock signal and produces an interrupt signal up on roll over. When the
counter is running on the processor’s clock , it is called a “Timer”, which counts a
predefined number of processor clock pulses and  generates a programmable delay.
When the counter is running on an external clock source (may be a periodic or aperiodic
external signal) it is called a “Counter” itself and it can be used for counting external
events.
In  8051, the oscillator output is divided by 12 using a divide by 12 network and then fed
to the Timer as the clock signal. That means for an 8051 running at 12MHz, the timer
clock input will be  1MHz. That means the timer advances once in every 1uS and the
maximum time delay possible using a single 8051 timer is ( 2^16) x (1µS) = 65536µS.
Delays longer than this can be implemented by writing up a basic delay program using
timer and then looping it for a required number of time. We will see all these in detail in
next sections of this article.
Now we know that the crystal frequency is 11.0592 MHz hence T=1/f, which is
T=1/11.0592, which gives us T=90.42 nano seconds.

1
Name: Devashish Gupta Date: 23/07/2021
Roll.No: J062 Subject: Embedded Systems

Now in 8051 each machine cycle requires 12 pulses to complete basic operations and
we found time period for single cycle as T hence for 12 cycles T=12 X 90.42 nano
seconds. This will become 1.08504 Micro seconds.

Now to get 10KHz frequency square wave with 50% duty cycle T=1/10KHz, which is
T=100 micro seconds. So for 50% duty cycle each part will be of 50micro seconds. Hence
we will need 50/1.08504 = 46.082 cycle counts made by the timer. Hence the 8bit
counter will have 256-46 counts which is D2 in hex. So we load D2 in TH1 and TL1 for
50% duty cycle.

Code:
50% in Assembly Language

ORG 0000H
LJMP
START ORG
001BH CLR
TF1
CPL P.15
RETI
ORG 1000H
START:
SETB P1.5
MOV IE, #88H
MOV TMOD, #20H
MOV TH1, #0D2H
MOV TL1, #0D2H
SETB TR1
HERE: SJMP
HERE END

50% in C program

#include<reg51.h>
void delay(void) interrupt 3
{
mybit =~ mybit; TF1
= 0;
}
void main()

2
Name: Devashish Gupta Date: 23/07/2021
Roll.No: J062 Subject: Embedded Systems

{
mybit = 1;
IE = 0x00;
TMOD = 0x20;
TH1 = 0xD2;
TL1 = 0xD2;
TR1 = 1;
while(1)
{
}
}

75% in Assembly Language

ORG 0000H /*initialize*/ LJMP


main
org 001BH
CLR TF1
CPL P1.5
MOV TL1, R1
MOV 00, R3
MOV R3,01
MOV R1,00
MOV TH1,R2
MOV 00,R4
MOV R4,02

MOV R2, 00
SETB TR1
CLR TF1
CLR TF1
RETI
ORG 1000H
main:
SETB P1.5
MOV IE, #88H
MOV TMOD,#10H
MOV R1, #0CH
MOV R2, #0FEH
MOV R3, #0E9H
MOV R4, #011FH

3
Name: Devashish Gupta Date: 23/07/2021
Roll.No: J062 Subject: Embedded Systems

MOV TH1,R4
MOV TL1,R3
SETB TR1
HERE: SJMP
HERE END

Output:
50% in Assembly Language

4
Name: Devashish Gupta Date: 23/07/2021
Roll.No: J062 Subject: Embedded Systems

Conclusion:
Attempted to generate a square wave having 50% and 75% duty cycle and 100Khz
frequency, using 8051 microcontroller in Keil Software. We know that the 8 bit
counter will have 256-46 counts which is D2 in Hex format, therefore we loaded
D2 in TH1 and TL1 (Autonomous Mode) for 50% duty cycle, and observed a
square wave.

You might also like