question archive 3) a) Write a code for creating a square wave of 25% duty cycle on bit 3 of part 1
Subject:Electrical EngineeringPrice:3.86 Bought11
3) a) Write a code for creating a square wave of 25% duty cycle on bit 3 of part 1.
b) Write a code for creating a square wave of 99% duty cycle on bit 7 of part 2.
1. Program 25% duty cycle on bit 3 of port 1.
.INCLUDE "M32DEF.INC"
LDI R20, HIGH(RAMEND)
OUT SPH, R20
LDI R20, LOW(RAMEND)
OUT SPL, R20 ;initialize stack pointer
SBI DDRC, 3 ;set bit 3 of DDRC (PC3 = out)
HERE: SBI PORT1, 3 ;set to HIGH PC3 (PC3 = 1)
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CBI PORT1, 3 ;PC3 = 0
CALL DELAY ;call the delay subroutine
2. The program if 99% duty cycle on bit 7 of port 2.
.INCLUDE "M32DEF.INC"
LDI R20, HIGH(RAMEND)
OUT SPH, R20
LDI R20, LOW(RAMEND)
OUT SPL, R20 ;initialize stack pointer
SBI DDRC, 7 ;set bit 7 of DDRC (PC7 = out)
HERE: SBI PORT2, 7 ;set to HIGH PC7 (PC7 = 1)
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CALL DELAY ;call the delay subroutine
CBI PORT2, 7 ;PC7 = 0
RJMP HERE ;keep doing it
Step-by-step explanation
1. The 25% duty cycle means that the ON state will only toggle every 25% duty cyle of set time. and the rest 75% will be in OFF state. The program will set the pc3 ON every 25% and OFF every 75% of duty cycle.
2. The 99% cycle means that the
almost duty cycle will be in ON state.