标题: arduino 中断 [打印本页]

作者: lishoujie8023    时间: 2018-1-28 15:09
标题: arduino 中断
外部中断在不同的Arduino型号上位置也不同,只有外部中断发生在以下端口,Arduino才能捕获到,以下例举了常见的几种型号的外部中断引脚标号。
型号int.0int.1int.2int.3int.4int.5
UNO\Ethernet23    
Mega25602321201918
Leonardo3201  
Due 所有IO口均可

中断模式就是你的中断触发方式。在大多数arduino上有以下四种触发方式:
LOW                  低电平触发
CHANGE            电平变化,高电平变低电平、低电平变高电平
RISING              上升沿触发
FALLING            下降沿触发
HIGH                 高电平触发(该中断模式仅适用于Arduino due)

在定义中断函数后,要使用外部中断,你只需要在程序的Setup部分配置好中断函数即可,配置函数如下:
attachInterrupt(interrupt, function, mode);//interrupt为你中断通道编号,function为中断函数,mode为中断触发模式
需要注意的是在Arduino Due中,中断设置有点不同:
attachInterrupt(pin, function, mode); //due 的每个IO均可以进行外部中断,所以这里第一个参数为pin,即你使用的引脚编号。
如果在程序中途,你不需要使用外部中断了,你可以用中断分离函数detachInterrupt(interrupt );来取消这一中断设置。
同样在Arduino Due上,该函数为detachInterrupt(interrupt );

作者: luoyinbazi    时间: 2018-2-13 13:32
非常感谢,学习了




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1