0% found this document useful (0 votes)
93 views5 pages

Q: Write A Program To Generate A Square Wave of 1Khz On P0.0 While Simultaneously Reading Data From P1 and Sending It To P2

Uploaded by

yesfirst000
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)
93 views5 pages

Q: Write A Program To Generate A Square Wave of 1Khz On P0.0 While Simultaneously Reading Data From P1 and Sending It To P2

Uploaded by

yesfirst000
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/ 5

8051 | SQUARE WAVE PROGRAM

Using Timer Interrupt

Q: Write a program to generate a square wave of 1KHz on P0.0 while


simultaneously reading data from P1 and sending it to P2.

org 0
sjmp main ;goto main

org 000bh
sjmp T0ISR ; goto T0 ISR

org 0030h
main:
mov p1, #0ffh ; P1 input port
mov ie, #82h ; enable T0 int
mov tmod, #01h ; T0 - M1
mov tl0, #0ch ; count LB
mov th0, #0feh ; count HB
setb tr0 ; start timer
clr p0.0 ; make P0.0 = 0
again:
mov a, p1 ; A <-- P1
mov p2, a ; P2 <-- A
sjmp again ; loop

T0ISR:
cpl p0.0 ; compl. p0.0
clr tr0 ; make run bit 0
mov tl0, #0ch ; load count LB
mov th0, #0feh ; load count HB
setb tr0 ; start timer 0
reti ; return from isr

end

Delay calculation

Frequency of square wave = 1KHz


Time period = 1 ms
Delay = 0.5 ms
Delay = 500 microsec
Hence we need 500 counts

Count to be loaded = 65535-500+1 = 65036 = FE0CH

Count = FE0CH

www.BharatAcharyaEducation.com
All the best J Watch Video Lectures of all topics by Bharat Acharya Page 1
BHARAT ACHARYA EDUCATION
Videos | Books | Classroom Coaching
E: [email protected]
M: 9820408217

On the Simulator
Load the exact same program…

www.BharatAcharyaEducation.com
All the best J Watch Video Lectures of all topics by Bharat Acharya Page 2
8051 | SQUARE WAVE PROGRAM
Using Timer Interrupt

Run it… You will see P0.0 toggling between 0 and 1… that’s the square wave output as desired…

You can also change the switch inputs on P1 and see the changed output on P2

Observe p1.3 (switch 3) is off (default logic 1 )

In that case P2.3 will also be 1

www.BharatAcharyaEducation.com
All the best J Watch Video Lectures of all topics by Bharat Acharya Page 3
BHARAT ACHARYA EDUCATION
Videos | Books | Classroom Coaching
E: [email protected]
M: 9820408217

But when we press switch 3 (we have made p1.3 = 0)

As a result P2.3 will also become 0

This shows that we are doing both operations simultaneously. While a square wave is being produced
on p0.0 at the same time we are transmitting value from p1 to p2

www.BharatAcharyaEducation.com
All the best J Watch Video Lectures of all topics by Bharat Acharya Page 4
8051 | SQUARE WAVE PROGRAM
Using Timer Interrupt

https://www.bharatacharyaeducation.com
Learn...
8085 | 8086 | 80386 | Pentium |
8051 | ARM7 | COA

Fees: 1199/-
Duration: 6 months
Activation: Immediate
Certification: Yes
Free: PDFs of theory explanation
Free: VIVA questions and answers
Free: PDF of Multiple Choice Questions

Start Learning... NOW!


https://www.bharatacharyaeducation.com

Order my Books here...

8086 Microprocessor book


Link: https://amzn.to/3qHDpJH

8051 Microcontroller book


Link: https://amzn.to/3aFQkXc

#bharatacharya
#bharatacharyaeducation
#8086 #8051 #8085 #80386 #pentium
#microprocessor #microcontrollers

www.BharatAcharyaEducation.com
All the best J Watch Video Lectures of all topics by Bharat Acharya Page 5

You might also like