Search code examples
catmegainterruption

Atmega 8 interruption doesn't work


I wrote this code:

#define __AVR_LIBC_DEPRECATED_ENABLE__
#include <avr/delay.h>
#include <avr/io.h>
#include "lcd.h"
#include <avr/interrupt.h>

int screen = 0;

void insideTemp(void) {

    while (1) {
       //some code hiere
    }
}

void setup(void) {
    LCDInit(LS_NONE);
    MCUCR |= (1 << ISC01);
    GICR |= (1 << INT0);
    sei();
    DDRD = 0xff;
    ADMUX = (1 << REFS0) | (1 << ADLAR);
    ADCSRA = (1 << ADEN) | (1 << ADFR) | (1 << ADPS2);
}

SIGNAL(SIG_INTERRUPT0) {
    screen++;
    LCDClear();
    _delay_ms(10);
    switch (screen) {
    case 1:
        insideTemp();
        break;
    case 2:
        outsideTemp();
        break;
    case 3:
        engineTemp();
        break;
    default:
        screen = 0;
        insideTemp();
    }
}

int main(void) {
    setup();

    while (1) {

    }
}

Short description - proper function should be call after click on button but only first click work. If I delete while loop it works - but i have to check sth in loop (temperature sensor). What is wrong?


Solution

  • An infinite loop in an interrupt handler does not seem like a good idea to me:( Also, '_delay_ms' call from interrupt state sounds suspicious, but I don't know the OS so it may, or may not, be OK.