 .title "Sample Application for Mud Power System"
;*********************************************************************
; Program: Mud Power Cell Sample Application
; Date: 11/16/2004
; Programmer: Lance McBride
; Target: PIC10F206 SOT23-6
;
; This switches between supercaps and blinks an LED
; Internal RC Oscillator: 20.0000MHz (EACH INSTRUCTION=0.2us)
;*********************************************************************
; .LIST P=10F206, F=INHX32, R=HEX
 .INCLUDE "d:\mplab ide\MCHIP_Tools\P10F206.inc"

/*
; Register addresses
 .equ j, 0x0020	; assigns register address 0x20 to variable j
 .equ m, 0x0024
 .equ i, 0x0022

; .global __CONFIG _CP_OFF & _WDT_OFF & _HS_OSC

 .text
; Mainline of FIRST

 .org	0

 .global __reset

; initialize registers.
; These (i, j, k) control the delay. The contents of each register;
; counts down until it hits zero, so the starting value of the
; register controls how long the delay is.

__reset:

 mov.b #20, W0		; moves 8-bit literal to working register 0 (W0)
 mov W0, i			; moves contents of W0 to i
 mov.b #0xFF, W0
 mov W0, j
 mov.b #0xFF, W0
 mov W0, m
 
; starts in bank 0 

 mov 	#0x00, W0		; set port D output latch to 
 mov	W0, LATD		; all pins to logic low
	
            
 mov	#0x00, W0		; set up direction on PORTD as all out
 mov	W0, TRISD			 

StartLoop:
 mov 	#0x00, W0			; set all pins to logic 0
 mov	W0, LATD

 call  	Delay
 bset	LATD, #0		; set lowest pin to logic high & opto ch 3
 call  	Delay
 bset	LATD, #1		; set next pin to logic high & opto ch 2
 call  	Delay
 bset	LATD, #2		; set next pin to logic high
 call  	Delay
 bset	LATD, #3		; set next pin to logic high
 call  	Delay
 
 goto StartLoop


; PROCEDURE: Simple multiple instruction delay
; Total procedure = 8,437,956 cycles
; Time/cycle @ 20MHz = 200ns
; Total delay time = 1.6875912 seconds
Delay:

 mov  #0x20, W0
 mov  W0, i
DelayLoop1:      ; 32 * (6 + 263680)
 nop

  mov  #0xFF, W0
  mov  W0, j
DelayLoop2:      ; 256 * (6 + 1024)
  nop
 
  mov	#0xFF, W0
  mov	W0, m
DelayLoop3:      ; 256 * 4
   nop
; Decrement value in register, skip next instruction if value in
; register is then zero.
	dec  m				; decrement value in register k
	btsc m, #15
	bra  DelayLoop3 	; if k is zero, go to DelayLoop3

;    decfsz  k			; reduce loop counter
;    goto DelayLoop3

	dec  j
	btsc j, #15
	bra  DelayLoop2

	dec  i
	btsc i, #15
	bra  DelayLoop1

 return
 
Finished:			; now, just spin forever
 goto $

 .end
*/
