悠然小调 发表于 2012-4-9 16:40:29

st007 发表于 2012-3-29 17:21 static/image/common/back.gif
有库函数啊,定时中断
不明有庫函數, 是什麼, 我是新手初學的, 請敎一下

去官网下载MsTimer2.h这个的库文件放到ARDUINO的LIBRARY文件夹里。

#include <MsTimer2.h>

void setup()
{
pinMode(13, OUTPUT);
MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}

void loop()
{   }

void flash() {
static boolean output = HIGH;

digitalWrite(13, output);
output = !output;
}

anfe09 发表于 2012-11-2 22:28:44

哈哈 谢谢 过几天试试

Ryanli 发表于 2013-1-11 15:34:53

悠然小调 发表于 2012-3-9 20:35 static/image/common/back.gif
有库函数啊,定时中断
#include



请问这个库在哪里啊?

悠然小调 发表于 2013-1-15 17:49:02

Ryanli 发表于 2013-1-11 15:34 static/image/common/back.gif
请问这个库在哪里啊?

http://playground.arduino.cc/Main/MsTimer2

Ryanli 发表于 2013-2-25 08:19:01

悠然小调 发表于 2013-1-15 17:49 static/image/common/back.gif
http://playground.arduino.cc/Main/MsTimer2

谢啦,哈哈。

绵羊 发表于 2013-3-1 11:08:10

悠然小调 发表于 2012-4-9 16:40 static/image/common/back.gif
去官网下载MsTimer2.h这个的库文件放到ARDUINO的LIBRARY文件夹里。

#include


那个中断和串口还是iic通信有冲突啊,不知道是哪个。反正肯定有冲突,一用就死啊

jfo 发表于 2013-8-21 14:05:28

可以的,下面代码每125us(8KHz)产生一次中断,修改OCR1A 的值可以更改中断频率,
f = 16MHz / (2*(OCR1A + 1));const byte LED = 13;

ISR(TIMER1_COMPA_vect)
{
static boolean state = false;
state = !state;// toggle
digitalWrite (LED, state ? HIGH : LOW);
}

void setup() {
pinMode (LED, OUTPUT);

// set up Timer 1
TCCR1A = 0;          // normal operation
TCCR1B = _BV(WGM12) | _BV(CS10);   // CTC, no pre-scaling
OCR1A =999;       // compare A register value (1000 * clock speed)
TIMSK1 = _BV (OCIE1A);             // interrupt on Compare A Match
}// end of setup

void loop() { }This toggles pin D13 faster than you can see (once every 62.5 μS). (It turns on every second toggle, that is every 125 μS, giving a frequency of 1/0.000125 = 8 KHz)

更多interrupt参考:http://www.gammon.com.au/forum/?id=11488

天地 发表于 2014-7-26 00:10:39

那计数器呢?怎么搞?有什么好的资料啊?

mkk 发表于 2014-10-21 17:39:00

因该是可以用的,sei函数,但是里面的参数看不懂啊,也没有说明

抽烟不掉烟灰 发表于 2014-11-28 18:56:45

悠然小调 发表于 2012-3-9 20:35 static/image/common/back.gif
有库函数啊,定时中断
#include



这个你会用吗?

nuomistudio 发表于 2015-2-8 12:26:50

终于找到解决方法了,待验证……

butOn 发表于 2015-5-9 21:13:29

iron 发表于 2012-3-6 23:33
Arduino硬件难道没有时钟中断?

硬件当然有 但要操作寄存器
页: 1 [2]
查看完整版本: arduino为什么没有定时中断?