Atmega168 and peripheral interrupts

Dec 04, 2005 2 Replies

I have a problem with an atmega168.



On my test board I have a jumper on PB1 and a LED on PD5, using internal 8MHz RC-clock.



Given the following program: #include #include #include


INTERRUPT(SIG_PCINT0) { unsigned short i; char j;



for(j=0; j


I found the problem. I had a wrong signal name - which meant that each interrupt lead to a reset.

Here's the working program. #include #include #include #include

// PD5=OC0B=T1 SIGNAL(SIG_PIN_CHANGE0) { PORTD ^= _BV(PD5); }

int main(void) { // ENable int sei();

/* INITIALIZE 8MHz/256 -> 31 250 Hz */ CLKPR=_BV(CLKPCE); CLKPR=_BV(CLKPS3);

/* enable PD5 as output */ DDRD|= _BV(PD5);

//PCINT1 erlauben PCMSK0=_BV(PCINT1); PCICR=_BV(PCIE0);

//Pull-Up DDRB=0; PORTB=_BV(PORTB1);

/* BLINK, BLINK ... */ while (1) { sleep_mode(); } }

I found the problem. I had a wrong signal name - which meant that each interrupt lead to a reset.

Here's the working program. #include #include #include #include

// PD5=OC0B=T1 SIGNAL(SIG_PIN_CHANGE0) { PORTD ^= _BV(PD5); }

int main(void) { // ENable int sei();

/* INITIALIZE 8MHz/256 -> 31 250 Hz */ CLKPR=_BV(CLKPCE); CLKPR=_BV(CLKPS3);

/* enable PD5 as output */ DDRD|= _BV(PD5);

//PCINT1 erlauben PCMSK0=_BV(PCINT1); PCICR=_BV(PCIE0);

//Pull-Up DDRB=0; PORTB=_BV(PORTB1);

/* BLINK, BLINK ... */ while (1) { sleep_mode(); } }

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required