Forum Discussion
Altera_Forum
Honored Contributor
20 years agoFinally got this working. This example controls leds and 7-segment display. Tested with Nios II Development Kit, Cyclone II Edition. Disable processor type and features -> enable leds, seven segment display from kernel configuration to disable default blinking code.
#include <errno.h># include <stdio.h>
# include "nios2_system.h"
void nr_pio_showhex(int value)
{
static unsigned char _hex_digits_data = {
0x01, 0x4f, 0x12, 0x06, 0x4c, 0x24, 0x20, 0x0f, 0x00, 0x04, // 0-9
0x08, 0x60, 0x72, 0x42, 0x30, 0x38 // a-f
};
int led_value;
// Left Hand Digit, goes to PIO bits 8-14
led_value = _hex_digits_data;
led_value |= (_hex_digits_data) << 8;
na_seven_seg_pio->np_piodata = led_value;
}
int main (int argc, char* argv)
{
int i;
long x;
np_pio *led;
//np_pio *seven_seg;
led = na_led_pio;
//seven_seg = na_seven_seg_pio;
while(1) {
led->np_piodata = i;
//seven_seg->np_piodata = i;
nr_pio_showhex(i);
i++;
for(x=0; x<655350; x++);
}
return 0;
} Found example of interacting with hardware from http://www.niosforum.com/forum/index.php?a...t=st&f=18&t=710 (http://www.niosforum.com/forum/index.php?act=st&f=18&t=710)here (http://www.niosforum.com/forum/index.php?act=st&f=18&t=710). PIO structure is in C:\altera\kits\nios2\bin\eclipse\plugins\com.microtronix.nios2linux.kernel_1.4.0\linux-2.6.x\include\asm-nios2nommu\pio_struct.h. Copied 7-segment code from C:\altera\kits\nios2\components\altera_avalon_pio\sdk\lib\pio_showhex.c.