Arduino的详细介绍(基于Mega2560)(分文)

您所在的位置:网站首页 mega2560外部中断引脚 Arduino的详细介绍(基于Mega2560)(分文)

Arduino的详细介绍(基于Mega2560)(分文)

2024-04-17 03:38| 来源: 网络整理| 查看: 265

External Interrupts(外部中断): 2 (interrupt 0),  3 (interrupt 1), 18 (interrupt 5),  19 (interrupt 4),  20 (interrupt 3), 

21 (interrupt 2)。git

函数:函数

attachInterrupt():oop

功能:为中断发生时指定特定名称的中断服务程序。本函数可替代先前的任何中断功能。下图是各板子的中断介绍:ui

Board int.0 int.1 int.2 int.3 int.4 int.5 Uno, Ethernet 2 3         Mega2560 2 3 21 20 19 18 Leonardo 3 2 0 1 7   Due (see below) Due板子有强大的中断功能,使你能够在任何可得到的端口定义中断功能。你可使用 attachInterrupt()函数直接指定引脚号。

形式:attachInterrupt(interrupt, ISR, mode) attachInterrupt(pin, ISR, mode) (只在Arduino Due板子上是这种形式)spa

参数:code

interrupt: 中断号 (int); pin:中断引脚(只在Arduino Due板子上要用,其余板子已经指定好了各中断的引脚); ISR: 中断发生时的中断服务程序。这个函数必须没有参数没有返回值; mode:定义中断触发类型,有四种形式:LOW:低电平触发;CHANGE:电平变化触发;RISING :上升沿触发(由LOW变为HIGH);FALLING:降低沿触发(由HIGH变为LOW);  Due板子还支持高电平触发。ci

返回值:none;it

示例:table

int pin = 13; volatile int state = LOW; void setup() { pinMode(pin, OUTPUT); attachInterrupt(0, blink, CHANGE); } void loop() { digitalWrite(pin, state); } void blink() { state = !state; } 另外,使用 detachInterrupt()函数能够关掉中断,操做很简单:

detachInterrupt(interrupt); detachInterrupt(pin) (Arduino Due only)。class



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3