#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
uint8_t x = 0X00;
uint8_t arah;
ISR(PCINT1_vect)
{
if (PINJ&=~(1<<0)) {
arah = 1 ;
}
if (PINJ&=~(1<<1)) {
arah = 2 ;
}
}
int main (void)
{
DDRA |= 0XFF;
DDRB |= (1<<PB7);// LED output enable;
DDRJ &= ~(1 << 0);
DDRJ &= ~(1 << 1);
PORTJ |= (1 << 0);
PORTJ |= (1 << 1);
PCMSK1 |= (1 << PCINT9) | (1 << PCINT10);
PCICR |= _BV(PCIE1);
sei();
while (1) {
PORTB|=(1<<7);
_delay_ms(200);
PORTB&=~(1<<7);
_delay_ms(200);
switch (arah) {
case 0:
PORTA = 0XFF;
sei();
break;
case 1:
x++;
PORTA = x;
_delay_ms(200);
sei();
break;
case 2:
x--;
PORTA = x;
_delay_ms(200);
sei();
break;
}
}
}