;
; hello9.step.asm
; Neil Gershenfeld CBA MIT 11/12/05
;

.include "tn13def.inc"
.def temp0 = R16
.def temp1 = R17
.def temp2 = R18
.equ on_count = 30
.equ off_count = 10
.equ pulse_count = 10

.cseg
.org 0
rjmp reset

pulse_0:
   ldi temp0, pulse_count
   loop0_0:
      ldi temp1, pulse_count
      loop0_1:
         ldi temp2, on_count
         sbi PORTB, PB0
         on0:
            dec temp2
  	    brne on0
         ldi temp2, off_count
         cbi PORTB, PB0
         off0:
            dec temp2
 	    brne off0
         dec temp1
         brne loop0_1
      dec temp0
      brne loop0_0
   ret

pulse_1:
   ldi temp0, pulse_count
   loop1_0:
      ldi temp1, pulse_count
      loop1_1:
         ldi temp2, on_count
         sbi PORTB, PB1
         on1:
            dec temp2
  	    brne on1
         ldi temp2, off_count
         cbi PORTB, PB1
         off1:
            dec temp2
 	    brne off1
         dec temp1
         brne loop1_1
      dec temp0
      brne loop1_0
   ret

pulse_2:
   ldi temp0, pulse_count
   loop2_0:
      ldi temp1, pulse_count
      loop2_1:
         ldi temp2, on_count
         sbi PORTB, PB2
         on2:
            dec temp2
  	    brne on2
         ldi temp2, off_count
         cbi PORTB, PB2
         off2:
            dec temp2
 	    brne off2
         dec temp1
         brne loop2_1
      dec temp0
      brne loop2_0
   ret

pulse_3:
   ldi temp0, pulse_count
   loop3_0:
      ldi temp1, pulse_count
      loop3_1:
         ldi temp2, on_count
         sbi PORTB, PB3
         on3:
            dec temp2
  	    brne on3
         ldi temp2, off_count
         cbi PORTB, PB3
         off3:
            dec temp2
 	    brne off3
         dec temp1
         brne loop3_1
      dec temp0
      brne loop3_0
   ret

step_right:
   rcall pulse_2
   rcall pulse_0
   rcall pulse_1
   rcall pulse_3
   ret

step_left:
   rcall pulse_2
   rcall pulse_3
   rcall pulse_1
   rcall pulse_0
   ret

reset:
   ldi temp0, low(RAMEND) ; set stack pointer to top of RAM
   out SPL, temp0 ;
   sbi DDRB, PB0 ; set output pins
   sbi DDRB, PB1
   sbi DDRB, PB2
   sbi DDRB, PB3
   loop:
      rcall step_right
      rcall step_right
      rcall step_right
      rcall step_right
      rcall step_right
      rcall step_right
      rcall step_right
      rcall step_right
      rcall step_left
      rcall step_left
      rcall step_left
      rcall step_left
      rcall step_left
      rcall step_left
      rcall step_left
      rcall step_left
      rjmp loop
