Hi Myriam,
Without getting into a discussion about better ways of handling buttons, here are some changes that should get your code doing what you expected it to do:
# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "stdio.h"# include "stdlib.h"
int alt_main (void)
{
alt_u8 led;
alt_u8 button;
while (1)
{
button = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE);
switch (button) {
case 0x1 :
led=0x1;
break;
case 0x2 :
led=0x2;
break;
case 0x4 :
led=0x4;
break;
case 0x8 :
led=0x8;
break;
}
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);
}
Note that the button PIO is read with an IORD_ function call.
I imagine your problem with printf is that you do not have a device configured for stdout.