Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

C in a tabell

#include

<stdio.h>

#include

"altera_avalon_pio_regs.h"

#include

"system.h"

int

main()

{

int

rx_char;

char

line[100];

#define

PERIPH_SYS_LEDS_PIO_BASE PIO_0_BASE

#ifdef

NEEK_ID_NAME

#define

PATTERN1 0x02

#define

PATTERN2 0x03 // clears LEDs

#define

PATTERN3 0x03 // clears LEDs

#define

PATTERN4 0x01

#define

NULL_PATTERN 0x03 // clears LEDs

#else

#define

PATTERN1 0x03

#define

PATTERN2 0x0C

#define

PATTERN3 0x30

#define

PATTERN4 0xC0

#define

NULL_PATTERN 0x00 // clears LEDs

#endif

IOWR_ALTERA_AVALON_PIO_DATA(PERIPH_SYS_LEDS_PIO_BASE,NULL_PATTERN);

// Clear LEDs

// Print the message to STDOUT...

printf

("This is Lab1b for the nios II Software Development class\n\n");

#ifdef

NEEK_ID_NAME

printf(

"\nPlease choose an LED pattern: Press 1 or 4\n");

printf(

"Note: Only LEDs 1 and 4 are connected on NEEK Board!\n");

#else

printf

("\nPlease choose an LED pattern: Press 1 to 4\n");

#endif

while

(1)

{

printf

("\nType Value Now (followed by Enter):");

fgets

(line, sizeof(line),stdin);

sscanf

(line,"%d",&rx_char);

switch

(rx_char)

{

case

4:

printf

("\nLED Pattern 4\n");

IOWR_ALTERA_AVALON_PIO_DATA(PERIPH_SYS_LEDS_PIO_BASE,PATTERN4);

break

;

case

3:

printf

("\nLED Pattern 3\n");

IOWR_ALTERA_AVALON_PIO_DATA(PERIPH_SYS_LEDS_PIO_BASE,PATTERN3);

break

;

case

2:

printf

("\nLED Pattern 2\n");

IOWR_ALTERA_AVALON_PIO_DATA(PERIPH_SYS_LEDS_PIO_BASE,PATTERN2);

break

;

case

1:

printf

("\nLED Pattern 1\n");

IOWR_ALTERA_AVALON_PIO_DATA(PERIPH_SYS_LEDS_PIO_BASE,PATTERN1);

break

;

default

:

printf

("Please enter an integer value from 1 to 4\n");

break

;

}

}

return

0;

}

3 Replies