ATtiny13 Blink Using an Interrupt

Note to self: Ensure you set the fuse bits for internal oscillator correctly.

//  blinky
//  James M. Eli
//  5/14/2010
//  Set fuses: int osc @ 9.6MHz, slow startup, serial prog enabled
//  avrdude -p attiny13 -P usb -c usbtiny -U lfuse:w:0x7a:m
//  avrdude -p attiny13 -P usb -c usbtiny -U hfuse:w:0xff:m
//  program hex: 
//  avrdude -p attiny13 -P usb -c usbtiny -U flash:w:tiny13.hex 
#include <avr/interrupt.h> 

ISR(TIM0_OVF_vect) {
  //overflow occurs at 1024/9600000*256=27.3ms/18.3Hz (measured at 26.7ms/18.75Hz) 
  PORTB ^= (1<<PB0);   //toggle led pin 

int main(void) {
  //set port B pin0 as output
  DDRB = (1<<DDB0);
  PORTB = 0;
  //prescale timer to 1024   
  TCCR0B |= (1<<CS02) | (1<<CS00);    
  //enable timer overflow interrupt   
  TIMSK0 |= (1<<TOIE0);   

About Jim Eli

µC experimenter
This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s