I am using an DE0 board and wanted to count number of slide switches in ON position (there are 10 of these), and then lit corresponding number of LED (10 of these too) on the board. However I don't know how to use the result from masking to the IOWR. Thank you
alt_u16 sw;
volatile int i = 0;
alt_u16 count = 0x0;
alt_u16 mask = 0x0001;
alt_u16 sw2;
int CountSWITCHES(alt_u16 sw);
int alt_main (void)
{
while(1)
{
sw = IORD_ALTERA_AVALON_PIO_DATA(SWITCHES_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(LEDS_BASE, sw2);
}
return 0;
}
int CountSWITCHES(alt_u16 sw)
{
for(i = 0; i < 10; i++)
{
if (sw & mask)
{
count++;
}
mask = mask >> 1;
}
return count;
}
void TurnLedsON(alt_u16 sw2)
{
sw2 = CountSWITCHES(sw);
}