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 16 MHz and the system is using an ATmega328. Solution: .ORG O LDI OUT R16, HIGH (RAMEND) SPH RIG

EBK ELECTRICAL WIRING RESIDENTIAL
19th Edition
ISBN:9781337516549
Author:Simmons
Publisher:Simmons
Chapter25: Television, Telephone, And Low-voltage Signal Systems
Section25.3: Signal System
Problem 1R
icon
Related questions
Question

Trying to learn Assembly (Person Problem not graded)

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 16 MHz and the system is using an ATmega328.
Solution:
.ORG O
BACK:
LDI
OUT
LDI
OUT
L1:
L2:
13:
LDI
COM
OUT
CALL
RJMP
DELAY 1S:
LDI
LDI
LDI
DEC
BRNE
R16, HIGH (RAMEND)
SPH, R16
R16, LOW (RAMEND)
SPL, R16
R16,0x55
R16
PORTB, R16
DELAY 1S
BACK
R20, 64
R21, 200
R22,250
NOP
NOP
DEC
BRNE L3
R22
R21
L2
DEC
BRNE L1
RET
R20
; load R16 with 0x55
; complement PORTB
; send it to port B
;time delay
; keep doing this indefinitely
2014
Transcribed Image Text: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 16 MHz and the system is using an ATmega328. Solution: .ORG O BACK: LDI OUT LDI OUT L1: L2: 13: LDI COM OUT CALL RJMP DELAY 1S: LDI LDI LDI DEC BRNE R16, HIGH (RAMEND) SPH, R16 R16, LOW (RAMEND) SPL, R16 R16,0x55 R16 PORTB, R16 DELAY 1S BACK R20, 64 R21, 200 R22,250 NOP NOP DEC BRNE L3 R22 R21 L2 DEC BRNE L1 RET R20 ; load R16 with 0x55 ; complement PORTB ; send it to port B ;time delay ; keep doing this indefinitely 2014
Write an assembly language program, using a triple loop concept, to generate a ½-second delay and
toggle a signal on PORTB. See Example 3-20 in the textbook (page 103 in the 2nd edition) for an example
of the triple loop idea. Get the delay as close to a ½-second as possible.
Transcribed Image Text:Write an assembly language program, using a triple loop concept, to generate a ½-second delay and toggle a signal on PORTB. See Example 3-20 in the textbook (page 103 in the 2nd edition) for an example of the triple loop idea. Get the delay as close to a ½-second as possible.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Logic Gate and Its Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, electrical-engineering and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK ELECTRICAL WIRING RESIDENTIAL
EBK ELECTRICAL WIRING RESIDENTIAL
Electrical Engineering
ISBN:
9781337516549
Author:
Simmons
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Electricity for Refrigeration, Heating, and Air C…
Electricity for Refrigeration, Heating, and Air C…
Mechanical Engineering
ISBN:
9781337399128
Author:
Russell E. Smith
Publisher:
Cengage Learning