; 3 LED Flash
;
#include <p16F690.inc>

	__config (_HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF)

section 	UDATA
Delay1 		RES 	1
Delay2 		RES 	1

	cblock
		d1
		d2
	endc 

	org 0
	
Start
	BSF 	STATUS,RP0 		;select Register Page 1
	CLRF 	TRISC 			;make I/O PORTC all output
	BCF 	STATUS,RP0 		;back to Register Page 0
    MOVLW 	0x01            ;left justify              
    MOVWF 	ADCON0          ;Vdd and Vss as Vref
    BSF 	TRISA,1         ;Set RA0 to input                 ;
    BSF 	ANSEL,1 
        
		
MainLoop

	BCF 	PORTC,2 		;turn off LED3


;Dead Zone 0
;-----------------------------------------------------------------
; Delay = 1e-005 seconds
; Clock frequency = 20 MHz

; Actual delay = 1e-005 seconds = 50 cycles
; Error = 0 %
			;49 cycles
	movlw	0x10
	movwf	d1
Delay_0
	decfsz	d1, f
	goto	Delay_0

			;1 cycle
	nop
;-----------------------------------------------------------------


	BSF 	PORTC,0 		;turn on LED1

pot_delay0
	;Read Pot and scale time delay
	BSF 	ADCON0,GO 		;start conversion
	BTFSS 	ADCON0,GO 		;this bit will change to zero when the
							;conversion is complete
	GOTO 	$-1
	MOVF 	ADRESH,w 		;Copy the display to the LEDs
	ADDLW 	1
	MOVWF 	Delay2
A2DDelayLoop0
	DECFSZ	 Delay1,f 		;Delay Loop shortened by the ADResult as
							;controlled by the Pot. 
	GOTO 	A2DDelayLoop0
	DECFSZ 	Delay2,f
	GOTO 	A2DDelayLoop0
	
	BCF 	PORTC,0 		;turn off LED1

	
;Dead Zone 1	
;-----------------------------------------------------------------		
; Delay = 1e-005 seconds
; Clock frequency = 20 MHz

; Actual delay = 1e-005 seconds = 50 cycles
; Error = 0 %
			;49 cycles
	movlw	0x10
	movwf	d1
Delay_1
	decfsz	d1, f
	goto	Delay_1

			;1 cycle
	nop
;-----------------------------------------------------------------
	
	
	BSF 	PORTC,1 		;turn on LED2

pot_delay1	
	;Read Pot and scale time delay
	BSF 	ADCON0,GO 		;start conversion
	BTFSS 	ADCON0,GO 		;this bit will change to zero when the
							;conversion is complete
	GOTO 	$-1
	MOVF 	ADRESH,w 		;Copy the display to the LEDs
	ADDLW 	1
	MOVWF 	Delay2
A2DDelayLoop1
	DECFSZ	 Delay1,f 		;Delay Loop shortened by the ADResult as
							;controlled by the Pot. 
	GOTO 	A2DDelayLoop1
	DECFSZ 	Delay2,f
	GOTO 	A2DDelayLoop1

	BCF 	PORTC,1 		;turn off LED2

	
;Dead Zone 2	
;-----------------------------------------------------------------		
; Delay = 1e-005 seconds
; Clock frequency = 20 MHz

; Actual delay = 1e-005 seconds = 50 cycles
; Error = 0 %
			;49 cycles
	movlw	0x10
	movwf	d1
Delay_2
	decfsz	d1, f
	goto	Delay_2

			;1 cycle
	nop
;-----------------------------------------------------------------

	
	BSF 	PORTC,2 		;turn on LED3

pot_delay2	
	;Read Pot and scale time delay
	BSF 	ADCON0,GO 		;start conversion
	BTFSS 	ADCON0,GO 		;this bit will change to zero when the
							;conversion is complete
	GOTO 	$-1
	MOVF 	ADRESH,w 		;Copy the display to the LEDs
	ADDLW 	1
	MOVWF 	Delay2
A2DDelayLoop2
	DECFSZ	 Delay1,f 		;Delay Loop shortened by the ADResult as
							;controlled by the Pot. 
	GOTO 	A2DDelayLoop2
	DECFSZ 	Delay2,f
	GOTO 	A2DDelayLoop2

	
	GOTO	MainLoop
	end