
AVR tiny13 with limited IO, small and powerful, so it is really good to make a DIY LED candle.
Link:
http://www.electronics-lab.com/blog/?p=2948

We set the output to be toggled every time the counter value match our OCR0A value. Thus, a square wave is generated:
int main (void)
{
b0_output; //OC0A as led output
TCCR0B = 0x03; //select timer clkio/64
TCCR0A = (0x01)<<6 | 0x02; // Toggle OC0A | CTC MODE
TCNT0 = 0x0; //starting couter value
OCR0A = 0x7F; //around frequency @ 2.2HZ
//make the clk cpu slower
CLKPR = 1<<CLKPCE; //tell cpu to update the CLKPR
CLKPR = 0x8; //clkio = clkcpu/256
while(1) {
;; //interrupt do the rest
}
}

ISR(TIM0_OVF_vect) {
if (led){
b0_high;
led = 0;
} else {
b0_low;
led = 1;
}
}
#include <avr/io.h>
#include <avr/interrupt.h>
#include "pin_macros.h"
unsigned char led=0;
ISR(INT0_vect) {
if (led){
b0_high;
led = 0;
} else {
b0_low;
led = 1;
}
}
int main (void)
{
b1_input; //switch
b0_output; //led output
MCUCR = 1<<isc01; //set INT0 as falling edge trigger
GIMSK = 1<<INT0; //enable INTO in global interrupt mask
sei(); //enable interrupt
while(1) {
;; //interrupt do the rest
}
}


ruby gif2led pattern.gif 20 > pattern.hNow, we have to prepare the circuit part, we use AVR tiny13 together with 4017, please refer to the circuit diagram<here>. 4017 is used as a row counter, and such that we can only use 1 pin for row shifting. The remaining 4 IOs of the tiny13 would use for column output, we are using 10x8 matrix this time, so we assume the pattern is symteric to save pins, so 1 I/O drive 2 columns in our case. The circuit showed below:
//selected ratio is 20.0%
//Cal result: LED Matrix (row*col) = (10*8)const unsigned char pattern[63][10] PROGMEM = { //Frame 0 {0x42,0x00,0xa5,0x00,0x84,0x21,0x00,0x42,0x21,0x84} //Frame 1 ,{0x00,0xa5,0x00,0x84,0x21,0x00,0x42,0x21,0x84,0x42}
...
...#define MAX_FRAME 63
#define ROWS 10









