| 
View
 

InterruptsCorrection

This version was saved 20 years, 10 months ago View current version     Page history
Saved by PBworks
on October 26, 2005 at 12:26:55 am
 

Updated AVR Interrupt Example

 

Craig Limber's AVR interrupt page is perhaps the only decent page on interrupts on the AVR not directed toward experts.

Anyway, I did have a bit of challenge in getting it working on my atmega8515 and atmega16 using my STK500

A few changes were required:

 

one - avr-gcc 4.0.2 has trouble compiling cbi and sbi. I replaced them with the code cribbed from the AVR butterfly source to directly twiddle the bit to flip the LED.

two - the key fix, which took much googling, was to call "sei()" appropriately.

three - your include files are not displayed from your example. They are there in the source view, but the browser doesn't like the open/close brackets.

four - your include files, once corrected tossed all sorts of errors on gcc 4.0.2

 

Whether some, none, or all of these issues are 'real' I don't know - a few hours of AVR and avr-gcc experience is not enough for me to tell.

Thanks again for the tutorial.

 

-hb

 

//

// Craig Limber, July 2004

//

 

#include

#include

#include

#define cbiBF(port,bit) (port &= ~(1<#define sbiBF(port,bit) (port |= (1< 

//-----------------------------------------------------------------------------

SIGNAL(SIG_OUTPUT_COMPARE1A)

{

static uint8_t ledon;

if (ledon)

{

ledon = 0;

cbiBF(PORTB, PB4);

}

else

{

ledon = 1;

sbiBF(PORTB, PB4);

}

}

 

//-----------------------------------------------------------------------------

int main(void)

{

DDRB = _BV(DDB4); // enable output

TIMSK = _BV(OCIE1A);

sei();

TCCR1B = _BV(CS12) // 256 prescale

| _BV(WGM12); // CTC mode, TOP = OCR1A

//OCR1A = 15625; // count up to TOP 1hz with 8 meg system clock

OCR1A = 1625; // count up to TOP 1hz with 8 meg system clock

while (1)

asm volatile("nop" ::); // we spin! Better if put processor to sleep

return 0;

}

 

It's my intention to take down this page as soon as Craig has updated his page, and/or if he prefers that I not have this up...

Comments (0)

You don't have permission to comment on this page.