cembeddedavrisratmega16

Atmega16's PORTs don't work


I was trying to interface a seven-segment-display with Atmega16 chip with its decoder (74ls47), and increase the value it displays using ISR. The ISR should turn a led on and off then increase the value of the SSD, but it only makes the led blink and nothing happens to the SSD.

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "DIO.h"


unsigned int counter=0;


int main(void)
{
    SREG |= (1<<7); //The Holy Gate
    GICR |= (1<<7); //Enableing INT1
    MCUCR |=(1<<2);     //for INT1
    MCUCR |=(1<<3);     //for INT1  
    DDRC =0xFF;
    PORTC =0;
    DDRB |=(1<<0);
    while (1) 
    {   

    }
}

ISR (INT1_vect)
{

    digitalWrite('B', 0, 1);
    _delay_ms(500);
    digitalWrite('B', 0, 0);
    if (counter <= 9) {
        PORTC=counter;
        counter++;
    } else {
        counter=0;
    }
}

Note: digitalWrite is a function to turn the led on and off which is pre-defined in "DIO.h" file

Thanks in advance.


Solution

  • Ok, actually I've solved it and have no idea how did it work. I defined "counter" volatile.

    My mistake :

    volatile unsigned char counter = 0;
    ....
    ISR (INT0_vect)
    {
          if (counter <= 9) {
            PORTC=counter;
            counter++;}
            else {
            counter=0;}
    }
    int main (void)
    {
        ....
        while(1)
        {
    
        }
    }
    

    The corrected code :

    volatile unsigned char counter ;
    ....
    ISR (INT0_vect)
    {
          if (counter <= 9) {
            PORTC=counter;
            counter++;}
            else {
            counter=0;}
    }
    int main (void)
    {
        ....
        counter=0;
        while(1)
        {
    
        }
    }