;-------------------------------------------------------------------------


#define         porog_260_m     0xaa  ;0xa7 ;0xa8 
#define         porog_260_l     0xbe  ;0x76 ;0xb0 
;---------------
#define         porog_235_m     0x98 
#define         porog_235_l     0x80 

#define         porog_230_m     0x95 
#define         porog_230_l     0x40 
;---------------
#define         porog_set_m     0x88             ; 210 v
#define         porog_set_l     0x40 
;---------------
#define         porog_210_m     0x88 
#define         porog_210_l     0x00 ;0x40 

#define         porog_205_m     0x85 
#define         porog_205_l     0x00 
;---------------
#define         porog_185_m     0x79 
#define         porog_185_l     0x00 ;0x00 

#define         porog_180_m     0x76 ;0x74 
#define         porog_180_l     0x00 ;0xc0 
;---------------
#define         porog_165_m     0x69  ;0x6c ;0x66 
#define         porog_165_l     0x8d  ;0xc0 
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
main:           call    adc
;---------------
                movlw   porog_165_l
                movwf   compare_l
                movlw   porog_165_m
                movwf   compare_m

                call    compare

                btfss   u_low_porog
                goto    main_1

                call    rele_in_set             ; U < 165
                call    rele_out_clr

	       bcf     ac_ok
                return
;---------------
main_1:         movlw   porog_180_l
                movwf   compare_l
                movlw   porog_180_m
                movwf   compare_m

                call    compare

                btfss   u_low_porog
                goto    main_2

                call    rele_in_set             ; 165 < U < 180
                call    rele_out_clr

	       bsf     ac_ok
                return
;---------------
main_2:         movlw   porog_185_l
                movwf   compare_l
                movlw   porog_185_m
                movwf   compare_m

                call    compare

                btfsc   u_low_porog
                return
;---------------
main_3:         movlw   porog_205_l
                movwf   compare_l
                movlw   porog_205_m
                movwf   compare_m

                call    compare

                btfss   u_low_porog
                goto    main_4

                call    rele_in_set             ; 185 < U < 205
                call    rele_out_set
	       bsf     ac_ok
                return
;---------------
main_4:         movlw   porog_210_l
                movwf   compare_l
                movlw   porog_210_m
                movwf   compare_m

                call    compare

                btfsc   u_low_porog
                return
;---------------
main_5:         movlw   porog_230_l
                movwf   compare_l
                movlw   porog_230_m
                movwf   compare_m

                call    compare

                btfss   u_low_porog
                goto    main_6

                call    rele_in_clr             ; 210 < U < 230
                call    rele_out_clr
	       bsf     ac_ok
                return
;---------------
main_6:         movlw   porog_235_l
                movwf   compare_l
                movlw   porog_235_m
                movwf   compare_m

                call    compare

                btfsc   u_low_porog
                return
;---------------
main_7:         call    rele_in_clr             ; 235 < U
                call    rele_out_set

                movlw   porog_260_l
                movwf   compare_l
                movlw   porog_260_m
                movwf   compare_m

                call    compare

                btfsc   u_low_porog
                goto    main_8

	       bcf     ac_ok
                return
;---------------
main_8:	       bsf     ac_ok
	       return
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
compare:        bcf     u_low_porog
;---------------
                movf    adc_result_m, 0
                subwf   compare_m, 0            ; compare - adc_result
                btfsc   status, z
                goto    compare_1

                btfss   status, c
                return

                bsf     u_low_porog
                return
;---------------
compare_1:      movf    adc_result_l, 0
                subwf   compare_l, 0            ; compare - adc_result
                btfss   status, c
                return

                bsf     u_low_porog
                return
;-------------------------------------------------------------------------

