catsbee 发表于 2013-3-19 20:18:42

关于arduino外部脉冲计数产生中断~

RT ,实验室要做一套扫描装置,现在需要这一部分!
麻烦大家写个例子程序,板子是mega2560.

catsbee 发表于 2013-3-19 20:19:07

#define ledPin 13

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

// initialize timer1
noInterrupts();         // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1= 0;

OCR1A = 31250;            // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12);   // CTC mode
TCCR1B |= (1 << CS12);    // 256 prescaler
TIMSK1 |= (1 << OCIE1A);// enable timer compare interrupt
interrupts();             // enable all interrupts
}

ISR(TIMER1_COMPA_vect)          // timer compare interrupt service routine
{
digitalWrite(ledPin, digitalRead(ledPin) ^ 1);   // toggle LED pin
}

void loop()
{
// your program here...
}

catsbee 发表于 2013-3-20 12:57:56

上面是内部定时器产生2HZ的中断,但是我想知道外部计数中断。

TCCR1B |= (1 << CS11);
页: [1]
查看完整版本: 关于arduino外部脉冲计数产生中断~