Я написал программу простого таймера для Atmega328 в обычном режиме. Но я не могу мигать светодиодом, если я скомпилирую код в Atmel Studio 6.2. Но тот же код отлично работает, если я компилирую в arduino IDE. Я дал код для Arduino, а также Atmel Studio ниже. Кажется, что где-то есть проблема. Есть ли проблема с значением F_CPU?Невозможно получить работу таймера
// Code compiled using Atmel Studio:
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000
unsigned char x=0;
ISR(TIMER1_OVF_vect) {
x=!x;
}
void setup() {
DDRB=0x01;
TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0000; // 16bit counter register
TCCR1B = 0x04; // start timer/ set clock
};
int main (void)
{
setup();
while(1)
{
PORTB= x;
}
return(0);
}
Код, написанный с Arduino IDE:
#define LED 8
boolean x=false;
ISR(TIMER1_OVF_vect) {
x=!x;
}
void setup() {
pinMode(LED, OUTPUT);
TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0x0000; // 16bit counter register
TCCR1B = 0x04; // start timer/ set clock
};
void loop() {
PORTB= x;
}
Обращаем ваше внимание, что я использую плату arduino Uno Rev3. Без прерываний все работает нормально. –