Fun with timers and interrupts on Atmel Tiny26
April 17, 2009
A long time since my last post on this site... Anyway I've been experimenting a little with my Atmel Tiny26 uC today using AVR Studio 4 for development and the AVR ISP mkII programmer to program the uC.
First off I made the usual blinking LED by flipping an output pin interleaved with delaying code. That worked nicely and the next step was to use one of the two timers of the Tiny26 to create interrupts instead of actively delaying the uC. After some reading of the datasheet and some examples on the internet I got it to work and I thought I'd put the C code up here for others who might be interested in using the AVR line of uC's and programming them using the AVR-GCC compiler. I made a bunch of comments in the code about the clock prescaler and so on but I guess you should have the Tiny26 datasheet at hand if you want to closely examine what the different names are all about.
The _BV(...) macro used in the code is short for the C construct (1<<(...)) and basically just takes a pin/bit number and creates a byte with all zeros except for a one at the given pin/bit number.