I am experimenting with using timer interrupts. having trouble getting ISR interrupt to fire...at least I think that is the problem.
Any help would be appreciated.
Here is the code I have:
/*
* tiny85_blink_by_timer_interrupt.ino
* testing porgramming attiny portB pin0
*
* using AVR_TINY_PROGRAMMER from sparkfun
* using USBtinyISP in "tools-Programmer"
* using ATTiny85 @ 8 MHz (internal oscilator; BOD disable) in "tools-Board"
* or using ATTiny85 (internal 8MHz Clock) in "tools-Board"
*
* Created: 4/29/2014
* Modified: 5/01/2014
* Author: Krist Norlander; krist_norlander@msn.com
*/
#include <avr/io.h>
#include <avr/interrupt.h>
void setup()
{
// Disable global interrupts before initialization
cli();
//initialize the PortB Pin0 to output; same as pinMode(ledPin, OUTPUT);
DDRB |= (1<<PINB0);
//initialize the timer0
TCCR0A = (1<<WGM01); // Put timer0 in CTC mode and clear other bits
TCCR0B = (1<<CS02); // Timer0 prescaling 256 and clearing other bits
TIMSK |= (1<<OCIE0A); // enable timer1 compare interrupt
//set the timer0 count
OCR0A = 255; // Count 255 cycles before calling ISR interrupt
PORTB |= (1<<PINB0); // Set PortB Pin0 high to turn on LED
//initialize global interrupts before beginning loop
sei();
}
void loop()
{
//do nothing
//everything is done by timer interrupt
}
ISR(TIM0_COMPA_vect) {
//toggle the PortB pin0 to HIGH or LOW
PORTB ^= (1<<PINB0);
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.