out_control:	call	adc_out

		movf	adresh, 0
		movwf	adc_result_m

		bsf	status, rp0
		movf	adresl, 0
		bcf	status, rp0
		movwf	adc_result_l
;-----------------
out_control_min:	movlw	flash_min_adr_m
		call	flash_read   
		movwf	flash_data_m

		movlw	flash_min_adr_l
		call	flash_read   
		movwf	flash_data_l

		btfsc	out_ok
		goto	out_control_min_0

		incf	flash_data_m
		incf	flash_data_m
		incf	flash_data_m
		incf	flash_data_m
		incf	flash_data_m
		incf	flash_data_m
		incf	flash_data_m
;-----------------
out_control_min_0:movf	adc_result_m, 0
		subwf	flash_data_m, 0	; compare - adc_result
		btfsc	status, z
		goto	out_control_min_1

		btfsc	status, c
		goto	out_control_off
		goto	out_control_max
;-----------------
out_control_min_1:movf	adc_result_l, 0
		subwf	flash_data_l, 0	; compare - adc_result

		btfsc	status, c
		goto	out_control_off
		goto	out_control_max
;--------------------------------------------		
out_control_max:	movlw	flash_max_adr_m
		call	flash_read   
		movwf	flash_data_m

		movlw	flash_min_adr_l
		call	flash_read   
		movwf	flash_data_l

		btfsc	out_ok
		goto	out_control_max_0

		decf	flash_data_m	
		decf	flash_data_m
		decf	flash_data_m
;-----------------
out_control_max_0:movf	adc_result_m, 0
		subwf	flash_data_m, 0	; compare - adc_result
		btfsc	status, z
		goto	out_control_max_1

		btfsc	status, c
		goto	out_control_on
		goto	out_control_off
;-----------------
out_control_max_1:movf	adc_result_l, 0
		subwf	flash_data_l, 0	; compare - adc_result

		btfss	status, c
		goto	out_control_off
		goto	out_control_on
;--------------------------------------------
out_control_on:	btfsc	out_ok
		goto	out_control_on_1

		decfsz	on_counter
		goto	out_control_off_2
;-----------------
out_control_on_1:	movlw	0x05
		movwf	off_counter
		movlw	0x01
		movwf	on_counter

out_control_on_2:	bsf	pin_rele_off
		bsf	pin_sv_out
		bsf	out_ok
		return
;--------------------------------------------
out_control_off:	btfss	out_ok
		goto	out_control_off_1

		decfsz	off_counter
		goto	out_control_on_2
;-----------------
out_control_off_1:movlw	0x01
		movwf	off_counter
		movlw	0x05
		movwf	on_counter

out_control_off_2:bcf	pin_rele_off
		bcf	pin_sv_out
		bcf	out_ok
		return
;-------------------------------------------------------------------------		
