
DE1-S
O
C C
OMPUTER
S
YSTEM WITH
N
IOS
II
For Quartus II 15.0
request to be sent to the processor whenever
TO
becomes 1. After an interrupt occurs, it can be cleared by writing
any value into the
Status
register.
3.4
Using Interrupts with Assembly Language Code
An example of assembly language code for the DE1-SoC Computer that uses interrupts is shown in Figure
16
.
When this code is executed on the DE1-SoC board it displays a rotating pattern on the HEX 7-segment displays.
The pattern rotates to the right if pushbutton
KEY
1
is pressed, and to the left if
KEY
2
is pressed. Pressing
KEY
3
causes the pattern to be set using the SW switch values. Two types of interrupts are used in the code. The HEX
displays are controlled by an interrupt service routine for the interval timer, and another interrupt service routine is
used to handle the pushbutton keys. The speed at which the HEX displays are rotated is set in the main program, by
using a counter value in the interval timer that causes an interrupt to occur every 33 msec.
.
equ
KEY2, 1
/********************************************************************************
* This program demonstrates use of interrupts in the DE1-SoC Computer. It first starts the
* interval timer with 33 msec timeouts, and then enables interrupts from the interval timer
* and pushbutton KEYs
*
* The interrupt service routine for the Altera interval timer displays a pattern on the HEX3-0
* displays, and rotates this pattern either left or right:
*
KEY[0]: loads a new pattern from the SW switches
*
KEY[1]: rotates the displayed pattern to the right
*
KEY[2]: rotates the displayed pattern to the left
*
KEY[3]: stops the rotation
********************************************************************************/
.
text
/* executable code follows */
.
global
_start
_start:
/* set up stack pointer */
movia
sp, 0x03FFFFFC
/* stack starts from highest memory address in SDRAM */
movia
r16, 0xFF202000
/* internal timer base address */
/* set the interval timer period for scrolling the HEX displays */
movia
r12, 5000000
/* 1/(100 MHz)
×
(5000000) = 50 msec */
sthio
r12, 8(r16)
/* store the low halfword of counter start value */
srli
r12, r12, 16
sthio
r12, 0xC(r16)
/* high halfword of counter start value */
Figure 16. An example of assembly language code that uses interrupts (Part
a
).
16
Altera Corporation - University Program
2015