Question: Consider the following AVR assembly code shown below (with some information missing) that waits for 1 minute using the 16-bit Timer/Counter1 with the system clock

Consider the following AVR assembly code shown below (with some information missing) that waits for 1 minute using the 16-bit Timer/Counter1 with the system clock frequency of 16 MHz operating under the CTC mode. Write and explain the instructions in lines (1-10) necessary to make this code work properly for the highest resolution. More specifically,

(a) Fill in lines (1-2) with the necessary code to enable the interrupt on Timer/Counter1 output compare match.

(b) Fill in lines (3-6) with the necessary code to load the value for delay that generates an interrupt after 4 seconds.

(c) Fill in lines (7-8) with the necessary code to set the prescaler, value, and the mode of operation.

(d) Fill in line (9) with the necessary code to set counter.

(e) Fill in line (10) with the necessary code to decrement counter.

.include "m128def.inc"

.def mpr = r16

.def counter = r17

.cseg ; beginning of code segment

.ORG $0000

RJMP INIT ; reset interrupt

.ORG $0018 ; Timer/Counter1 Compare Match A interrupt vector

RJMP Reload_counter

.ORG $0046 ; end of interrupt vectors

INIT:

_______________________(1) ; Enable interrupt on Timer/Counter1

; Output Compare A Match

_______________________(2)

SEI ; Enable global interrupt

_______________________(3) ; Load the value for delay

_______________________(4)

_______________________(5)

_______________________(6)

_______________________(7) ; Set prescaler and mode

_______________________(8)

_______________________(9) ; Set counter

LOOP:

CPI counter, 0 ; Repeat until interrupted

BRNE LOOP

...

Reload_counter:

PUSH mpr ; Save mpr

____________________(10) ; Decrement counter

POP mpr ; Restore mpr

RETI

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!