2013-03-02 84 views
1

我正在爲atmega168a編寫C代碼。當我編譯下面的代碼時,我得到了attempt to use poisoned "SIG_OUTPUT_COMPARE0Aattempt to use poisoned "SIG_OUTPUT_COMPARE0B錯誤。但是我在http://www.protostack.com/blog/2010/09/timer-interrupts-on-an-atmega168/上看到ISR函數的類似用法,如果有人能告訴我我做錯了什麼,我將不勝感激。我正在使用atmel studio 6.0及其gcc在Windows 7 PC上編譯代碼。錯誤:嘗試使用中毒「SIG_OUTPUT_COMPARE0A」

#include <avr/io.h> 
#include <avr/interrupt.h> 
#include <avr/iomx8.h> 


volatile int new_msg; 
volatile int new_msg_available = 0; 
volatile int message = 0xFFFF; 
int main(void) 
{ 
    DDRB = 0xFF; 
    TIMSK0 = _BV(OCIE0A) | _BV(OCIE0B); // Enable Interrupt TimerCounter0 Compare Match A & B // #define OCIE0A 1... (1<<1); 
    TCCR0A = _BV(WGM01); // Mode = CTC ... #define WGM01 1 ... mode 2 
    TCCR0B = _BV(CS01); // Clock/8, 0.000008 seconds per tick 
    OCR0A = 104;   // 0.000008*104 = 0.000832 SIG_OUTPUT_COMPARE0A will be triggered. 
    OCR0B = 52;   // 416 usec 

    message = 0xFFFE; 

    volatile int i; 
    sei(); //interrupts are globally switched on 


    while(1) 
    { 
     if (OCR0A >= 104){ 
       for (i=0; i<18; i++) { 
        if (i <2){ 
         PORTB = 0xFF; 
        } 
        else if ((i<15) && (message & 0x1)) { 
         PORTB = 0x00; 
        } 
        else if (i>15){ 
         PORTB = 0xFF; 
        } 
        else{ 
         PORTB = 0x00; 
        } 
        message >>= 1; 
       }  
     } 
    } 
    return 0; 
} 


ISR(SIG_OUTPUT_COMPARE0A) 
{ 
    if(new_msg_available == 1){ 
     message = new_msg; 
     new_msg_available = 0; 
    }else{ 
     message = 0xFFFF; 
    } 
} 

ISR(SIG_OUTPUT_COMPARE0B) 
{ 
    PORTB ^= 0xFF; 
} 

回答