Question: Please Explain the given Program we are using Atmega32 Microcontroller. Not do it on Atmel studio just explain all the steps Example 3-20 Write a


Please Explain the given Program we are using Atmega32 Microcontroller. Not do it on Atmel studio just explain all the steps
Example 3-20 Write a program to toggle all the bits of I/O register PORTB every 1 s. Assume that the crystal frequency is 8 MHz and the system is using an ATmega32. Solution: .INCLUDE "M32 DEF. INC" .ORG 0 LDI R16, HIGH (RAMEND) OUT SPH, R16 LDI R16, LOW (RAMEND) OUT SPL, R16 LDI R16,0x55 ;load R16 with Ox55 BACK: COM OUT CALL RJMP R16 PORTB, R16 DELAY 1$ BACK ; complement PORTB send it to port B itime delay ; keep doing this indefinitely R20, 32 R21, 200 R22, 250 DELAY 1S: LDI L1: LDI L2: LDI L3: NOP NOP DEC BRNE R22 L3 DEC BRNE R21 L2 DEC BRNE RET R20 L1 Machine cycle = 1/8 MHz= 125 ns Delay = 32 x 200 x 250 x 5 x 125 ns = 1,000,000,000 ns = 1,000,000 us = 1 s. In this calculation, we have not included the overhead associated with the two outer loops. Use the AVR Studio simulator to verify the delay. Example 3-20 Write a program to toggle all the bits of I/O register PORTB every 1 s. Assume that the crystal frequency is 8 MHz and the system is using an ATmega32. Solution: .INCLUDE "M32 DEF. INC" .ORG 0 LDI R16, HIGH (RAMEND) OUT SPH, R16 LDI R16, LOW (RAMEND) OUT SPL, R16 LDI R16,0x55 ;load R16 with Ox55 BACK: COM OUT CALL RJMP R16 PORTB, R16 DELAY 1$ BACK ; complement PORTB send it to port B itime delay ; keep doing this indefinitely R20, 32 R21, 200 R22, 250 DELAY 1S: LDI L1: LDI L2: LDI L3: NOP NOP DEC BRNE R22 L3 DEC BRNE R21 L2 DEC BRNE RET R20 L1 Machine cycle = 1/8 MHz= 125 ns Delay = 32 x 200 x 250 x 5 x 125 ns = 1,000,000,000 ns = 1,000,000 us = 1 s. In this calculation, we have not included the overhead associated with the two outer loops. Use the AVR Studio simulator to verify the delay
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
