Hi,
I tried to copy and run example of how to use hardware timers to trigger an ISR. I used the more or less identical information from
and
my code is:
int timer = 0; //volatile?
bool state = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
//cli();//stop interrupts //notwendig?
TCCR0A = (1 << WGM01); //Set the CTC mode, clear timer on compare, prescaler config
OCR0A = 77; //Value for ORC0A for 1ms
TIMSK0 |= (1 << OCIE0A); //Set the interrupt request
sei(); //Enable interrupt warum nicht am ende?
TCCR0B |= (1 << CS02); //Set the prescale 1/1024 clock
TCCR0B |= (1 << CS00);
}
void loop() {
//in this way you can count 1 second because the interrupt request is each 1ms
if (timer >= 1000) {
state = !state;
timer = 0;
}
digitalWrite(LED_BUILTIN, state);
}
ISR(TIMER0_COMPA_vect) { //This is the interrupt request
timer++;
}
My problem is, that my compiler doesn't know these register names, and ISR(). None of the examples uses an include, for them it works right away. What do I have to include to make it work?
A part of the error messages:
Arduino: 1.8.13 (Windows 8.1), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
timer:55:5: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER0_COMPA_vect) { //This is the interrupt request
^
C:\Users\xxxxxxx\Documents\Arduino\timer\timer.ino: In function 'void setup()':
timer:36:3: error: 'TCCR0A' was not declared in this scope
TCCR0A = (1 << WGM01); //Set the CTC mode, clear timer on compare, prescaler config
^
timer:36:18: error: 'WGM01' was not declared in this scope
TCCR0A = (1 << WGM01); //Set the CTC mode, clear timer on compare, prescaler config
^
timer:37:3: error: 'OCR0A' was not declared in this scope
OCR0A = 77; //Value for ORC0A for 1ms
^
timer:39:3: error: 'TIMSK0' was not declared in this scope
TIMSK0 |= (1 << OCIE0A); //Set the interrupt request
^
C:\Users\xxxxxxx\Documents\Arduino\timer\timer.ino: At global scope:
timer:55:4: error: expected constructor, destructor, or type conversion before '(' token
ISR(TIMER0_COMPA_vect) { //This is the interrupt request
^
exit status 1
expected constructor, destructor, or type conversion before '(' token