;*************************************************************************** ; Application: Led flasher ; Author: Dan Williams ; Date: ; Assembler: AVR Studio 4.07. ; Target: Atmel ATtiny13. ;*************************************************************************** ;------ objective ----- ;PB0 PWM1 ;PB1 PWM2 ;PB2 ANA2 ;PB3 SC ;PB4 SD ;PB5 ANA1 ; ;---- this test ----- ;PB0 LED1 ;PB1 LED2 ;PB2 LED3 ;PB3 SC ;PB4 SD ;PB5 LED4 ; ;**************************************************************************** .device ATtiny13 ; ------------- Memory locations --------------- ; ; .def bar =r01 ; one byte ram location ; ; ---------------------------------------------- ; R 0 ->15 are gen. purp. .def A = r16 .def B = r17 ; and logic instructions .def C = r18 .def D = r19 .def curstate = r20 .def laststate = r21 .def i2cin = r22 .def bitcount = r23 .def _T = r24 .def _U = r25 .def _V = r26 .def _w = r27 .def _X = r28 .def _Y = r29 .def _Z = r30 ;cant use r25 -> r31 ; ------------- Equates ------------------ .equ INPUT = 0 .equ OUTPUT = 1 ; --- Port Directions --- .equ PB0DIR = OUTPUT .equ PB1DIR = OUTPUT .equ PB2DIR = OUTPUT .equ PB3DIR = INPUT .equ PB4DIR = INPUT .equ PB5DIR = OUTPUT ; --- Initial port state --- .equ INPB0 = 0 .equ INPB1 = 0 .equ INPB2 = 0 .equ INPB3 = 0 .equ INPB4 = 0 .equ INPB5 = 0 ; --- Port Names --- .equ LED1 = 0 ; start / stop .equ LED2 = 1 ; 1 / 0 .equ LED3 = 2 ; .equ SC = 3 .equ SD = 4 .equ LED4 = 5 ; RESET ; --- amalgimate --- .equ INITDIR = (PB5DIR< curstate:0 sbic PINB, SD ; is data not clear sbr curstate, (1<<0) ;bit copy clock -> curstate:1 sbic PINB, SC ; is clock not clear sbr curstate, (1<<1) ;lookup = laststate | curstate ;laststate = curstate >> 2 bst laststate, 0 bld curstate, 2 bst laststate, 1 bld curstate, 3 mov curstate, laststate ;if lookup = 8 then call clock0 ; falling clock edge while data low *ALSO* ack *ALSO* sending nextbit cpi curstate, 8 breq clock0 ;if lookup = 11 then call stop ; data went high while clock high cpi curstate, 11 breq stop ;if lookup = 13 then call clock1 ; falling clock edge while data high *ALSO* sending nextbit cpi curstate, 13 breq clock1 ;if lookup = 14 then call start ; data went low while clock high cpi curstate, 14 breq start rjmp irqdone stop: cbi PORTB, LED1 rjmp irqdone start: sbi PORTB, LED1 rjmp irqdone clock0: cbi PORTB, LED2 rjmp irqdone clock1: sbi PORTB, LED2 rjmp irqdone irqdone: reti