EasyManua.ls Logo

Altera DE1-SoC - User Input;Output Devices (Buttons, Switches, LEDs)

Altera DE1-SoC
45 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
DE1-SOC COMPUTER SYSTEM WITH NIOS II For Quartus II 15.0
#include "nios2_ctrl_reg_macros.h"
#include "key_codes.h" // defines values for KEY0, KEY1, .. .
/* key_pressed and pattern are written by interrupt service routines; we have to declare
* these as volatile to avoid the compiler caching their values in registers */
volatile int key_pressed = KEY2; // shows which key was last pressed
volatile int pattern = 0x0000000F; // pattern for HEX displays
volatile int shift_dir = LEFT; // direction to shift the pattern
/********************************************************************************
* 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
********************************************************************************/
int main(void)
{
/* Declare volatile pointers to I/O registers (volatile means that IO load and store instructions
* will be used to access these pointer locations instead of regular memory loads and stores) */
volatile int * interval_timer_ptr = (int *) 0xFF202000; // interval timer base address
volatile int * KEY_ptr = (int *) 0xFF200050; // pushbutton KEY address
/* set the interval timer period for scrolling the HEX displays */
int counter = 5000000; // 1/(100 MHz) × (5000000) = 50 msec
*(interval_timer_ptr + 0x2) = (counter & 0xFFFF);
*(interval_timer_ptr + 0x3) = (counter >> 16) & 0xFFFF;
/* start interval timer, enable its interrupts */
*(interval_timer_ptr + 1) = 0x7; // STOP = 0, START = 1, CONT = 1, ITO = 1
*(KEY_ptr + 2) = 0xF; /* write to the pushbutton interrupt mask register, and
* set mask bits to 1 */
NIOS2_WRITE_IENABLE( 0x3 ); /* set interrupt mask bits for levels 0 (interval timer)
* and level 1 (pushbuttons) */
NIOS2_WRITE_STATUS( 1 ); // enable Nios II interrupts
while(1); // main program simply idles
}
Figure 20. An example of C code that uses interrupts.
24 Altera Corporation - University Program
2015

Other manuals for Altera DE1-SoC

Related product manuals