error: 'TIMSK' was not declared in this scope 如何解决

软件用的是Arduino 1.85  单片机是ATtiny 85


错误信息

sketch\Servo8Bit.cpp: In static member function 'static void ServoSequencer::servoTimerSetup()':



Servo8Bit.cpp:457: error: 'TIMSK' was not declared in this scope


     TIMSK |= (1 << OCIEnx);


     ^


sketch\Servo8Bit.cpp: In static member function 'static void ServoSequencer::setupTimerPrescaler()':


Servo8Bit.cpp:516: error: 'TCCR1' was not declared in this scope


         TCCR1 = 0;


         ^


sketch\Servo8Bit.cpp: In static member function 'static void ServoSequencer::timerCompareMatchISR()':


Servo8Bit.cpp:635: error: 'TIFR' was not declared in this scope


             TIFR = (1 << OCF0A);  // write logical 1 to the OCF0A flag to clear it


             ^


exit status 1

'TIMSK' was not declared in this scope


程序代码

// 2015 Coretech Robotics 
// Servo Library: http://www.cunningturtle.com/attiny4585-servo-library/
// IR Code: David Cuartielles: http://forum.arduino.cc/index.php?topic=17965.0


#include "Servo8bit.h" 
#define trigPin 0
#define echoPin 3


int ir_pin = 4;
int motorPinL = 1;
int motorPinR = 2;
int key;            
int start_bit = 2000; 
int bin_1 = 1000; 
int bin_0 = 400;   
unsigned long stoptimer;
boolean autoMode;
Servo8Bit motorL, motorR;


void setup() {


   pinMode(ir_pin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  motorL.attach(motorPinL);
  motorR.attach(motorPinR);
  //Serial.begin(9600);
  digitalWrite(0, HIGH);
}


void loop() {
  key = getIRKey();
  if (key != -1) {
    //Serial.println(key);
    if (key < 755 && key > 750){moveMotors(160, 160);} //up
    if (key < 2805 && key > 2795){moveMotors(10, 10);} //down
    if (key < 725 && key > 715){moveMotors(10, 160);} //left
    if (key < 3285 && key > 3275){moveMotors(160, 10);} //right
    if (key < 2677 && key > 2667){
      autoMode = !autoMode;
      moveMotors(94, 85);
      delay(400);
    }
    if (key < 2710 && key > 2695){
      motorL.detach();
      motorR.detach();
    }
  }
  stoptimer = millis();
}


void moveMotors(int speedL, int speedR){
  motorL.write(speedL);
  motorR.write(180-speedR);
}


int getIRKey() {
 int data[12];
 while(pulseIn(ir_pin, LOW, 20000) < 2200) {
   if(stoptimer+20 < millis() && !autoMode)   moveMotors(94, 85);
   if(autoMode){
     if(getDistance() < 10){
       moveMotors(94, 20);
       delay(400); 
     }
     else{
       moveMotors(120, 120); 
     }
   }
   key = 0;
 }
 stoptimer = millis()+1000;
 data[0] = pulseIn(ir_pin, LOW);
 data[1] = pulseIn(ir_pin, LOW);
 data[2] = pulseIn(ir_pin, LOW);
 data[3] = pulseIn(ir_pin, LOW);
 data[4] = pulseIn(ir_pin, LOW);
 data[5] = pulseIn(ir_pin, LOW);
 data[6] = pulseIn(ir_pin, LOW);
 data[7] = pulseIn(ir_pin, LOW);
 data[8] = pulseIn(ir_pin, LOW);
 data[9] = pulseIn(ir_pin, LOW);
 data[10] = pulseIn(ir_pin, LOW);
 data[11] = pulseIn(ir_pin, LOW);


 for(int i=0;i<=11;i++) {


   if(data[i] > bin_1) {
       data[i] = 1;
   }  else {
       if(data[i] > bin_0) { 
         data[i] = 0;
       } else {
        data[i] = 2; 
       }
   }
 }


 for(int i=0;i<=11;i++) {
   if(data[i] > 1) {
       return -1;     
   }
 }


 int result = 0;
 int seed = 1;
 for(int i=11;i>=0;i--) {    
   if(data[i] == 1) {
       result += seed;
   }
   seed = seed * 2;
 }


 return result;                  
}


int getDistance(){
  long duration;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  return (duration/2) / 29.1;
}  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值