You are on page 1of 8

EE234 Exam 2

Name: ______________________________
Part 1: Choose the Best Answer (3 points each)
(D )1.
Where does the AVR microcontroller save the return address
during a subroutine call?
(a) on-chip SRAM
(b) program memory
(c) register r30:r31
(d) stack
(A )2. The subroutine delayby100ms receives the multiple of 100 ms in
register r16, what value should be placed in r16 if we want to generate a
delay of 1 second?
(a) 10
(b) 1
(c) 5
(d) 20
(B )3.
To allocate the stack space for local variables, we should
(a) increment the stack pointer
(b) subtract a value which is equal to the number of bytes to allocate from
the stack pointer (c) increment Z pointer
(d) decrement the Z pointer by the value that is equal to the number of bytes
required by the local variables
(C )4.
In the call k instruction, k is
(a) distance of the subroutine
(b) value of the subroutine
(c) address of the subroutine to be called
(d) the first incoming argument of the subroutine
(A )5.
For the icall instruction, the subroutine address is specified in
(a) Z pointer
(b) Y pointer
(c) X pointer
(d) stack pointer

(D )6.
When the ret instruction is executed, what happens?
(a) the return address is popped into the Z pointer
(b) the return address is popped into the Y pointer
(c) the return address is popped into the X pointer
(d) the return address is popped into the PC
(B )7.
After power on reset, the AVR XMEGA automatically selects which
of the following clock source as the system clock before the user changes it?
(a) 32-KHz on-chip oscillator
(b) 2 MHz on-chip RC oscillator
(c) 32 MHz on-chip RC oscillator
(d) external oscillator
(C )8. What should be the multiplying factor for the PLL circuit if you want to
use the 4 MHz external crystal oscillator as the reference clock of the PLL and
generate a 32 MHz system clock?
(a) 2
(b) 4
(c) 8
(d) 16
(A )9. Which of the following instruction sequence can configure PORTA even
pins for output and odd pins for input?
(a) ldi r16,0x55; sts PORTA_DIR, r16
(b) ldi r16,0xAA; sts PORTA_DIR, r16
(c) ldi r16,0xFF; sts PORTA_DIR, r16
(d) ldi r16,0x00; sts PORTA_DIR, r16
(D )10. Which of the following instruction sequence can read from PORTA and
output to PORTB?
(a) lds r20, PORTA_IN, sts PORTB_IN, r20
(b) lds r20, PORTA_OUT, sts PORTB_IN, r20
(c) lds r20, PORTA_IN, sts PORTB_IN, r20
(d) lds r20, PORTA_IN, sts PORTB_OUT, r20

(B )11. Assume that PORTC is driving 8 LEDs. Which of the following


instruction sequence can turn on the LEDs driven by pins 7, 4, and 0 while at
the same time turn off the others? (a) ldi r20, 0x33, sts PORTC_OUT, r20
(b) ldi r20, 0x91, sts PORTC_OUT, r20
(c) ldi r20, 0x44, sts PORTC_OUT, r20
(d) ldi r20, 0x77 , sts PORTC_OUT, r20
(A )12. Refer to Figure E2.1, PC6~PC0 are driving segment inputs g to a.
Which of the following values can display digit 7?
(a) 0x07
(b) 0x70
(c) 0x33
(d) 0x5B
(C )13. Refer to Figure E2.1, which of the following values can display digit 2?
(a) 0x6D
(b) 0x5A
(c) 0x5B
(d) 0x5F

(D )14. Refer to Figure E2.2, what value should be sent to the AD7302 in
order to generate a 1.1 V output from either VOUTA or VOUTB pin?
(a) 70
(b) 80
(c) 75
(d) 85

(C )15. Refer to Figure E2.2, what value should be sent to the AD7302 in
order to generate a 1.5 V output from either VOUTA or VOUTB pin?
(a) 90
(b) 100
(c) 116
(d) 126

Part 2
1. Write a program to generate the periodic waveform shown in Figure E2.3
from the VOUTB pin using the circuit shown in Figure E2.2 assuming that the
subroutine delayby1ms is available to you to call. The multiple value is
passed in r16. The start of the program has been provided, you need only
enter the rest of the program. (15 points)

