ECE 375 Computer Organization and Assembly Language Programming


Rate this product

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
.include “”
.def mpr = r16
.org $0000
.org $0006
.org $000C
.org $000E
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

{ …
…do something…



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 “”
.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
(1) ; Enable interrupt on Timer/Counter0 overflow
SEI ; Enable global interrupt
(3) ; Load the value for delay
(4) ;
(5) ; Set prescalar and mode
(6) ;
(7) ; Set counter
CPI counter, 0 ; Repeat until interrupted

PUSH mpr ; Save mpr
(8) ; Load the value for delay
(9) ;
(10) ; Decrement counter
POP mpr ; Restore mpr
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 “”
.def mpr = r16
.def temp = r17
.equ step =

; 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
; Initial compare value for PWM output
sbis PIND, 0
rjmp MAIN
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 “”
.def mpr = r16
.ORG $0000

.ORG $0026
RJMP SendData

.ORG $0046

…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

ld mpr, X+ ; Send first data
out UDR0, mpr
ld mpr, X+ ; Send next data
out UDR0, mpr

Open chat
Need help?
Can we help you?