[Atmel] 用SAM-BA或JLINK跑ATSAM4E16的程序(4)中断查询按键

[复制链接]
1664|1
 楼主| ddllxxrr 发表于 2015-11-1 07:33 | 显示全部楼层 |阅读模式
通过上个程序,我打开了ASF EXPLORER中的快速指导


里边有Quick Start Guide快速指导,然后打开
根据提示形成程序。只不过我的开发板管脚
分配不一样。我的是

按键PA20
LED PA0




最后形成程序:
  1. #include <asf.h>


  2. void pin_edge_handler(const uint32_t id, const uint32_t index)
  3. {
  4.         if ((id == ID_PIOA) && (index == PIO_PA20)){
  5.                 if (pio_get(PIOA, PIO_TYPE_PIO_INPUT, PIO_PA20))
  6.                 pio_clear(PIOA, PIO_PA0);
  7.                 else
  8.                 pio_set(PIOA, PIO_PA0);
  9.         }
  10. }

  11. int main (void)
  12. {
  13.         /* Insert system clock initialization code here (sysclk_init()). */

  14.         board_init();
  15.        
  16.        
  17.         pmc_enable_periph_clk(ID_PIOA);
  18.         pio_set_output(PIOA, PIO_PA0, LOW, DISABLE, ENABLE);
  19.         pio_set_input(PIOA, PIO_PA20, PIO_PULLUP);
  20.         pio_handler_set(PIOA, ID_PIOA, PIO_PA20, PIO_IT_EDGE, pin_edge_handler);
  21.         pio_enable_interrupt(PIOA, PIO_PA20);
  22.         NVIC_EnableIRQ(PIOA_IRQn);
  23.        
  24.        
  25.         while(1)
  26.         {
  27.                
  28.                 ;
  29.         }

  30.         /* Insert application code here, after the board has been initialized. */
  31. }

以下是运行时,调试的截图:






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
dirtwillfly 发表于 2015-11-1 11:48 | 显示全部楼层
感谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部