Learning Interrupts

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I am trying to learn how to use interrupts and I am having trouble with the following code. I am using a STK500 along with the STK500's LED and Switches.  My AVR is a ATMega168A.  In the below code, I want to flash the LED on PORTC0 when an interrupt is detected on PORTB0. When I load the code, the LED stays on and when I push the button, nothing happens. I assume that how I am setting the interrupts incorrectly.

 

#define F_CPU 16000000L
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

int main(void)
{
	/* LED C0*/
	DDRC |= 1<<PORTC0; // Set pin to output led
	PORTC &= ~(1<<PORTC0); // low
    
	/* Switch B0*/
	/* PCICR Pin change interrupt control register */
	
	PCICR |= 1<<PCIE0; // enable interrupts on bank b 
	PCMSK0 |= 1<<PORTB0; // enable pin B0

	sei();

    while(1)
    {
	    _delay_ms(10);
		
    }
}

ISR(PCINT0_vect){
	
	PORTC = (1<<PORTC0); // high
	_delay_ms(1000);
	PORTC &= ~(1<<PORTC0); // low
	_delay_ms(1000);
}

Thanks for the help

"When all else fails, read the directions"

Last Edited: Thu. Dec 4, 2014 - 01:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Never mind - There was a typo in my code. Noticed it when I was editing my post. The above code works.

"When all else fails, read the directions"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mom always said I never mind.

 

277,232,917 -1 The largest known Mersenne Prime

Measure twice, cry, go back to the hardware store

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where can I find the introduce of INT4_vect,INT5_vect...?

Such as them.

一个大学生

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding to 'js' post, there might be a more recent list in the build of avrlibc that Atmel/Microchip does. It is online here: http://www.atmel.com/webdoc/AVRL...

 

If you're using Atmel Studio, there will be a similar locally stored page in the help there.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]