Forum Discussion

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

problem of the example "key_intterput"

hello~there~

The example is easy.but....it didn't work.

when i use the debug....

look at the picture please ~

why?

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    #include <stdio.h># include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "sys/alt_irq.h"# include "priv/alt_busy_sleep.h"

    volatile alt_u32 done = 0;

    static void KeyDown_interrupts(void* context, alt_u32 id)

    {

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);

    done++;

    }

    void InitPIO(void)

    {

    IOWR_ALTERA_AVALON_PIO_DIRECTION(LED_PIO_BASE, 0xFF);

    IOWR_ALTERA_AVALON_PIO_DIRECTION(BUTTON_PIO_BASE, 0x00);

    IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xFF);

    IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x00);

    alt_irq_register(BUTTON_PIO_IRQ, NULL, KeyDown_interrupts);

    }

    int main(void)

    {

    volatile alt_u32 key_state,old_state,new_state;

    old_state = 0xff;

    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, old_state);

    InitPIO();

    while(1)

    {

    if(0 != done)

    {

    done--;

    alt_busy_sleep(5000);

    key_state = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE)&0xFF;

    if(key_state == 0xff)

    continue;

    new_state = ~(old_state ^ key_state);

    old_state = new_state;

    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, new_state);

    }

    }

    return(0);

    }