Thursday, May 28, 2015

And Finally the Breathing LED is Here, :)


Jonathan Ive style, Old Macbook Pro sleep indicator LED.

Using interrupt, fast PWM on ATTiny13A.





.include "../tn13Adef.INC" 
.def a = r16
.def b = r17
.def c = r18
.def d = r19
.org $0000              ; startup vector
    rjmp onReset
.org $0006              ; compare match vector
    rjmp Tim0CompA
onReset:
    ldi a, 1
    out OCR0A,a
    ldi b, 1
    ldi c, 0
    ldi d, 255
    
    sbi DDRB,0          ; port B0 as output
    
    ldi a, 0b10000011   ; pwm mode 3
    out TCCR0A, a
    
    ldi a, 0b00000011   ; divider 01/no 10/8 11/64 100/256 101/1024
    out TCCR0B,a
    
    ldi a, 0b0000100    ; enable compare interupt
    out TIMSK0,a
    
    sei

main:
    rjmp main
    
Tim0CompA:
    in a, OCR0A
    rjmp incdec
        switch:
    out OCR0A,a
    reti

incdec:
    sbrs b,0
    rjmp deca
    inc a
        back:
    cp a,c
    breq oneB
    cp a,d
    breq zeroB
        bBack:
    rjmp switch
    
    
deca:
    dec a
    rjmp back
    
oneB:
    ldi b,1
    rjmp bBack
zeroB:
    ldi b,0

    rjmp bBack
.