我正在为 atmega168a 编写 C 代码。编译下面的代码时出现attempt to use poisoned "SIG_OUTPUT_COMPARE0A
错误。但是我在http://www.protostack.com/blog/2010/09/timer-interrupts-on-an-atmega168/attempt to use poisoned "SIG_OUTPUT_COMPARE0B
上看到了类似的ISR
函数用法,如果有人能告诉我我做错了什么,我将不胜感激?我正在使用 atmel studio 6.0 及其 gcc 在 Windows 7 pc 上编译代码。
#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;
}