0% found this document useful (0 votes)
69 views

Micro Lab Task 3

This document contains code examples demonstrating the use of timers and counters on a microcontroller to generate square waves of different frequencies. It includes programs that: 1) Generate a 500Hz square wave using Timer 0 mode 1; 2) Generate a 2KHz square wave using Timer 1 mode 2; 3) Use Counter 1 mode 2 to count input pulses and display the count on LEDs; 4) Generate alternating square waves on two pins using Timer 0; and 5) Generate a 1KHz square wave after 10 counts using Timer 0 and Counter 1.

Uploaded by

Harsha Bomanna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Micro Lab Task 3

This document contains code examples demonstrating the use of timers and counters on a microcontroller to generate square waves of different frequencies. It includes programs that: 1) Generate a 500Hz square wave using Timer 0 mode 1; 2) Generate a 2KHz square wave using Timer 1 mode 2; 3) Use Counter 1 mode 2 to count input pulses and display the count on LEDs; 4) Generate alternating square waves on two pins using Timer 0; and 5) Generate a 1KHz square wave after 10 counts using Timer 0 and Counter 1.

Uploaded by

Harsha Bomanna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Microcontrollers and its Applications

(ECE3003)

Lab Task 3
Sriharsha Bommana (16BEC0215)

Q) ​Write a program to generate a 500Hz square wave frequency using


mode 1 on one of the pins of P1. Examine the frequency using Logic
Analyzer.

Code:

ORG 0000H
MOV TMOD, #01H
here: MOV TL0, #66H
MOV TH0,#0FCH
CPL P1.0
ACALL delay
SJMP here
delay:SETB TR0
again:JNB TF0,again
CLR TR0
CLR TF0
RET
END
Output:

Q) ​Use timer 1 mode 2 to generate a square wave of 2KHz at P2.0

Code:

ORG 0000H
MOV TMOD, #20H
MOV TH1, #19H
here: CPL P2.0
ACALL delay
SJMP here
delay: SETB TR1
again: JNB TF1, again
CLR TR1
CLR TF1
RET
END
Output:

Q) ​Assuming clock pulses are fed into pin TI, write a program for counter
1 in mode 2 to count pulses and display the state of TL1 in P2 which is
connected to 8 LEDs.

Code:

MOV TMOD,#01100000B
MOV TH1,#00H
SETB P3.5
again: SETB TR1
back: MOV A, TL1
MOV P2, A
JNB TF1, back
CLR TR1
CLR TF1
SJMP again
END
Output:

Q) ​Develop an 8051 ALP program to generate square waves as shown


below. examine the same using the KEIL IDE inbuilt Logic Analyzer.

Code:

ORG 0000H
MOV TMOD,#01H
HERE:CPL P2.0
ACALL D
CPL P1.0
ACALL D
SJMP HERE
D: MOV TH0,#0DBH
MOV TL0,#0FFH
SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
CLR TF0
RET
END

Output:

Calculation:

Time period = 1.085 µs


Required frequency (f) = 5 Hz
Required Time Period (T) = 1/f = 20ms
T/2 = 10ms
(T/2)/1.085µs = (9217)10
65,536-9217 = (56319)10 = (DBFF)16

Q) ​Use Counter 1 in mode 2 and after 10 number of counts on TL1,


generate a SQUARE waveform of 1 KHz on P1.2 by using Timer 0 in
mode 1, show the counts in TL1 on port 2.

Code:
ORG 0000
MOV TMOD, #60H;
MOV TH1, #00
SETB P3.5
SETB TR1
AGAIN: MOV A, TL1
MOV P2,A
CJNE A, #10, AGAIN
CLR TR1
CLR TF1
MOV TMOD, #01H;
LOOP:MOV TL0, #0FFH
MOV TH0, #0DBH
CPL P1.2
ACALL DELAY
SJMP LOOP
DELAY:SETB TR0
L1:JNB TF0,L1
CLR TR0
CLR TF0
RET
END
Output:

Calculation:

Required Frequence (F) = 1KHz


T=1ms
T/2=0.5ms
(x)10 = (T/2)/1.085µs = 461
(x)10 = (T/2)/1.085µs = (9217)10
65,536-9217 = (56319)10 = (DBFF)16

You might also like