#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define FOSC 16000000
unsigned char counter=0;
//INT0 interrupt
ISR(INT0_vect )
{
if(bit_is_clear(PIND, PD1))
{
counter++;
PORTF=counter;
PORTC=0X01;
}
else
{
counter--;
PORTF=counter;
PORTC=0X02;
}
}
//INT1 interrupt
ISR(INT1_vect )
{
if(bit_is_set(PIND, PD0))
{
counter--;
PORTF=counter;
PORTC=0X02;
}
else
{
counter++;
PORTF=counter;
PORTC=0X01;
}
}
int main(void)
{
/* set PD0 and PD1 as input */
DDRD &=~ (1 << PD0); /* PD0 and PD1 as input */
DDRD &=~ (1 << PD1);
PORTD |= (1 << PD0)|(1 << PD1); /* PD0 and PD1 pull-up enabled */
DDRF=0XFF;
DDRC=0X03;
EIMSK |= (1<<INT0)|(1<<INT1); /* enable INT0 and INT1 */
EICRA |= (1<<ISC01)|(1<<ISC11)|(1<<ISC10); /* INT0 - falling edge, INT1 - rising edge */
/* enable interrupts */
sei();
while(1)
{
//do nothing ;)
_delay_ms(1);
}
return 0;
}