VTech Alphabert s Magic Readport User Manual Page 26

  • Download
  • Add to my manuals
  • Print
  • Page
    / 80
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 25
Lab Manual of Microcontroller & Interfacing Page 26
EXPERIMENT NO. 6
AIM: Write a program to generate square wave of 50% duty cycle having frequency 5 KHz at
port pin P1.0 using timer 1 in mode 2. Modify program to generate pulse waveform of
70% duty cycle using timer on the same pin.
Calculation of delay:
Time = 1/Frequency = 1/(5x10
3
) = 200 µS
For 50% duty cycle ON time and OFF time are equal
T
ON
= T
OFF
= 100 µS
Time delay required is 100.
If we consider crystal frequency 12 MHz, time to execute one cycle is
T = = 1 µS
If we will use pure software delay to generate delay of 100 µS
Program:
ORG 00h ; Start program from location 00h
CLR P1.0 ; Make P1.0 output pin
next: ACALL delay ; Call delay of 100 µS
CPL P1.0 ; Complement P1.0 to generate square wave
SJMP next
delay: MOV R7,#30h ; Load count value 48 (30h)
loop: DJNZ R7, loop ; Decrement R7 until it becomes zero
NOP ; No operation
RET ; Return to main routine
END
Total number of cycles in delay loop:
Total number if cycles C
T
= C
O
+ C
L
+ C
R
= 1 + 4 82 + 1+2 = 100
Where, C
O
= Number of cycles outside the loop
C
L
= Number of cycles inside the loop
C
R
= Number of cycles for return instruction.
Total time = C
T
x 1 µS = 100 µS
Note: Execute this program using Keil and observe waveforms at port pin P1.0. (Measure
frequency and verify whether it is giving correct value or not)
:: WORKSHEET ::
Exercise:
A. 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.
Memory
Location
HEX
code
Label Opcode Operands Comments
Page view 25
1 2 ... 21 22 23 24 25 26 27 28 29 30 31 ... 79 80

Comments to this Manuals

No comments