
DE1-S
O
C C
OMPUTER
S
YSTEM WITH
N
IOS
II
For Quartus II 15.0
#
include
"key_codes.h"
// defines values for KEY0, KEY1,
. . .
extern volatile int
key_pressed;
/********************************************************************************
* Pushbutton - Interrupt Service Routine
*
* This routine checks which KEY has been pressed. It writes this value to the global
* variable KEY_PRESSED.
********************************************************************************/
void
pushbutton_ISR(
void
)
{
volatile int
* KEY_ptr = (int *) 0xFF200050;
int
press;
press = *(K 3);
// read the pushbutton interrupt register
*(K 3) = press;
// clear the interrupt
if
(press & 0x1)
// KEY0
key_pressed = KEY0;
else if
(press & 0x2)
// KEY1
key_pressed = KEY1;
else if
(press & 0x4)
// KEY2
key_pressed = KEY2;
else
// press & 0x8, which is KEY3
key_pressed = KEY3;
return
;
}
Figure 24. Interrupt service routine for the pushbutton keys.
30
Altera Corporation - University Program
2015