有难度的问题-修改库文件IRremote红外库改写为支持ATtiny85-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 13744|回复: 11

[已解决] 有难度的问题-修改库文件IRremote红外库改写为支持ATtiny85

[复制链接]
发表于 2013-9-4 12:05 | 显示全部楼层 |阅读模式
本帖最后由 S1213 于 2013-9-4 13:02 编辑

最近ATtiny85玩的甚是开心,突发奇想做个红外项目用ATtiny85,这时才发现这个IRremote不支持ATtiny85.发此贴求助!
并记录自己一步步学习修改库文件的路程。

问题都写在 6 楼了!
 楼主| 发表于 2013-9-4 12:11 | 显示全部楼层
本帖最后由 S1213 于 2013-9-4 12:26 编辑

Arduino软件版本:1.0.4 / 1.0.5            

   硬件使用:Digispark  http://www.arduino.cn/thread-3034-1-1.html   

38Khz 红外一体化接收头

  红外LED

软件设置截屏

软件设置截屏


 楼主| 发表于 2013-9-4 12:19 | 显示全部楼层
Arduino1.0.4软件提示错误内容:
IRremote.cpp: In member function 'void IRsend::mark(int)':
IRremote.cpp:227: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:227: error: 'COM2B1' was not declared in this scope
IRremote.cpp: In member function 'void IRsend::space(int)':
IRremote.cpp:235: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:235: error: 'COM2B1' was not declared in this scope
IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
IRremote.cpp:264: error: 'TIMSK2' was not declared in this scope
IRremote.cpp:274: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:274: error: 'WGM20' was not declared in this scope
IRremote.cpp:274: error: 'TCCR2B' was not declared in this scope
IRremote.cpp:274: error: 'WGM22' was not declared in this scope
IRremote.cpp:274: error: 'CS20' was not declared in this scope
IRremote.cpp:274: error: 'OCR2A' was not declared in this scope
IRremote.cpp:274: error: 'OCR2B' was not declared in this scope
IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
IRremote.cpp:290: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:290: error: 'WGM21' was not declared in this scope
IRremote.cpp:290: error: 'TCCR2B' was not declared in this scope
IRremote.cpp:290: error: 'CS21' was not declared in this scope
IRremote.cpp:290: error: 'OCR2A' was not declared in this scope
IRremote.cpp:290: error: 'TCNT2' was not declared in this scope
IRremote.cpp:293: error: 'TIMSK2' was not declared in this scope
IRremote.cpp:293: error: 'OCIE2A' was not declared in this scope
 楼主| 发表于 2013-9-4 12:29 | 显示全部楼层

arduino 1.0.4 软件报错信息

本帖最后由 S1213 于 2013-9-4 12:33 编辑

arduino 1.0.4 软件报错信息 如下:(注意:为了便于观察已删减路径信息)

IRremote.cpp: In member function 'void IRsend::mark(int)':
IRremote.cpp:227: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:227: error: 'COM2B1' was not declared in this scope
IRremote.cpp: In member function 'void IRsend::space(int)':
IRremote.cpp:235: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:235: error: 'COM2B1' was not declared in this scope
IRremote.cpp: In member function 'void IRsend::enableIROut(int)':
IRremote.cpp:253: error: 'TIMSK2' was not declared in this scope
IRremote.cpp:263: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:263: error: 'WGM20' was not declared in this scope
IRremote.cpp:263: error: 'TCCR2B' was not declared in this scope
IRremote.cpp:263: error: 'WGM22' was not declared in this scope
IRremote.cpp:263: error: 'CS20' was not declared in this scope
IRremote.cpp:263: error: 'OCR2A' was not declared in this scope
IRremote.cpp:263: error: 'OCR2B' was not declared in this scope
IRremote.cpp: In member function 'void IRrecv::enableIRIn()':
IRremote.cpp:279: error: 'TCCR2A' was not declared in this scope
IRremote.cpp:279: error: 'WGM21' was not declared in this scope
IRremote.cpp:279: error: 'TCCR2B' was not declared in this scope
IRremote.cpp:279: error: 'CS21' was not declared in this scope
IRremote.cpp:279: error: 'OCR2A' was not declared in this scope
IRremote.cpp:279: error: 'TCNT2' was not declared in this scope
IRremote.cpp:282: error: 'TIMSK2' was not declared in this scope
IRremote.cpp:282: error: 'OCIE2A' was not declared in this scope
 楼主| 发表于 2013-9-4 12:37 | 显示全部楼层

