通过上个程序,我打开了ASF EXPLORER中的快速指导
里边有Quick Start Guide快速指导,然后打开
根据提示形成程序。只不过我的开发板管脚
分配不一样。我的是
按键PA20
LED PA0
最后形成程序:
- #include <asf.h>
- void pin_edge_handler(const uint32_t id, const uint32_t index)
- {
- if ((id == ID_PIOA) && (index == PIO_PA20)){
- if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA20))
- pio_clear(PIOA, PIO_PA0);
- else
- pio_set(PIOA, PIO_PA0);
- }
- }
- int main (void)
- {
- /* Insert system clock initialization code here (sysclk_init()). */
- board_init();
-
-
- pmc_enable_periph_clk(ID_PIOA);
- pio_set_output(PIOA, PIO_PA0, LOW, DISABLE, ENABLE);
- pio_set_input(PIOA, PIO_PA20, PIO_PULLUP);
- pio_handler_set(PIOA, ID_PIOA, PIO_PA20, PIO_IT_EDGE, pin_edge_handler);
- pio_enable_interrupt(PIOA, PIO_PA20);
- NVIC_EnableIRQ(PIOA_IRQn);
-
-
- while(1)
- {
-
- ;
- }
- /* Insert application code here, after the board has been initialized. */
- }
以下是运行时,调试的截图:
|