Hallo,
ich bekomme es leider immer noch nicht vernünftig hin, Interruptroutinen
für einen Atmega in C++ zu implementieren.
Jetzt wollte ich die Objekte Global machen und in den ISRs dann die
entsprechende Funktion aufrufen.
1 | #include "system.h"
|
2 | #include <util/delay.h>
|
3 | #include <avr/io.h>
|
4 | #include "Timer/timer.h"
|
5 |
|
6 | timer timer0(TCCR0A,
|
7 | ~(1 << WGM00) | (1 << WGM01),
|
8 | TCCR0B,
|
9 | (1 << CS00) | (1 << CS01) & ~(1 << CS02),
|
10 | OCR0A,
|
11 | OCR0A = 250 - 1,
|
12 | TIMSK0,
|
13 | (1 << OCIE0A));
|
14 |
|
15 | int main(void)
|
16 | {
|
17 | while(1)
|
18 | {
|
19 | if(timer0.getNewTime() == true){
|
20 | ....
|
21 | }
|
22 | }
|
23 | }
|
24 |
|
25 | void TIMER0_COMPA_vect(void)
|
26 | {
|
27 | timer0.interrupt();
|
28 | }
|
in timer.cpp
1 | timer::timer(volatile uint8_t &tccra, uint8_t tccraNewState,
|
2 | volatile uint8_t &tccrb, uint8_t tccrbNewState,
|
3 | volatile uint8_t &ocra, uint8_t ocraNewState,
|
4 | volatile uint8_t &timsk, uint8_t timskNewState)
|
5 | {
|
6 | tccra |= tccraNewState;
|
7 | tccrb |= tccrbNewState;
|
8 | ocra |= ocraNewState;
|
9 | timsk |= timskNewState;
|
10 | }
|
11 |
|
12 | timer::~timer()
|
13 | {
|
14 | }
|
15 |
|
16 | bool timer::getNewTime()
|
17 | {
|
18 | return _newTime;
|
19 | }
|
20 | void timer::interrupt()
|
21 | {
|
22 | _milliseconds++;
|
23 | if(_milliseconds >= 500)
|
24 | {
|
25 | _milliseconds = 0;
|
26 | _seconds++;
|
27 | PORTB ^= ( 1 << PORTB5 );
|
28 | //_newTime = true;
|
29 | }
|
30 | }
|
Zum Testen möchte ich zunächst wieder die LED and PB5 blinken lassen.
Aber diese bleibt aus. Auch in der Simulation wird nicht in die ISR
gesprungen. Kann mir da jemand evtl. sagen, wieso die ISR nicht
aufgerufen wird?
In der Simulation wird der Brakepoint an der Stelle
1 | if(timer0.getNewTime() == true){
|
auch nie erreicht. Vorher wird alles Resettet und von vorne gestartet.
Gruß
Franz