You are on page 1of 8

School of Electronics Engineering (SENSE)

B. Tech – Electronics & Communication Engineering

ECE3003 – MICROCONTROLLER AND ITS


APPLICATIONS

Lab Record
(L37+L38)

Submitted By
20BEC1042 – Meghana R

Submitted To
Dr.Manoj Kumar Rajagopal

Date: 01/03/2022

Page | 1
20BEC1042 ECE3003-Microcontroller and its Applications Lab
LAB 7: TIMERS/COUNTERS OF 8051 (Part I)

Aim: To write an 8051 ASM program to;

1. To generate a frequency of last digit of reg no KHZ on port P2.7. Assume


the crystal frequency as 11.0592 MHz.
2. To toggle bit of P1.7 for every Last digit of reg no Seconds. Assume the
crystal frequency as 33 MHz.

Challenging Tasks:
Task-1:
Write an 8051-assembly language program using timers to generate a frequency
of 10 kHz on port P2.7. Assume the crystal frequency as 24 MHz.
Task-2:
Write an 8051-assembly language program using timers to blink the LED
connected at P1.7 TON of 0.75 seconds and TOFF of 0.25 seconds. Assume the
crystal frequency as 33 MHz.

Program 1:
ORG 0000H
MOV TMOD, #01H
AGAIN: MOV TL0, #1AH
MOV TH0, #0FFH
SETB TR0
LOOP: JNB TF0, LOOP
CLR TR0
CPL P2.7
CLR TF0
SJMP AGAIN
END

Calculations:
For a crystal frequency of 11.0592 MHz, gives 11059200 Hz.

Page | 2
20BEC1042 ECE3003-Microcontroller and its Applications Lab
We know that 1 machine cycle = 12 pulses.
So, no. of instruction cycles per sec is; 11059200/12 = 921600 Hz
And, time period for 1 pulse is; 1/921600 = 1.085 µs
Now for 2kHz, T = 1/f = 1/2kHz = 500 µs (Period of square wave)
For a single high/low pulse, it is 500/2 = 250 µs
Now, 250 µs/1.085 µs = 230, and 65536-230 = 65306
This in hexadecimal is FF1A
Thus, TL = 1AH and TH = FFH

Output 1:
A square-wave with a frequency of 2kHz is produced at port P2.7

Inference 1: We infer that we can generate waves of required frequency in a


port with uniform time interval between each using timers.
Result 1: Thus, ASM programs were written for 8051 µC to perform the port
operations of data using timers and the output is matched with theoretical
calculations.
Page | 3
20BEC1042 ECE3003-Microcontroller and its Applications Lab
Program 2:
ORG 0000H
MOV TMOD, #01H
LOOP: MOV R1, #85
CPL P1.7
AGAIN: MOV TL0, #00H
MOV TH0, #00H
SETB TR0
BACK: JNB TF0, BACK
CLR TR0
CLR TF0
DJNZ R1, AGAIN
SJMP LOOP
END

Calculations:
For a crystal frequency of 33 MHz, gives 33000000 Hz.
We know that 1 machine cycle = 12 pulses.
So, no. of instruction cycles per sec is; 33000000/12 = 2750000 Hz
And, time period for 1 pulse is; 1/2750000 = 0.36 µs
Now, 65536*0.36 µs = 23.59 ms
We need the time delay for 2 s.
So, no. of times to repeat is, 2000/23.59 = 84.78 ≈ 85

Output 2:
Bits of P1.7 port toggle every 2s producing a square-wave with a crystal frequency of 33MHz

Page | 4
20BEC1042 ECE3003-Microcontroller and its Applications Lab
Inference 2: We infer that we can toggle the bits of a particular port with a
required uniform time interval between each using timers.
Result 2: Thus, ASM programs were written for 8051 µC to perform the port
operations of data using timers and the output is matched with theoretical
calculations.

Challenging Tasks:
Challenging Task-1 Program:
ORG 0000H
MOV TMOD, #01H
AGAIN: MOV TL0, #9CH
MOV TH0, #0FFH
SETB TR0
LOOP: JNB TF0, LOOP
CLR TR0
CPL P2.7
CLR TF0
SJMP AGAIN
END

Page | 5
20BEC1042 ECE3003-Microcontroller and its Applications Lab
Calculations:
For a crystal frequency of 24 MHz, gives 24000000 Hz.
We know that 1 machine cycle = 12 pulses.
So, no. of instruction cycles per sec is; 24000000/12 = 2000000 Hz
And, time period for 1 pulse is; 1/2000000 = 0.5 µs
Now for 10kHz, T = 1/f = 1/10kHz = 100 µs (Period of square wave)
For a single high/low pulse, it is 100/2 = 50 µs
Now, 50 µs/0.5 µs = 100, and 65536-100 = 65436
This in hexadecimal is FF9C
Thus, TL = 9CH and TH = FFH

Output - Task 1:
A square-wave with a frequency of approximately 10kHz is produced at port P2.7

Inference (Task-1): We infer that we can generate waves of required frequency


in a port with uniform time interval between each using timers.

Page | 6
20BEC1042 ECE3003-Microcontroller and its Applications Lab
Result (Task-1): Thus, ASM programs were written for 8051 µC to perform the
port operations of data using timers and the output is matched with theoretical
calculations.

Challenging Task-2 Program:


ORG 0000H
RES: SETB P1.7
ACALL DELAY
ACALL DELAY
ACALL DELAY
CLR P1.7
ACALL DELAY
JMP RES
DELAY: MOV R0, #11
START: MOV TMOD, #01H
MOV TH0, #000H
MOV TL0, #000H
SETB TR0
HERE: JNB TF0, HERE
CLR TR0
CLR TF0
DJNZ R0, START
RET
END

Calculations:
For a crystal frequency of 33 MHz, gives 33000000 Hz.
We know that 1 machine cycle = 12 pulses.
So, no. of instruction cycles per sec is; 33000000/12 = 2750000 Hz
And, time period for 1 pulse is; 1/2750000 = 0.36 µs
Now, 65536*0.36 µs = 23.59 ms
For the time delay of 0.75s,
the no. of times to repeat is, 750/23.59 = 31.79 ≈ 32
For the time delay of 0.25s,
the no. of times to repeat is, 250/23.59 = 10.59 ≈ 11

Page | 7
20BEC1042 ECE3003-Microcontroller and its Applications Lab
Output - Task 2:
LED connected to port P1.7 is turned on and off with equal intervals

Inference (Task-2): We infer that we can turn on/off elements connected to a


port with uniform time intervals between each using timers.
Result (Task-2): Thus, ASM programs were written for 8051 µC to perform the
port operations of data using timers and the output is matched with theoretical
calculations.

Page | 8
20BEC1042 ECE3003-Microcontroller and its Applications Lab

You might also like