;***** Specify Device

.include "m32def.inc"

.def tempport   =r16    
.def count1     =r17            ; and logic instructions
.def count2     =r18
.def count3     =r19
;******************************************************************
.cseg                                   ;CODE segment
.org 0x0000
        rjmp    init                    ; origin

.org 0x012A
init:   
     ldi     r16,high(RAMEND)
     out     SPH,r16
     ldi     r16,low(RAMEND)
     out     SPL,r16
     cli
     ldi     tempport,$FF
     out     DDRB,tempport           ; set portb pin 2 as output
     ser     tempport
     out     PORTB,tempport          ; set portb pin 2 level high

start:
     ldi     tempport,$00            ; set tempport bit 0 low
     out     PORTB,tempport          ; write to port

     rcall      wait               ; do the wait thing

     ldi     tempport,$FF          ; set tempport bit to high
     out     PORTB,tempport          ; write to port

     rcall      wait               ; do the wait thing

     rjmp     start               ; go back and do it all over again


; ----------------------------
; wait subroutine 
; ----------------------------
wait:    
        ldi     count1,5              ; load count1 with decimal 200

d1:
        ldi     count2,200              ; load count2 with decimal 200

d2:
     ldi     count3,200

d3:
     dec     count3
     brne     d3
        dec     count2                  ; decrement count2
        brne    d2                      ; loop if not zero              
        dec     count1                  ; decrement count1 if count2 is zero
        brne    d1                      ; do inside loop again if count2 nz
        ret
; ----------------------------        