对应问题点在ATmega328P 数据手册中的信息

手册位置1.png 手册位置2.png
手册位置3.png

 楼主| 发表于 2013-9-4 12:44 | 显示全部楼层
查了一下,以上问题基本上都是和 avr 的Timer (定时器)有关的参数选项,这其中也确实没有对ATtiny系列的支持信息。
资料见下:
timer.png


 楼主| 发表于 2013-9-4 12:55 | 显示全部楼层
本帖最后由 S1213 于 2013-9-4 13:05 编辑

问题集:


1. IRremote 红外库文件对于硬件的要求Attiny85,到底能不能满足?
2. IRremoteint.h中的代码 defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)     需要详细介绍软件是如何知道我们用的是不是1280或者        2560,这个只是定义了一下吧,如何、在哪里判断的?

   我需要加入attiny85 ,根据上述定义我是不是要写成
   defined (__AVR_ATtiny85__)

3. IRremote中是如何得知需要哪一个引脚作为TX输出的?引脚好像都是固定的?
4. 根据IRremoteint.h中如下描述 attiny85 是否需要修改时钟频率 ?
    #ifdef F_CPU
    #define SYSCLOCK F_CPU     // main Arduino clock
    #else
    #define SYSCLOCK 16000000  // main Arduino clock
    #endif



 楼主| 发表于 2013-9-4 12:59 | 显示全部楼层
IRremoteint.h 文件中的内容

// define which timer to use
//定义哪些计时器使用
// Uncomment the timer you wish to use on your board. If you
//取消计时器您希望使用在你的董事会。如果你
// are using another library which uses timer2, you have options
//使用另一个库,使用timer2,你有选择的权利
// to switch IRremote to use a different timer.
//切换IRremote使用不同的计时器。
 楼主| 发表于 2013-9-4 13:07 | 显示全部楼层
本帖最后由 S1213 于 2013-9-4 13:11 编辑

IRremoteint.h 定义的timer
主要关注 TCCR1A 、TCCR1B、TIMSK  、WGM11 、WGM12、WGM13、OC1A

// defines for timer1 (16 bits)
#elif defined(IR_USE_TIMER1)
#define TIMER_RESET
#define TIMER_ENABLE_PWM     (TCCR1A |= _BV(COM1A1))
#define TIMER_DISABLE_PWM    (TCCR1A &= ~(_BV(COM1A1)))

  #define TIMER_ENABLE_INTR    (TIMSK = _BV(OCIE1A))
  #define TIMER_DISABLE_INTR   (TIMSK = 0)

#define TIMER_INTR_NAME      TIMER1_COMPA_vect
#define TIMER_CONFIG_KHZ(val) ({ \
  const uint16_t pwmval = SYSCLOCK / 2000 / (val); \
  TCCR1A = _BV(WGM11); \
  TCCR1B = _BV(WGM13) | _BV(CS10); \
  ICR1 = pwmval; \
  OCR1A = pwmval / 3; \
})
#define TIMER_CONFIG_NORMAL() ({ \
  TCCR1A = 0; \
  TCCR1B = _BV(WGM12) | _BV(CS10); \
  OCR1A = SYSCLOCK * USECPERTICK / 1000000; \
  TCNT1 = 0; \
})
#if defined(CORE_OC1A_PIN)
#define TIMER_PWM_PIN        CORE_OC1A_PIN  // Teensy
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define TIMER_PWM_PIN        11  // Arduino Mega
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
#define TIMER_PWM_PIN        13 // Sanguino
#else
#define TIMER_PWM_PIN        9  // Arduino Duemilanove, Diecimila, LilyPad, etc
#endif
 楼主| 发表于 2013-9-4 15:17 | 显示全部楼层
有人修改了IRremote库问题 for attiny85 但是好像是 timer 不够用,所以没有成功?
http://forum.arduino.cc/index.php?topic=91174.15
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-3 07:23 , Processed in 0.114787 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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