Starting from:

$30

ECE 375 Computer Organization and Assembly Language Programming

ECE 375
Computer Organization and Assembly Language Programming
Note: I strongly recommend that you utilize the ATmega128 datasheet when solving these questions.
Problem #1 [25 pts]
The AVR code below (with some information missing) is designed to initialize and service interrupts from three I/O devices (DevA,
DevB, and DevC).
(a) There are 8 external interrupt pins (INT0-INT7) in AVR. Based on the code provided, which three interrupt pins are these I/O
devices connected to and what is the immediate value needed in line 1?
(b) Which I/O device’s interrupt is triggered by a low level input?
(c) Assume that pins 7 and 6 on PORTC are connected to an additional output device (DevD). Fill in lines 2-3 such that the
corresponding pins are specified as outputs. Do not configure any other pins on the port as outputs.
(d) Suppose DevA requires that no interrupts are detected while it is being serviced. Fill in lines 4-5 with the necessary code to clear
any latched interrupts at the end of ISR_DevA.
(e) Consider the RCALL instruction on line 0. Would the program function correctly if this line was replaced with the following
underlined text? CALL ISR_DevB Assume that no other lines of code are changed. Provide an explanation to support your
answer.
.include “m128def.inc”
.def mpr = r16
START:
.org $0000
JMP INIT
.org $0006
RJMP ISR_DevA
.org $000C
RCALL ISR_DevB (0)
RETI
.org $000E
RJMP ISR_DevC
INIT:
ldi mpr, 0b00110000
sts EICRA, mpr
ldi mpr, 0b00000100
out EICRB, mpr
ldi mpr, (1)
out EIMSK, mpr
ldi mpr, $00
out DDRD, mpr
out DDRE, mpr
(2)
(3)
sei

MAIN:
{ …
…do something…
}
ISR_DevA:


(4)
(5)
RETI
ISR_DevB:
{…

RET
}
ISR_DevC:
{…

RETI
}
Problem #2 [25 pts]
Consider the following AVR assembly code that waits for 1 second using the 8-bit Timer/Counter0 with the system clock
frequency of 16 MHz operating under Normal mode. Take the time to read through this code and determine how it is designed to
function. Write and explain the instructions in lines (1-10) necessary to make this code work properly. More specifically,
(a) Fill in lines (1-2) with the necessary code to enable the interrupt on Timer/Counter0 overflow.
(b) Fill in lines (3-4) with the necessary code to load the value for delay that generates an interrupt after 5 ms.
(c) Fill in lines (5-6) with the necessary code to set the prescalar value and the mode of operation.
(d) Fill in line (7) with the necessary code to set counter.
(e) Fill in lines (8-9) with the necessary code to reload the value for delay.
(f) Fill in line (10) with the necessary code to decrement counter.
.include “m128def.inc”
.def mpr = r16
.def counter = r17

.ORG $0000
RJMP Initialize
.ORG $0020 ; Timer/Counter0 overflow interrupt vector
JMP Reload_counter
.ORG $0046 ; End of interrupt vectors
Initialize:
(1) ; Enable interrupt on Timer/Counter0 overflow
(2)
SEI ; Enable global interrupt
(3) ; Load the value for delay
(4) ;
(5) ; Set prescalar and mode
(6) ;
(7) ; Set counter
LOOP:
CPI counter, 0 ; Repeat until interrupted
BRNE LOOP

Reload_counter:
PUSH mpr ; Save mpr
(8) ; Load the value for delay
(9) ;
(10) ; Decrement counter
POP mpr ; Restore mpr
RETI
Problem #3 [25 pts]
Consider the AVR code segment shown below (with some missing information) that configures Timer/Counter0 for Fast PWM
operation, and modifies the Fast PWM duty cycle whenever a specific button on Port D is pressed.
(a) Fill in lines (1-2) with the instructions necessary to configure Timer/Counter0 for Fast PWM mode, non-inverting output, and
a prescale value of 8.
(b) Based on the prescale value used in part (a), what is the frequency of the PWM signal (fPWM) being generated by
Timer/Counter0? Assume the system clock frequency is 16 MHz.
(c) Fill in lines (3-4) to provide the compare value for Timer/Counter0 so that the initial duty cycle is 0%.
(d) What would be the value necessary for the variable step to increase the duty cycle by 10% each time the DUTY_STEP
subroutine is executed? Ignore the case when/if the compare value overflows.
.include "m128def.inc"
.def mpr = r16
.def temp = r17
.equ step =
INIT:

; stack pointer is initialized

; I/O ports
ldi mpr, 0b00010000 ; set pin 4 (OC0) as output
out DDRB, mpr

ldi mpr, 0b00000000 ; set pin 0 as input
out DDRD, mpr
ldi mpr, 0b00000001 ; enable pull-up resistor for pin 0
out PORTD, mpr
; Timer/Counter0
; Fast PWM mode, non-inverting, prescale = 8
(1)
(2)
; Initial compare value for PWM output
(3)
(4)
MAIN:
sbis PIND, 0
rcall DUTY_STEP
rjmp MAIN
DUTY_STEP:
push mpr
push temp
in mpr, ________ ; read the current PWM compare value
ldi temp, step
add mpr, temp ; add step value to compare value
out ________, mpr ; write new PWM compare value
pop temp
pop mpr
ret ; return
Problem #4 [25 pts]
Write a subroutine initUSART0 to configure the ATmega128 USART0 to operate as a transmitter that will send data every time
a USART0 Data Register Empty interrupt occurs. The transmitter operates with the following settings:
• 8 data bits, 1 stop bits, and odd parity
• 3,000 Baud rate (note that you will have to choose the closest available rate)
• Transmitter enabled
• Normal asynchronous mode operation
• Interrupt enabled
Assume the system clock is 16 MHz. The skeleton code is shown below:
.include “m128def.inc”
.def mpr = r16
.ORG $0000
RJMP initUSART0

.ORG $0026
RJMP SendData

.ORG $0046
initUSART0:

…Your code goes here. The lines below provide hints as to what you should do…
; Configure USART0 (Port E, pin 1) as output

; Set baud rate to 3,000

; Enable Transmitter and data register empty interrupt

; Set asynchronous mode and frame format

; Set the global interrupt enable bit

Main:
ld mpr, X+ ; Send first data
out UDR0, mpr
Loop:
RJMP Loop
SendData:
ld mpr, X+ ; Send next data
out UDR0, mpr
reti

More products