NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Setting pins to fire interrupts

January 30, 2010
by 920
920's Avatar

I'm trying to set PC1 to fire as PCINT1. I've tried googling and found enough info that made it work well enough to make the MCU reset continually whenever the pin was asserted high or low (so at least I know it's responding), but that doesn't really help. I tried reading the data sheet but it's kind of confusing on this issue. Could someone explain what needs to be done to enable an interrupt on a specific pin? This would make a great post to be stickied in one of the forums for newbs.

BTW, this code is for a project for my "instrumentation for scientists" class where I'm attempting to teach squirrels to play tic-tac-toe. I intend to post a complete writeup of how this was done. If I don't post it directly here, I will post at least a link to wherever I have the info. There will also be vids posted on-line.

Ok, enough with the preliminaries, here comes some hard facts.

1: Here's what I currently have for the setup and handling. I'm using PB1 as the interrupt pin (INTPC1).

    // PORTB pins 1-5 as input
DDRB &= !(1<<PB1 | 1<<PB2 | 1<<PB3 | 1<<PB4 | 1<<PB5);

...

PCMSK0 |= (1<<PCINT1);

PCICR |= (1<<PCIE0);

2: I'm catching this as :

ISR(PCINT1_vect) {

But whenever this is held either hi or lo, it resets to main. I've seen a lot of confusing entries on other boards (including AVRfreaks) which say it was solved by changing to PCINT0_vect.

Can someone help me make some sense from this?

Moreover, is someone up to the task of making a post clarifying what it takes to enable interrupts on the pins properly?

Any help would be GREATLY appreciated.

January 31, 2010
by 920
920's Avatar

Ok, after a good night's sleep and some fiddling around, I managed to get this to work. It seems that the PCINT1_vect does not actually handle PCINT1... I changed the code to handle PCINT0_vect and now it's all hunky-dory.

January 31, 2010
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi 920,

Yes, that can be a bit confusing. There are three separate PCINTn_vect interrupts (0,1,2). PCINT0_vect handles PCINT0 through PCINT7. PCINT1_vect handles PCINT8 through PCINT15. PCINT2_vect handles PCINT16 through PCINT23. (See page 71 of the ATmega168 datasheet.) Glad to hear that you got it working!

Mike

Post a Reply

Please log in to post a reply.

Did you know that you can control 120 LEDs with just 17 microcontroller pins? Learn more...