DE1-SOC COMPUTER SYSTEM WITH NIOS II For Quartus II 15.0
/********************************************************************************
* This program demonstrates the use of parallel ports in the DE1-SoC Computer
* It performs the following:
* 1. displays the SW switch values on the red lights LEDR
* 2. displays a rotating pattern on the HEX displays
* 3. if KEY[3..0] is pressed, uses the SW switches as the pattern
********************************************************************************/
int main(void)
{
/* Declare volatile pointers to I/O registers (volatile means that the locations will not be cached,
* even in registers) */
volatile int * LED_ptr = (int *) 0xFF200000; // red LED address
volatile int * HEX3_HEX0_ptr = (int *) 0xFF200020; // HEX3_HEX0 address
volatile int * SW_switch_ptr = (int *) 0xFF200040; // SW slider switch address
volatile int * KEY_ptr = (int *) 0xFF200050; // pushbutton KEY address
int HEX_bits = 0x0000000F; // initial pattern for HEX displays
int SW_value;
volatile int delay_count; // volatile so C compiler does not remove loop
while (1)
{
SW_value = *(SW_switch_ptr); // read the SW slider switch values
*(LED_ptr) = SW_value; // light up the red LEDs
if (*KEY_ptr != 0) // check if any KEY was pressed
{
HEX_bits = SW_value; // set pattern using SW values
while (*KEY_ptr != 0); // wait for pushbutton KEY release
}
*(HEX3_HEX0_ptr) = HEX_bits; // display pattern on HEX3 ... HEX0
/* rotate the pattern shown on the HEX displays */
if (HEX_bits & 0x80000000)
HEX_bits = (HEX_bits << 1) | 1;
else
HEX_bits = HEX_bits << 1;
for (delay_count = 100000; delay_count != 0; −−delay_count); // delay loop
}
}
Figure 9. An example of C code that uses parallel ports.
8 Altera Corporation - University Program
2015