极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17469|回复: 2

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

[复制链接]
发表于 2013-3-19 20:18:42 | 显示全部楼层 |阅读模式
RT ,实验室要做一套扫描装置,现在需要这一部分!
麻烦大家写个例子程序,板子是mega2560.
回复

使用道具 举报

 楼主| 发表于 2013-3-19 20:19:07 | 显示全部楼层
  1. #define ledPin 13

  2. void setup()
  3. {
  4.   pinMode(ledPin, OUTPUT);
  5.   
  6.   // initialize timer1
  7.   noInterrupts();           // disable all interrupts
  8.   TCCR1A = 0;
  9.   TCCR1B = 0;
  10.   TCNT1  = 0;

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

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

  21. void loop()
  22. {
  23.   // your program here...
  24. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-3-20 12:57:56 | 显示全部楼层
上面是内部定时器产生2HZ的中断,但是我想知道外部计数中断。

TCCR1B |= (1 << CS11);  
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-29 08:09 , Processed in 0.040500 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表