.include <atxmega128A1def.inc>
.def temp = r16
.cseg
.org 0x00
rjmp start
.org 0xF6
start:
ldi
temp,low(RAMEND)
; initialize the SP
out
CPU_SPL,temp
;

ldi
temp,high(RAMEND) ;

out
CPU_SPH,temp
;

call
setCPUClkto32Mwith16MCrystal
ldi
temp,0xFF
sts
PORTA_DIR,temp
; configure Port A for output
sts
PORTB_DIR,temp
; configure Port B for output
ldi
r20,0x02
sts
PORTB_OUTSET,r20
; select channel B
loopE:
ldi
ZL,low(dacVal<<1)
ldi
ZH,high(dacVal<<1)
ldi
r20,3
; loop count
ldi
r21,0x01
loopI:
sts
PORTB_OUTCLR,r21
; pull WR low
lpm r16,Z+
; perform DAC
sts
PORTA_OUT,r16 ;
"
sts
PORTB_OUTSET,r21
; start D/A conversion
ldi
r16,1
call
delayby1ms
dec r20
brne loopI
jmp loopE
.include "sysClock_xmega.asm"
.include "delays_xmega.asm"
dacVal: .db
0x27,0x74,0xC1

2. Convert the following instruction sequence into a subroutine: (5 points)


sub:

ldi
add
add
add
ret

r20,5
; add a label
r16,r20
r17,r20
r18,r20
; add a ret instruction

3. For the circuit shown in Figure E2.4, write a program to turn on one LED at
a time from top to bottom and then from bottom to top. When turn on LEDs
from top to bottom, the turn-on time from top to bottom are 800ms (top),
700 ms, , 100 ms (bottom). When turn on LEDs from bottom to top, the
turn-on time for LEDs are 800 ms (bottom), 700 ms, , and 100 ms (top).
The delayby100ms subroutine is available for you to call. The multiple of the
delay is passed in r16. (15 points)

start:

Ever:
loop:

.include <atxmega128A1def.inc>
.def temp = r16
.cseg
.org 0x00
rjmp start
.org 0xF6
ldi
temp,low(RAMEND)
; initialize the SP
out
CPU_SPL,temp
;

ldi
temp,high(RAMEND) ;

out
CPU_SPH,temp
;

call
setCPUClkto32Mwith16MCrystal
ldi
r20,0xFF
sts
PORTC_DIR,r20 ; configure PORTC for output
ldi
r18,16
; set up loop count
ldi
ZL,low(ledPat << 1)
ldi
ZH,high(ledPat << 1)
lpm r17,Z+
sts
PORTC_OUT,r17 ; output LED pattern
lpm r16,Z+
call
delayby100ms ; wait for appropriate delay
dec r18
brne loop
jmp Ever
6

ledPat:

.include "delays_xmega.asm"
.include "sysClock_xmega.asm"
.db
0x80,8,0x40,7,0x20,6,0x10,5,0x08,4,0x04,3,0x02,2,0x01,1
.db
0x01,8,0x02,7,0x04,6,0x08,5,0x10,4,0x20,3,0x40,2,0x80,1

4. You are given the circuit that drives a single common anode sevensegment display.
Write down the value to display digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. (10
points)

Solution:
Pattern for
Pattern for
Pattern for
Pattern for
Pattern for
Pattern for
Pattern for
Pattern for
Pattern for
Pattern for

0
1
2
3
4
5
6
7
8
9

is
is
is
is
is
is
is
is
is
is

0x01
0x4F
0x12
0x06
0x4C
0x24
0x20
0x0F
0x00
0x04

5. Assume that the name of a subroutine is testNum and it accepts 3


incoming arguments. Write an instruction sequence to place testNum in Z
pointer, load 23, 45, 57 into r16, r17, r18 and make the subroutine call using
the subroutine call instruction that uses Z pointer to specify the subroutine
address. (10 points)
Solution:
ldi
ZL,low(testNum << 1)
ldi
ZH,high(testNum << 1)
ldi
r16,23
ldi
r17,45
ldi
r18,57
7

icall

You might also like