;**********************************************************************
;                                                                     *
;    Filename:	    CH.asm                                 *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;                                                                     *
;    Files required:  ????????????? ??????????????                    *
;                          ???????????                                *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:  ???????? ?????? ?????????????? ???????????????           *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;
             	
	list      p=16f628A           		; list directive to define processor
	#include <p16F628A.inc>       		; processor specific variable definitions

	errorlevel  2            			; suppress message 302 from list file

	__CONFIG   _CP_ON & _DATA_CP_ON & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_ON & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT 


;=======================================================================================================
	cblock	0x020
;================================	
r_PORTB							; ??????????? ???????? ??????
d_PORTB							;	
d_PORTA							;

ind_1							; ?????????? ??????? ?????????? ??????? ??????
ind_2							; ?????????? ??????? ?????????? ??????? ??????
ind_3							; ?????????? ???????? ?????????? ?????????? ??????	
buf_ind_1						; ????? ?????????? 1 ??????????
buf_ind_2						; ????? ?????????? 2 ??????????
buf_ind_3						; ????? ?????????? 3 ?????????? 

perem1							; 
perem2							; 
perem5							; 

reg_ind							; ??????? ????????? ?????? ??????????
b_zad_ind						; ?????????? ???????????? ?????????
;================================
cher300_10						; 
cher02							; 
cher05							; 
;chet_10						; ??????? ???????? ???????????? ?? 1 ??
;cher60m						; ??????? ???????? ???????????? ?? 1 ???
;================================
flag_i1							; ????? ?????????
flag_i2							; ????? ?????????
flag_1							; ????? ??????????
flag_2							; ???? ?????? ?????????? ????????? ??????????
flag_3							; ????? ??????????
flag_4							; ????? ??????????
flag_5
;================================
;period							; ?????? ????????? ????????
avtovyh							; ?????????? ?????????? ?? ?????? ?????????
;================================
adr_e							; ?????????? ??? ?????? ? EEPROM
data_e							; 
chtteep						    ; ??????? ????????? ?????? ? EEPROM
;================================
uskor                     		; ?????????? ????????? ???????? ??????????? ??????? ??????
uskor_1                     	;
;========================================
;================================
;?????????? ??????????? ? ?????? EEPROM
;========================================
flag_0							;* ????? ????????? ?????? ???????????
Te_zad_hi,Te_zad_lo				;* ??????? ?????? ???????????
Gi_zad_lo						;* ???? ???????????
Up_alr_hi,Up_alr_lo				;* ??????? ????????? ???????
Dn_alr_hi,Dn_alr_lo				;* ?????? ????????? ???????
Vr_zak_hi,Vr_zak_lo				;* ????? ??????? ???????????? ?????????? ????? ? ??????? ????????? ??? ????? ?????????
Vr_pov_hi,Vr_pov_lo				;* ????? ???????? ?????????? ??????? ???????????

end_stek						;*
;========================================
Vr_cak_hi,Vr_cak_lo				; ??????? ??????? ???????????? ?????????? ????? ? ??????? ????????? ??? ????? ?????????
Vr_cpo_hi,Vr_cpo_lo				; ??????? ??????? 
;========================================
; ???????? ????????? ??????????? ??????????????
;========================================
; ?????????
flag_s							; 
count							; 
temp							; 
R3								; 
R2								; 
R1								; 
R0								; 
; ???????
binu							; 
binh							; 
binl							; 
; ????????
edin							; ???????
dest							; ???????
sotn							; ?????
tysc							; ??????
dtys							; ?????? ?????
stys							; ????? ?????
mlon							; ???????
;========================================
;========================================
; ?????????? ????????? ????????? 16 ?????? ?????
peAsh							; ?????_? 
peAsl							; 
peBsh							; ?????_? 
peBsl							; 
regsr							; 
flag_srv						; 
;========================================

;========================================
schet_sim1						; ??????? ????? ??????
schet_sim2						; ??????? ?????? ???????
;===================================
TEMP_HI
TEMP_LO
;vr_konvert
COM_REG
TEMP0 
TEMP1
t_binu
t_binh
t_binl
T_izm_hi					   		; ?????????? ???????????
T_izm_lo					  		;
;========================================
T_min_hi					   		; ??????????? ???????????
T_min_lo					  		;
T_max_hi					   		; ???????????? ???????????
T_max_lo					  		;
;========================================
;========================================
	endc
;========================================
	cblock	0x07d	
;================================
w_temp                     		; variable used for context saving 
status_temp                		; variable used for context saving
pclath_temp        	  			; variable used for context saving
;=================================
	endc
;========================================
	cblock	0x0A0
	endc	
;========================================


;===========================================================================================
;===========================================================================================
; ???????? ?????? ??????????? ???????? (??????? ?????? ???? ?????????? ? ?????? ?????)
#define		TRISDAL	TRISA		; ??????? ?????????? ????? ???????
#define		PORTDAL	PORTA		; ??????? ?????? ????? ???????
#define		LINE	3			; ????? ????? ???????1
#define		DALLAS	PORTA,3		; ???? ????? ? ????????1
;===========================================================================================
; ???????? ?????? ?????????
#define		S_A		d_PORTB,1	; ??????? ?
#define		S_B		d_PORTB,2	; ??????? B
#define		S_C		d_PORTB,3	; ??????? C	
#define		S_D		d_PORTB,4	; ??????? D
#define		S_E		d_PORTB,5	; ??????? E 
#define		S_F		d_PORTB,6	; ??????? F
#define		S_G		d_PORTB,7	; ??????? G
#define		S_H		d_PORTA,6	; ??????? H

#define		SOT		d_PORTA,1	; ??????????? ??? ??????? ??????????
#define		DES		d_PORTA,2	; ??????????? ??? ??????? ??????????
#define		EDI		d_PORTA,7	; ??????????? ??? ???????? ??????????

; ?????????? ????? ??? ?????? ????????? ?????????
; ???? ?
#define		CL_PA	b'00011001'	; ? ???? ????? "0" ??????????????? ?? ???? ??????? ?????????? ????????, "1" ?? ???? ????????? ??????? ?? ?????? ???????? ??? ????? ????????? 
#define		SE_PA	b'10000110'	; ? ???? ????? ?????????? ? "1" ???? ???? ??? ????????? ? ???????????? ??????? ???????? ???????????
; ???? ?
#define		CL_PB	b'00000000'	; ? ???? ????? "0" ??????????????? ?? ???? ??????? ?????????? ????????, "1" ?? ???? ????????? ??????? ?? ?????? ???????? ??? ????? ????????? 
#define		SE_PB	b'00000000'	; ? ???? ????? ?????????? ? "1" ???? ???? ??? ????????? ? ???????????? ??????? ???????? ???????????

;===========================================================================================
; PORTY TLAčíTEK
#define		TRB2		PORTB,1		; vice
#define		TRB3		PORTB,2		; méně
#define		TRB1		PORTB,3		; FUNKCE
#define		TRB4		PORTB,4		; FUNKCE RUČNĚ
#define		PORTKN		b'00011110'	;POPSÁNÍ POLOHY TLAČÍTEK PORTU

;===========================================================================================
;===========================================================================================
#define		INDK	flag_0,0	; ????? "????????? ???????????"
#define		NAGR	flag_0,1	; ????? "???????????"
#define		HOLD	flag_0,2	; ????? "??????????"
#define		RUCH	flag_0,3	; REŽIM RUČNĚ
;=================================
#define		B_MIG	flag_1,0	; ??? ??????? (1 ???????, 0 ?????)
#define		UST	flag_1,1	; ??? ?????? ????????? ??????????
#define		vp_rp	flag_1,2	; ??? ?????? 0-????? ?????????, 1-????????? ?????????
#define		LE_RI	flag_1,3	; ??? ??????????? ??????
#define		CON	flag_1,4	; ??? ???? ??????????????? ???????????
;=================================
; ???? ????????? ????????? ??????????
#define		REGRA	flag_2,0	; ??? ?????? ?????? ?????? ??????????
#define		TMZAD	flag_2,1	; ??? ??????? ??????????? ?????????????
#define		GIZAD	flag_2,2	; BIT ZAD?N? HYSTEREZE
#define		HIALR	flag_2,3	; ??? ????????? ??????? ?????? ????????????? ???????????
#define		LOALR	flag_2,4	; ??? ????????? ??????? ?????? ????????????? ???????????
#define		VRZDR	flag_2,5	; ??? ??????? ????????? ?????? ????????????
#define		VRPZK	flag_2,6	; ??? ??????? ?????????? ??????? ???????????
#define		PROIZ	flag_2,7	; ?????? ? ????????????
;=================================
#define		kl_no	flag_3,0	; DRŽENÍ TLAČÍTKA
#define		RELE1	flag_3,1	; ????? ???? 
#define		RELE2	flag_3,2	; ????? ???? 
#define		E_data	flag_3,3	; ???? ?????? ??????
#define		MINUS	flag_3,4	; ??? ????????? ????????????? ??????????
#define		ERROR_D	flag_3,5	; ?????? ??????? ???????????
#define		oh_te	flag_3,6	; ????????? ??????? ??????????? ??????? ?? ??????????? ???????
;=================================
#define		MINUS_d	flag_4,0	; ??? ????????? ????????????? ??????????
#define		B24	flag_4,1	;
#define		BTE	flag_4,2	; ??? ??????? ?????? ????? ?? 00
#define		BTE0_00	flag_4,3	;
#define		BRACON	flag_4,4	; ??? ?????????? ????????????
#define		zad_op	flag_4,5	; ??? ?????????? 
#define		Ind_MIN	flag_4,6	; ????????? ??????????? ???????????
#define		Ind_MAX	flag_4,7	; ????????? ???????????? ???????????
;=================================
#define		f_RB1	flag_5,0	;
#define		f_RB2	flag_5,1	;
#define		f_RB3	flag_5,2	;
#define		f_RB4	flag_5,3	;
;=================================
; ???? ????????? ?????????
#define		TOCHKA1	flag_i2,0	; ??? ????????? ?????????? ?????
#define		TOCHKA2	flag_i1,1	; 
#define		TOCHKA3	flag_i1,2	; 
#define		TOCHm1	flag_i1,3	; ??? ??????? ?????????? ?????
#define		TOCHm2	flag_i1,4	; 1 - ?????? ? ???????? 2 ??.
#define		TOCHm3	flag_i1,5	; 0 - ????? ?????????
#define		RAZR1	flag_i1,6	; ??? ??????? ??????? ??????????
#define		RAZR2	flag_i1,7	; 0 - ????? ?????????
#define		RAZR3	flag_i1,0	; 1 - ?????? ? ???????? 2 ??.
;=================================
; ???? ????????? ?????????
#define		RAV		flag_srv,0		; ??? ????????? =
#define		BOL		flag_srv,1		; ??? ????????? >
#define		MEN		flag_srv,2		; ??? ????????? <
#define		BOL_RAV	flag_srv,3		; ??? ????????? >=
#define		MEN_RAV	flag_srv,4		; ??? ????????? <=
;=================================

;=================================
#define		SPUAN	.15			; ???????? ???????? ?????????? ?? ?????????
#define		DIND	.10			; ???????????? ?????????? ? ?????? ????????? (????????? ????? - .10 ??????)
;======================================================================================
; ??????? ???????????????
#define		c0		b'01111110'	; 0-0
#define		c1		b'00001100'	; 1-1
#define		c2		b'10110110'	; 2-2 "z"
#define		c3		b'10011110'	; 3-3
#define		c4		b'11001100'	; 4-4 "?"
#define		c5		b'11011010'	; 5-5 "S"
#define		c6		b'11111010'	; 6-6
#define		c7		b'00001110'	; 7-7
#define		c8		b'11111110'	; 8-8
#define		c9		b'11011110'	; 9-9
;======================================================================================
#define		c_		b'00000000'	; ?????? "??????" 
#define		cM		b'10000000'	; ?????? "-"
#define		cn		b'10101000'	; "n"
#define		cN		b'01101110'	; "?"
#define		co		b'10111000'	; "o" 
#define		cE		b'11110010'	; "E"
#define		cr		b'10100000'	; "r"
#define		cd		b'10111100'	; "d"
#define		cb		b'11111000'	; "b"
#define		ct		b'11110000'	; "t"
#define		cA		b'11101110'	; "A"
#define		cC		b'01110010'	; "C"
#define		cH		b'11101100'	; "H"
#define		cP		b'11100110'	; "P"
#define		cc		b'10110000'	; "c"
#define		ch		b'11101000'	; "h"
#define		cL		b'01110000'	; "L"
#define		ci		b'00100000'	; "i"
#define		cg		b'11001110'	; "g"
#define		cF		b'11100010'	; "F"
#define		cU		b'01111100'	; "U"
#define		cu		b'00111000'	; "u"
#define		cY		b'11011100'	; "?"

;======================================================================================

;=======================================================================================================
;**********************************************************************
		ORG		0x000      	   			; processor reset vector
 			nop
		goto	main           			; go to beginning of program
;=======================================================================================================
	ORG     0x004             			; interrupt vector location
			movwf   w_temp            	; save off current W register contents
			movf	STATUS,w          	; move STATUS register into W register
			movwf	status_temp       	; save off contents of STATUS register
			movf	PCLATH,W	  		; move PCLATH register into W register
			movwf	pclath_temp       	; save off contents of PCLATH register

			clrf	STATUS				; ????? ????? 0
;===============================================
			bcf		T1CON,TMR1ON		; ?????? ????????,
			bcf		PIR1,TMR1IF			; ???????? ???? ?????????? ?? ?????? TMR1
			movlw	0xfe				; ???????? ?? 300 ??
			movwf	TMR1H				; ?????????? ?????????????? ???????
			movlw	0x60				; ??? ??????????????? ??????? ?? 300 ??
			movwf	TMR1L				; (65563 - ((4 000 000/4)/8)/300) 
;============== ?????? 	300 ??	
;========================================================================== 
;==============	????????? ???????????? ??????? ????????? ????????
			movf	b_zad_ind,f			; ????????? ????? ??????? ?????
			BZ		$+2					;
			decf	b_zad_ind,f			; 
;==============	????????? ???????????? ?????? ??????????
			call	indic				;
;========================================================================== 
			decfsz	cher300_10,f		; ??????? ???????? ???????????? ?? 10 ?? 
			goto	end_pr				; 
			movlw	.30					; ???? ????????? ???? ??????????? ???????
			movwf	cher300_10			;
;========================================================================== 
;======== ?????? 	10 ??		
;========================================================================== 
			decfsz	cher05,f			; ??????? ???????? ???????????? ?? 2 ?? 
			goto	end_pr				; 
			movlw	.5					; ???? ????????? ???? ??????????? ???????
			movwf	cher05				;
;========================================================================== 
;============== ?????? 	2 ??
			btfss	B_MIG				; ???? ?????????? ??????????? ??????????
			goto	$+3					;
			bcf		B_MIG				;
			goto	$+2					;
			bsf		B_MIG				;
;========================================================================== 			
			decfsz	cher02,f			; ??????? ???????? ???????????? ?? 1 ?? 
			goto	end_pr				; 
			movlw	.2					; ???? ????????? ???? ??????????? ???????
			movwf	cher02				; ?????? 1 ??
;==========================================================================
;============== ?????? 	1 ?? start		;				
			
			;==============		?????? ??????? ???????? ???????????	
			movf	Vr_cak_hi,f		; 
			btfss	STATUS,Z		; 
		goto	decfvrem			; 
			movf	Vr_cak_lo,f		; 
			btfss	STATUS,Z		; 
		goto	decfvrem			; 
			bsf		BRACON			; 			
		goto	end_decfvrem	
decfvrem			
			movlw	.1				;
			subwf	Vr_cak_lo,f		;
			btfss	STATUS,C		;
			decf	Vr_cak_hi,f		;			
end_decfvrem
			;==============			
			;==============		?????? ??????? ?????????? ?????	
			movf	Vr_cpo_hi,f		; 
			btfss	STATUS,Z		; 
		goto	decf_open			; 
			movf	Vr_cpo_lo,f		; 
			btfss	STATUS,Z		; 
		goto	decf_open			; 
			bsf		zad_op		; 			
		goto	end_decf_open	
decf_open			
			movlw	.1				;
			subwf	Vr_cpo_lo,f		;
			btfss	STATUS,C		;
			decf	Vr_cpo_hi,f		;			
end_decf_open
			;==============				
			;==============			;
			movf	avtovyh,f		; ?????? ??????? 
			SKPNZ					;
		goto	chet_1mi_m			;
			decfsz	avtovyh,f		;
		goto 	chet_1mi_m			;
			call	resautoexit
			;==============			;
;===============================================				
chet_1mi_m							;	
;===============================================
;==========================================================================
;============== ?????? 	1 ?? end
;=================================
;=================================
;=================================
;=================================
end_pr
			bsf		T1CON,TMR1ON	; ?????? ???????,

			movf    pclath_temp,w     	; retrieve copy of PCLATH register
			movwf	PCLATH            	; restore pre-isr PCLATH register contents
			movf    status_temp,w     	; retrieve copy of STATUS register
			movwf	STATUS            	; restore pre-isr STATUS register contents
			swapf   w_temp,f
			swapf   w_temp,w          	; restore pre-isr W register contents
		retfie                   	 	; return from interrupt
;=======================================================================================================
;*************************************************************************************************************************************************
deshif		addwf	PCL,f			; ?????????? ????
			retlw	b'01111110'		; "0"
			retlw	b'00001100'		; "1"
			retlw	b'10110110'		; "2"
			retlw	b'10011110'		; "3"
			retlw	b'11001100'		; "4"
			retlw	b'11011010'		; "5"
			retlw	b'11111010'		; "6"
			retlw	b'00001110'		; "7"
			retlw	b'11111110'		; "8"
			retlw	b'11011110'		; "9"
			retlw	b'00000000'		; "10"-"?????"
			retlw	b'10000000'		; "11"-"?????"				
;*************************************************************************************************************************************************
;*************************************************************************************************************************************************
con_dro		addwf	PCL,f			;  		?????? ????	 ???????????
			retlw	.0				; 0-		00			0 ??? ???????? 0,1 ???
			retlw	.1				; 1-		06			1 ??????????? ??????????
			retlw	.1				; 2-		12			1 ??? ???????? 0,01 ???
			retlw	.2				; 3-		18			2 ????????? ?????? ????
			retlw	.3				; 4-		25			3
			retlw	.3				; 5-		31			3
			retlw	.4				; 6-		37			4
			retlw	.4				; 7-		43			4
			retlw	.5				; 8-		50			5
			retlw	.6				; 9-		56			6
			retlw	.6				; 10-		62			6
			retlw	.7				; 11-		68			7
			retlw	.8				; 12-		75			8
			retlw	.8				; 13-		81			8
			retlw	.9				; 14-		87			9
			retlw	.9				; 15-		93			9
			retlw	.0				; 16-		00			0 ????? ????
;============================================================================================
;*******************************************************************************************************************************************
text_1		addwf	PCL,f			; ??? ?????????? (???? ????? ? 0)
			retlw	.12				; ?????????? ?????? - retlw ? ????????????
			retlw	cC				; C
			retlw	cA				; A
			retlw	cM				; "-"
			retlw	c2				; 2
			retlw	c6				; 6
			retlw	cM				; "-"
			retlw	cn				; n
			retlw          ci				; i				
			retlw	cc				; c
			retlw	co				; o
			retlw	cM				; "-"
					;	.12 ?????? ???????
			retlw	.6				; ?????????? ?????? - retlw ? ????????????
			retlw	b'11110010'		; "E"
			retlw	b'10100000'		; "r"
			retlw	b'00000000'		; " "
			retlw          b'10111100'		; "d"
			retlw	b'11110001'		; "t."
					;	.24 -18 ??????? ????????????
			retlw	.16				; ?????????? ?????? - retlw ? ????????????
			retlw	b'10000000'		; "-"
			retlw	b'10000000'		; "-"
			retlw	b'00001110'		; 7-7
			retlw	b'10110110'		; "2"
			retlw	b'11111110'		; "8"
			retlw	b'10000000'		; "-"
			retlw	b'11011110'		; "9"
			retlw	b'11001100'		; "4"	
			retlw	b'11111110'		; "8"
			retlw	b'10000000'		; "-"
			retlw	b'00001110'		; 7-7
			retlw	b'11111010'		; "6"						
			retlw	b'11111010'		; "6"	
			retlw	b'10000000'		; "-"			
			retlw	b'10000000'		; "-"			
					;	.34 ?????? ??????
			retlw	.6				; ?????????? ?????? - retlw ? ????????????
			retlw	b'11110010'		; "E"
			retlw	b'10100001'		; "r."
			retlw	b'00000000'		; " "
			retlw	b'11011010'		;  "S
			retlw	b'10101000'		; "n"
					;	.40 ??????? ?????? - ??????
			retlw	.4				; ?????????? ?????? - retlw ? ????????????
			retlw	ct				; "t"
			retlw	co				; "o"
			retlw	cP				; "P"
					;	.44 ??????? ?????? - ???????
			retlw	.4				; ?????????? ?????? - retlw ? ????????????
			retlw	b'01110010'		; "?"
			retlw	b'10111000'		; "o"
			retlw	b'01110000'		; "L"
					;	.48
			retlw	.5				; ?????????? ?????? - retlw ? ????????????
			retlw	b'01110010'		; "C"
			retlw	b'11101100'		; "H"
			retlw	b'01110000'		; "L"
			retlw	b'00000010'		; "-"
					;	.53 
			retlw	.4				; ?????????? ???????? +1
			retlw	ct				; "t"
			retlw	cE				; "E"
			retlw	cP				; "P"
					;	.57  prop
			retlw	.4				; ?????????? ???????? +1
			retlw	b'11101100'		; "H"
			retlw	b'11001100'		; "y"
			retlw	b'11011010'		; 5-5 "S"
					;	.61  iteg
			retlw	.4				; ?????????? ???????? +1
			retlw	ct				; "t"
			retlw	b'00000010'		; "-"
			retlw	b'00000010'		; "-"
					;	.65 Uu1 ---
			retlw	.4				; ?????????? ???????? +1
			retlw	ct				; "t"
			retlw	b'00010000'		; "_"
			retlw	b'00010000'		; "_"
					;	.69 Tel
			retlw	.4				; ?????????? ???????? +1
			retlw	b'11110000'		; "t"
			retlw	b'11110010'		; "E"
			retlw	b'01110000'		; "L"
					;	.73 ???/????
			retlw	.4				; ?????????? ???????? +1
			retlw	b'10100000'		; "r"
			retlw	b'11110010'		; "E"
			retlw	b'01111010'		; "G"
					;	.77 Uu2 ---
			retlw	.4				; ?????????? ?????? - retlw ? ????????????
			retlw	b'01110010'		; "C"
			retlw	b'11101110'		; "A"
			retlw	b'11011010'		; 5-5 "S"
					;	.81 Uu3 ---
			retlw	.4				; ?????????? ?????? - retlw ? ????????????
			retlw	b'01110010'		; "C"
			retlw	b'10110110'		; "2"
			retlw	b'10110000'		; "c"
;					;	.85  iteg
;			retlw	.4				; ?????????? ???????? +1
;			retlw	ct				; "t"
;			retlw	b'00000010'		; "-"
;			retlw	b'00000000'		; ""
;					;	.89 Uu1 ---
;			retlw	.4				; ?????????? ???????? +1
;			retlw	ct				; "t"
;			retlw	b'00010000'		; "_"
;			retlw	b'00000000'		; ""
;============================================================================================


;============================================================================================
; ??????? ?????? ??????
main		movlw	0x5				; ???? 0
			movwf	FSR				; 
ClfMem		clrf	INDF			; 
			incf	FSR,f			; 
			movlw	0x80			;
			subwf	FSR,w			;
			BNZ 	ClfMem			;
			clrf	INDF			; 			
;============================================================================================
;============================================================================================
;????????????? ??????????
			clrwdt					; ????? ??????????? ???????++++++
;====================================
			movlw	0x07			; 0x07 ???
			movwf	CMCON			; ????????? ???????????
;====================================
			bsf		STATUS,RP0		; ????? ????? 1
			movlw	b'00001111'		; ????????? ????????? (???????? ??????. ?????????, ???????????? ?? WDT, ????. 1:128)
			movwf	OPTION_REG		; 
;====================================
			movlw	b'00001000'		;  ????????? ?????? A ? ? R0 ?? ????, ????????? ?? ?????
			movwf	TRISA			;
;			clrf	TRISA			; 
			clrf	TRISB			; 

;==================================== 			
		; ????????? ???????	TMP1	; 
			bcf		STATUS,RP0		; ??????? ???? 0
			movlw	b'00110001'		; ?????? ???????, ???????????? 4 ?? = 1:8 - 125 000 ??
			movwf	T1CON			;
;============================================================================================
			call	vost_data		; ????????????? ???????? ????? ????????? ???????
;============================================================================================
		; ????????????? ??????????
			movlw	SPUAN			;
			movwf	uskor_1			; 
			movwf	uskor			; 
			
			movlw	.2				; ??????? 10 ?? ????? 1 ???????
			movwf	cher300_10		; 
			movwf	cher02			; 
			movwf	cher05			; 
			
			bcf		LE_RI			; ????????? ????? ?????? ???????????

			call	res_init		;
;============================================================================================
		; ????????? ??????????
			movlw	b'11000000'		;
			movwf	INTCON			; ????????? ?????????? ?? ???????????? ?????????
			bsf		STATUS,RP0		; ????? ????? 1
			bsf		PIE1,TMR1IE		; ????????? ?????????? ?? TIMER1
			bcf		STATUS,RP0		; ????? ????? 0
;============================================================================================
;============================================================================================
			bsf		STATUS,RP0			; ??????? ???? 1
			movlw	PORTKN				; ? ????????? ????? ?????? ?? ????
			movwf	TRISB				; 
			bcf		STATUS,RP0			; ??????? ???? 0			

			btfsc	TRB3					; ???? ????? ??????? ?????????? 
			goto	$+.2				; 	
		goto	vos_data				; 
			
			bsf		STATUS,RP0			; ??????? ???? 1
			clrf	TRISB				; ? ????????? ??? ????? ????? ?? ????? 
			bcf		STATUS,RP0			; ??????? ???? 0
;============================================================================================			
;============================================================================================
		; ???????? ????????? ????????? ? ??????? ??????????
			call	celsio				;
			;==============				;
			movlw	.0					; 
			call	big_str				; ??????? ?????? CH-25xx
			call 	och_left			; ??????? ??????????
	
			call	celsio				;
			bsf		Ind_MIN				;
			bsf		Ind_MAX				;
			call	restem				;
;============================================================================================




;============================================================================================
; ???? ?????? ??????????
ind			clrwdt						; ????? ??????????? ???????++++++
			;==============				;
			call	kondosdata			; 
			;==============				;		
			call	celsio				; ????????? ???????????
			;==============				; ?????????
;========================================
			movf	T_izm_lo,w			;
			movwf	peAsl				; ????????? ?????? ?? ?????????? ??????	
			movf	T_izm_hi,w			;
			movwf	peAsh				;			
			movf	T_max_lo,w			;
			movwf	peBsl				; ????????? ?????? ?? ?????????? ??????	
			movf	T_max_hi,w			;
			movwf	peBsh				;			
 			call    sravnenie			;
			btfss	BOL					; ?????????  ?????? ??????? ???????? ??????????
		goto	$+.5							;
			movf	T_izm_lo,w			; 
			movwf	T_max_lo			; ????????? ? ?????????? ??????? ???????????
			movf	T_izm_hi,w			; 
			movwf	T_max_hi			; ????????? ? ?????????? ??????? ???????????
;========================================
			movf	T_min_lo,w			;
			movwf	peBsl				; ????????? ?????? ?? ?????????? ??????	
			movf	T_min_hi,w			;
			movwf	peBsh				;			
 			call    sravnenie			;
			btfss	MEN					; ?????????  ?????? ??????? ???????? ??????????
		goto	$+.5							;
			movf	T_izm_lo,w			; 
			movwf	T_min_lo			; ????????? ? ?????????? ??????? ???????????
			movf	T_izm_hi,w			; 
			movwf	T_min_hi			; ????????? ? ?????????? ??????? ???????????			
;========================================
			btfsc	Ind_MIN				; 
		goto	immi					; 
			btfsc	Ind_MAX				; 		
		goto	imma					; 
			movfw	T_izm_hi			; 			
			movwf	binh				; 
			movfw	T_izm_lo			; 				
		goto	itegc			
immi		movfw	T_min_hi			; 			
			movwf	binh				; 
			movfw	T_min_lo			; 				
		goto	itegc			
imma		movfw	T_max_hi			; 			
			movwf	binh				; 
			movfw	T_max_lo			; 				
itegc		movwf	binl				;
			
			bsf		BTE					;
			call	bin_dec				;
			call	conv_t				;
;========================================			
			call	ind_zad				;
			;==============				;
			movlw	.20					;
			movwf	b_zad_ind			;
			;==============				;
			call	upravlenie			;	(?????????? ???????????? ?????????)		
			;==============				;
			call	klava				; 
;--------------------------------------------				
kontr		btfss	UST					; ????? ?????? ??????
			goto	ind					; ????? ????????? ? ?????????????/????? ?????????
;--------------------------------------------
; ???? ????????? ??????????
nast	
			;==============				;		
			call	celsio				; ????????? ???????????
			;==============				; 
			clrwdt						; ????? ??????????? ???????++++++
			call	upravlenie			;
			movfw	uskor				;
			movwf	b_zad_ind			;
			call	ind_zad				; 			
			call	klava				; 
		goto	kontr					; 
;============================================================================================


;============================================================================================
restem
			btfss	Ind_MIN				; 
		goto	$+.5					; 
			movf	T_izm_lo,w			; 
			movwf	T_min_lo			; 
			movf	T_izm_hi,w			; 
			movwf	T_min_hi			;
			bcf		Ind_MIN				;
			
			btfss	Ind_MAX				; 
	return								; 
			movf	T_izm_lo,w			; 
			movwf	T_max_lo			;
			movf	T_izm_hi,w			; 
			movwf	T_max_hi			;
			bcf		Ind_MAX				;
	return
;============================================================================================
upravlenie								;????????? ?????????? ??????? ???????????
;============================================================================================
;============================================================================================
;======================================= ????? ?????????????
			btfsc	ERROR_D				; ???????? ??????????? ??????? ???????????
		return							;
;			btfsc	UST
;		return			
			btfsc	NAGR				; ???????? ?????? ? ??????? ??????????? ??? ????????????.
		goto	upra					; 
			btfsc	HOLD				; 
		goto	upra					; 
			btfsc	RUCH
		return							; 
			bcf	RELE1					; 
			bcf	RELE2					; 
		return							; 			
;======================================= 
upra		clrf	peBsh				; 
			movf	T_izm_lo,w			;
			movwf	peAsl				; ????????? ?????? ?? ?????????? ??????	
			movf	T_izm_hi,w			;
			movwf	peAsh				;			
			movf	Gi_zad_lo,w			; ???????? ???????? ??????????? ? ??????????? ?????????
			addwf	Te_zad_lo,w			;
			movwf	peBsl				; ???????? ??????
			btfsc	STATUS,C			; 
			incf	peBsh,f				; 
			movf	Te_zad_hi,w			;
			addwf	peBsh,f				; ???????? ??????
 			call    sravnenie			;
			btfsc	BOL_RAV				; ?????????  ?????? ??????? ???????? ??????????
		goto	off_re					;
				
			movf	Te_zad_hi,w			;
			movwf	peBsh				; ???????? ??????			
			movf	Gi_zad_lo,w			; ???????? ???????? ??????????? ? ??????????? ?????????
			subwf	Te_zad_lo,w			;
			movwf	peBsl				; ???????? ??????
			btfss	STATUS,C			; 
			decf	peBsh,f				; 
 			call    sravnenie			;
			btfss	MEN_RAV				; ?????????  ?????? ??????? ???????? ??????????
		goto	control					; 
			btfsc	HOLD				;			
		goto	bcre					; 
bsre		bsf		RELE1				; ????????
rein		bcf	RAZR1					; 
			bcf	RAZR2					; 
			bcf	RAZR3					; 
		goto	control					; 
off_re									; 
			btfss	HOLD				;
		goto	bcre					; 
			btfsc	zad_op				; 
		goto	bsre					; 	
			btfsc	UST					; ????????? ??????? ?????????? ? ?????? ?????????		
		goto	rein					; 
			bsf	RAZR1					; 
			bsf	RAZR2					; 
			bsf	RAZR3					; 
		goto	control					; 
bcre		btfss	RELE1				; 
		goto	rein					; 
			bcf		RELE1				; ?????????;
			bcf		zad_op				; 	
			movfw	Vr_pov_hi			;
			movwf	Vr_cpo_hi			; 
			movfw	Vr_pov_lo			;
			movwf	Vr_cpo_lo			; 			
;	return								; 
;============================================================================================
control		; ???????? ????????? ????????? ???????????? ?????
			; ????? ?? ?????????? ??????? ? ??????? ????? ? ???????? ?????????
			movf	Vr_zak_hi,f			; 
			btfss	STATUS,Z			; 
		goto	rong					; 
			movf	Vr_zak_lo,f			; 
			btfss	STATUS,Z			; 
		goto	rong					; 
	return								; ??????? ??????????????
;========================================
rong
			btfss		BRACON			; 	
	return								; ????? ??????? ?? ?????
;========================================
			movfw	T_izm_hi			; ????????? ?????? ?? ?????????? ??????	
			movwf	peAsh				; ?????????? ??????????? ?? ?????? ?????????
			movfw	T_izm_lo			; 
			movwf	peAsl				;
			
			movfw	Up_alr_hi			;
			movwf	peBsh				; 
			movfw	Up_alr_lo			; 
			movwf	peBsl				;
			call	sravnenie			;
			btfss	MEN					;
		goto	alr_d2					;

			movfw	Dn_alr_hi			;
			movwf	peBsh				; 
			movfw	Dn_alr_lo			; 
			movwf	peBsl				;
			call	sravnenie			;
			btfss	BOL					;
		goto	alr_d2					;
			bcf		RELE2				; ot??????? ???? ??????
	return								; 
alr_d2
			bsf		RELE2				; ???????? ???? ??????
			btfsc	UST
		return	
			movlw	.48 				; 
			call	big_str				; ??????????? ??? ?????????? ????
			call 	och_left			; ??????? ??????????
			movlw	.255				; ??????????? ??????? ?????????
			movwf	b_zad_ind			;
	return								; 				
;============================================================================================
;============================================================================================
klava		; ????????? ????????? ??????? ??????
			bsf		STATUS,RP0			; ????? ????? 1
			movlw	PORTKN				; ? ????????? ????? ?????? ?? ????
			movwf	TRISB				; 
			bcf		STATUS,RP0			; ????? ????? 0
;==================================== !!!!!!!!
;			call	zaderj				; ????? ???????????? ????????
										; ??????????? ??? ????????? ??????? ???????? ?? ??????
;====================================
			btfsc	TRB1					; ??????? ??????? 
		goto	t_PB3					; 
			btfsc	kl_no				; 
		goto	vyh						; 
			call	zaderj				; ????? ???????????? ????????
			call	zaderj  ; Chenzee
			call	zaderj  ; Chenzee
			btfsc	TRB1					; ??? ??????? ???????? ?????????			
		goto	end_kl_call				; 
			;
;;;;;;;;;;;;;;;;;;;;;; Chenzee
			btfsc	TRB2					; ??????? ??????? 
			goto	Chenzee1 ; je zmacknute pouze TRB1
			call	zaderj		;je zmacknute i RB2 ==>misto RB4	; ????? ???????????? ????????
			goto	t_PB4
;;;;;;;;;;;;;;;;;;;; Chenzee
;====================
Chenzee1
			bcf		f_RB1
			btfsc		vp_rp			; ??? ?????? ?????? ?????????? ??????? ???????? 1- ??????? ????????? ??????????
		goto	$+3						; 
			bsf			vp_rp			; ?????????? ????? ????????? ?????????? ??? ?????? < >
		goto	$+2						; 
			bcf			vp_rp			; ?????????? ????? ?????? ??????? ??? ?????? < >
vyb_re	
			call	vyb_fun				; 
		goto	end_kl_call				; 
;====================================		
t_PB3		btfsc	TRB3					; ??????? ?????? 
		goto	t_PB2					; 
			btfsc	kl_no				; 
		goto	vyh						; 
			call	zaderj				; ????? ???????????? ????????
			btfsc	TRB3					; 			
		goto	end_kl_call				; 			
			bcf		f_RB3				;
;====================
			btfss	UST					;
		goto	in_temin				;
			btfsc	vp_rp				; ??? ?????? ?????? ?????????? ??????? ???????? 1- ??????? ????????? ??????????
		goto	$+3						; 
			bsf		LE_RI				; ????? ??????????? ?????? ???????. ?????? ????? ????????? ????? ???????
	goto	vyb_re						; 
			call	ustanov				; 
		goto	end_kl_call				; 
;====================================	
t_PB2		btfsc	TRB2					; ??????? ?????? 
		goto	end_klava ;chenzee
		;goto	t_PB4	  ;chenzee				;  
			btfsc	kl_no				; 
		goto	vyh						; 
			call	zaderj				; ????? ???????????? ????????
			call	zaderj	 ; Chenzee		; ????? ???????????? ????????
			call	zaderj 	 ; Chenzee		; ????? ???????????? ????????

			btfsc	TRB2					; 			
		goto	end_kl_call				; 			
;;;;;;;;;;;;;;;;;;;;;; Chenzee
			btfsc	TRB1					; ??????? ??????? 
			goto	Chenzee2 ; je zmacknute pouze TRB1
			call	zaderj		;je zmacknute i RB1 ==>misto RB4	; ????? ???????????? ????????
			call	zaderj
			goto	t_PB4
;;;;;;;;;;;;;;;;;;;; Chenzee
;====================
Chenzee2
			bcf		f_RB2				;
;====================			
			btfss	UST					;
		goto	in_temax				;
			btfsc	vp_rp				; ??? ?????? ?????? ?????????? ??????? ???????? 1- ??????? ????????? ??????????
		goto	$+3						; 
			bcf		LE_RI				; ????? ??????????? ?????? ???????
		goto	vyb_re					; 
			call	ustanov				; 
		goto	end_kl_call				; 
;====================================
;====================================
t_PB4	
;;;;;;;;;;;;;;;;;Chenzee
;	btfsc	TRB4					; ??????? ?????? 
;		goto	end_klava				;  
;			btfsc	kl_no				; 
;		goto	vyh						; 
;			call	zaderj				; ????? ???????????? ????????
;			btfsc	TRB4					; 			
;		goto	end_kl_call
;;;;;;;;;;;;;;;;;Chenzee						; 			

			bcf		f_RB4				;
;====================			
			btfss	RUCH				; JESTLI JE RUČNÍ REŽIM SEPNI RELE
		goto	trote					; 
			btfsc	kl_no			
		goto	vyh						;
			btfss	RELE1				; 
		goto	$+4						; 
			bcf		RELE1				; 
			bsf		kl_no				; ??? ??????? ??????
		goto	end_kl_call				; 
			bsf		RELE1				; 								
			bsf		kl_no				; ??? ??????? ??????
		goto	end_kl_call				; 			
trote		call	restem				; 
		goto	end_kl_call				; 
;====================================
in_temin
			bcf		Ind_MAX				; 
			bsf		Ind_MIN				; 
			movlw	ct 					; 
			movwf	ind_1				; 
			movlw	b'00010000'			; "_" 
			movwf	ind_2				; 
			movlw	b'00000000'			; "" 
			movwf	ind_3				; 
		goto	inhre	
;====================================
in_temax
			bcf		Ind_MIN				; 	
			bsf		Ind_MAX				; 
			movlw	ct 					; 
			movwf	ind_1				; 
			movlw	b'00000010'			; "-" 
			movwf	ind_2				; 
			movlw	b'00000000'			; "" 
			movwf	ind_3				; 
inhre
			clrf	flag_i2
			clrf	flag_i1
			bsf		STATUS,RP0			; ????? ????? 1
			clrf	TRISB				; ? ????????? ??? ????? ????? ?? ????? 
			bcf		STATUS,RP0			; ????? ????? 0

			movlw	.255				;
			movwf	b_zad_ind			;
			call	ind_zad				;
			movlw	DIND				; ????????????? ???????????? ??????????
			movwf	avtovyh				; 
		goto	end_kl_call				; 
;====================================
end_klava								;
			bcf		kl_no				; ???????? ??? ??????? ???????			
			movlw	SPUAN				; ????????????? ???????????? ????????
			movwf	uskor_1				; 
			movwf	uskor				;
		goto	end_kl_call				; 
;====================================
vyh		;	??????? ???????
			btfss	UST					;
		goto	end_vyh3				; 
			btfsc	vp_rp				; ????????? ??????? ????????? ? ?????? ?????? ???????
		goto	end_vyh1				; 
			;btfsc	TRB4 ;Chenzee					; ???? ????????? PB3+PB1		
			btfsc	TRB3 ;Chenzee
		goto	end_vyh1				; 
			btfsc	TRB1					; 
		goto	end_vyh1				; 			
			;==============				; ?????????????? ????? ?? ?????? ?????????
			clrf	avtovyh				; 
			call	resautoexit
			;==============				;
		goto	end_vyh3				; 
;====================================
end_vyh1
			movlw	.5					; 
			subwf	uskor_1,w			; ???????? ?????????? ?????????? ???????? 1
			BZ		end_vyh2			;	
			decfsz	uskor,f				; 
		goto	end_vyh3				; 
			decf	uskor_1,f			; 
			movfw	uskor_1				; 
			movwf	uskor				; 
end_vyh2								;			
			bcf		kl_no				;				
end_vyh3								;	
end_kl_call	
			bsf		f_RB1				;
			bsf		f_RB2				;
			bsf		f_RB3				;
			bsf		f_RB4				;
						
			bsf		STATUS,RP0			; ????? ????? 1
			clrf	TRISB				; ? ????????? ??? ????? ????? ?? ????? 
			bcf		STATUS,RP0			; ????? ????? 0
	return								;
;============================================================================================
resautoexit
			btfsc	Ind_MIN
		goto	res_init0	
			btfsc	Ind_MAX			
		goto	res_init0
			call	zap_eeprom			; ???????? ? ?????? ????????? ?????????
			
			bcf		UST					; ??? ?????? ????????? ??????????
			clrf	flag_2				; ???????? ???? ?????? ?????????			
			bcf		vp_rp				; ??? ?????? 0-????? ?????????		
			bcf		LE_RI				; ????????? ????? ???????????
res_init	movfw	Vr_zak_hi			;
			movwf	Vr_cak_hi			; 
			movfw	Vr_zak_lo			;
			movwf	Vr_cak_lo			; 
			movfw	Vr_pov_hi			;
			movwf	Vr_cpo_hi			; 
			movfw	Vr_pov_lo			;
			movwf	Vr_cpo_lo			;
			bcf		zad_op				;			
			bcf		BRACON				; 
res_init0			
			bcf		Ind_MIN				; 
			bcf		Ind_MAX				; 
	return								; 
;============================================================================================
zaderj				; ????? ???????????? ????????
			movlw	.250					; .200
			movwf	TEMP0				; 
			decfsz	TEMP0,f				; 
			goto	$-1					; 		
		return							; 		
;============================================================================================
;============================================================================================						
; ????? ??????? ????????? ??????????
vyb_fun
;====================================
			bsf		STATUS,RP0		; ????? ????? 1
			clrf	TRISB			; ? ????????? ??? ????? ????? ?? ????? 
			bcf		STATUS,RP0		; ????? ????? 0
			
			bsf		kl_no			; ??? ??????? ??????
			bsf		UST				; 
			
			clrf	flag_i1			; ????? ???? ????????? 	
			
			bcf		Ind_MIN			; 
			bcf		Ind_MAX			; 
			
			movlw	DIND			; ????????????? ???????????? ??????????
			movwf	avtovyh			; 
;====================================
			btfss	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	pr_pr				; ???? ?????????? ??? ????????			
			btfsc	REGRA			; ????? ?????? ?????????? 1-??????? 0-???????? (????????? ????????) 
		goto	REGRA_f				; 
			btfsc	TMZAD			; ??????? ???????? ???????? ?????????????
		goto	TMZAD_f				; 
			btfsc	GIZAD			; ??????? ???? ??????????????????
		goto	GIZAD_f				; 
			btfsc	HIALR			; ??????? ??????? ?????????? ???????? ????????  
		goto	HIALR_f				; 			
			btfsc	LOALR			; ??????? ?????????????
		goto	LOALR_f				; 
			btfsc	VRZDR			; 
		goto	VRZDR_f				; 
			btfsc	VRPZK			; 
		goto	VRPZK_f				; 			
			btfsc	PROIZ			; ????????? ???????? ????????????
		goto	PROIZ_f				; 			
		goto	REGRA_f				; 						
;=================================
pr_pr								; 		
			btfsc	LE_RI			;
		goto	prev				; 	 
			btfsc	REGRA			; ??????????? ????????????? ??????
		goto	TMZAD_f				; 
			btfsc	TMZAD			; 
		goto	GIZAD_f				; 
			btfsc	GIZAD			; 
		goto	HIALR_f				; 
			btfsc	HIALR			; 
		goto	LOALR_f				; 
			btfsc	LOALR			; 
		goto	VRZDR_f				; 
			btfsc	VRZDR			; 
		goto	VRPZK_f				; 
			btfsc	VRPZK			; 
		goto	PROIZ_f				; 			
		goto	REGRA_f				; ????????? ??????????? ???????
;=================================
prev		btfsc	REGRA			; ??????????? ????????????? ??????
		goto	PROIZ_f				; 
			btfsc	PROIZ			; 
		goto	VRPZK_f				; 
			btfsc	VRPZK			; 
		goto	VRZDR_f				; 
			btfsc	VRZDR			; 
		goto	LOALR_f				; 
			btfsc	LOALR			; 
		goto	HIALR_f				; 
			btfsc	HIALR			; 
		goto	GIZAD_f				; 
			btfsc	GIZAD			; 
		goto	TMZAD_f				; 			
		goto	REGRA_f				; ????????? ??????????? ???????
;===============================================
	; ?????? ? ????????????
PROIZ_f		movlw	b'10000000'		; 
			movwf	flag_2			; ????????? ??????? ????????? ?????? ???????????? (10-60)
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	PROIZ_d				; ???? ?????????? ??? ????????
			movlw	.69				; ???. ????????????
		goto	end_vybor_f			; 
PROIZ_d		movlw	.18				; ???. ????????????
			call	big_str			; ???????????? ??????? ??????
			movlw	.69				; ???. ????????????
			call	big_str			; ???????????? ??????? ??????	
	return							; 
;===============================================
;===============================================
		; ??? ??????? ?????????? ??????? ???????????
VRPZK_f		movlw	b'01000000'
			movwf	flag_2			; ????????? ??????????? ???????
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	VRPZK_d				; ???? ?????????? ??? ????????
			movlw	.81				;  Uco ---
		goto	end_vybor_f			; 
VRPZK_d		
			movfw	Vr_pov_hi		; 
			movwf	binh			; 
			movfw	Vr_pov_lo		; 
			movwf	binl			;  
		goto	frfr			 			
;===============================================
;===============================================
		;??? ??????? ????????? ?????? ????????????
VRZDR_f		movlw	b'00100000'
			movwf	flag_2			; ????????? ??????????? ???????
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	VRZDR_d				; ???? ?????????? ??? ????????
			movlw	.77				;  UAc ---
		goto	end_vybor_f			; 
VRZDR_d		
			movf	Vr_zak_hi,f		; 
			btfss	STATUS,Z		; 
		goto	infzn				; 
			movf	Vr_zak_lo,f		; 
			btfss	STATUS,Z		; 
		goto	infzn				; 
			movlw	c0				; ?????? O
			movwf	ind_1			;
			movlw	cF				; ?????? F
			movwf	ind_2			;			
			movlw	cF				; ?????? F
			movwf	ind_3			;
	return							; 
					
infzn		movfw	Vr_zak_hi		; 
			movwf	binh			; 
			movfw	Vr_zak_lo		; 
			movwf	binl			; 
frfr		bcf		TOCHKA2			;
			call    bin_dec			; 
			call	p_kl2			; 
	return							; 
;===============================================
;===============================================
		; ??? ????????? ??????? ?????? ???????????? ???????????
LOALR_f		movlw	b'00010000'
			movwf	flag_2			; ????????? ??????????? ???????
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	LOALR_d				; ???? ?????????? ??? ????????
			movlw	.65				; t__ ---
		goto	end_vybor_f			; 
LOALR_d		
			movfw	Dn_alr_hi		; 
			movwf	binh			; 
			movfw	Dn_alr_lo		; 
		goto	ind_tena			; 
;===============================================
	; ??? ????????? ??????? ?????? ???????????? ???????????	 
HIALR_f		movlw	b'00001000'		; 
			movwf	flag_2			; ????????? ??????????? ???????
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	HIALR_d				; ???? ?????????? ??? ????????
			movlw	.61				; t--
		goto	end_vybor_f			; 
HIALR_d		
			movfw	Up_alr_hi		; 
			movwf	binh			; 
			movfw	Up_alr_lo		; 
		goto	ind_tena			; 
;===============================================
	; bit zad?n? hystereze
GIZAD_f		movlw	b'00000100'		; 
			movwf	flag_2			; ????????? ??????????? ???????
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
		goto	GIZAD_d				; ???? ?????????? ??? ????????
			movlw	.57				; gic
		goto	end_vybor_f			; 
GIZAD_d		
			clrf	binh			; 
			movfw	Gi_zad_lo		; 
		goto	ind_tena			; 
;===============================================
		; ??? ??????? ??????????? ?????????????
TMZAD_f		movlw	b'00000010'		; 
			movwf	flag_2			; ????????? ??????????? ???????
			btfsc	vp_rp			; ???? ??????? ???????????? ????????? ?????????
			goto	TMZAD_d			; ???? ?????????? ??? ????????
			movlw	.53				; tuc
		goto	end_vybor_f			; 
TMZAD_d		
			movfw	Te_zad_hi		; 
			movwf	binh			; 
			movfw	Te_zad_lo		; 
ind_tena	movwf	binl			; 
			bsf		BTE				; 
			call    bin_dec			; 
			bsf		TOCHKA2			;
		goto	p_ind_r1			; 
;===============================================
		; ??? ?????? ?????? ?????? ??????????
REGRA_f		movlw	b'00000001'		; 
			movwf	flag_2			; ????????? ?????? ?????? ??????????
			btfsc	vp_rp			; ???? ??????? ???????????? ???????? ?????????
		goto	REGRA_d				; ???? ?????????? ??? ????????
			movlw	.73				; 		
		goto	end_vybor_f			; 
REGRA_d		btfss	INDK			; ????????? ???????????
		goto	i_NAGR				; 
			movlw	ci				; ?????? i 
			movwf	ind_1			;
			movlw	cn				; ?????? n
			movwf	ind_2			;			
			movlw	cd				; ?????? d
		goto	vin3				; 
i_NAGR		btfss	NAGR			; ????????? ??????????? 
		goto	i_HOLD
			movlw	ct				; ?????? T
			movwf	ind_1			;
			movlw	co				; ?????? o
			movwf	ind_2			;			
			movlw	cP				; ??????P
		goto	vin3				;  
i_HOLD		btfss	HOLD			; ????????? ??????????
		goto	i_RUCH
			movlw	cC				; ?????? C
			movwf	ind_1			;
			movlw	cH				; ?????? H
			movwf	ind_2			;			
			movlw	cL				; ?????? L
		goto	vin3				;  
i_RUCH								; ?????? ????? ??????
			movlw	cr				; ?????? r
			movwf	ind_1			;
			movlw	cu				; ?????? u
			movwf	ind_2			;			
			movlw	cc				; ?????? c
vin3		movwf	ind_3			;
	return							; 
;===============================================
; ????? ????????? ?????? ????????? ???????
;===============================================
end_vybor_f							; 
			btfsc	LE_RI			; 
		goto	$+3
			call	big_str			; ???????????? ??????? ??????
	return							;   
			call	big_str_re		; ???????????? ??????? ??????
	return							;  
end_vybor1							; 
			bsf		BTE				; 
			call    bin_dec			; 
			bsf		TOCHKA2			;
p_kl2								; 
			movfw	edin			; 
			movwf	ind_3			; 
			movfw	dest			; 
			movwf	ind_2			; 
			movfw	sotn			; 
			movwf	ind_1			;
end_vybor							; 
	return							; 
;============================================================================================
;============================================================================================






;============================================================================================
; ????????? ????????? ????????? ???????
ustanov	
;====================================
			bsf		STATUS,RP0		; ????? ????? 1
			clrf	TRISB				; ? ????????? ??? ????? ????? ?? ????? 
			bcf		STATUS,RP0		; ????? ????? 0
						
			bsf		kl_no			; ??? ??????? ??????
	
			movlw	DIND			; ????????????? ???????? ???????
			movwf	avtovyh			; ?????????? ?? ?????????

			btfsc	REGRA			; ????? ?????? ?????? ??????????
			goto	u_REGRA			;
						
			btfsc	TMZAD			; ??????? ??????????? ?????????????
			goto	u_TMZAD			; 
			
			btfsc	GIZAD			; ??????? ???????????
			goto	u_GIZAD			; 
			
			btfsc	HIALR			; ????????? ??????? ?????? ????????????? ???????????
			goto	u_HIALR			; 

			btfsc	LOALR			; ????????? ??????? ?????? ????????????? ???????????
			goto	u_LOALR			; 
			
			btfsc	VRZDR			; ??????? ????????? ?????? ????????????
			goto	u_VRZDR			; 
			
			btfsc	VRPZK			; ????? ?????????? ??????? ???????????
			goto	u_VRPZK			; 
	return		
 
;====================================
;????? ?????? ?????? ??????????	
u_REGRA				
			btfsc	f_RB3			; 
		goto	kk_REGRA			;
			btfss	INDK			;
		goto	$+.4				;
			bcf		INDK			;
			bsf		NAGR			;
	goto	REGRA_d					;
			btfss	NAGR			;
		goto	$+.4				;
			bcf		NAGR			;
			bsf		HOLD			;
	goto	REGRA_d					;				
			btfss	HOLD			;
		goto	$+.4				;
			bcf		HOLD			;
			bsf		RUCH			;
	goto	REGRA_d					;
			btfss	RUCH			;
		goto	$+.4				;
			bcf		RUCH			;
			bsf		INDK			;
	goto	REGRA_d					;

kk_REGRA	btfsc	f_RB2			; 
	goto	REGRA_d					;	
			btfss	INDK			;
		goto	$+.4				;
			bcf		INDK			;
			bsf		RUCH			;
	goto	REGRA_d					;
			btfss	NAGR			;
		goto	$+.4				;
			bcf		NAGR			;
			bsf		INDK			;
	goto	REGRA_d					;				
			btfss	HOLD			;
		goto	$+.4				;
			bcf		HOLD			;
			bsf		NAGR			;
	goto	REGRA_d					;
			btfss	RUCH			;
		goto	$+.4				;
			bcf		RUCH			;
			bsf		HOLD			;
	goto	REGRA_d					;		
;====================================
; ??????? ??????????? ?????????????
u_TMZAD
			btfsc	f_RB2			; + ??????????
		goto	kk_TMZAD			;
			movfw	Up_alr_hi		; tavr veh
			movwf	peAsh			;
			movfw	Up_alr_lo		;
			movwf	peAsl			;
			movfw	Gi_zad_lo		;
			subwf	peAsl,w			;
			btfss	STATUS,C		;
			decf	peAsh,f			;
			movlw	.10				;
			subwf	peAsl			;
			btfss	STATUS,C		;
			decf	peAsh,f			;			
			
			movf	Te_zad_hi,w		;
			movwf	peBsh			;
			movf	Te_zad_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	BOL				;
		goto	kk_TMZAD			;
			btfsc	TOCHKA3			; ???????????? ?????? ? ??????????? ?? ???? ?????????
		goto	umde_TMZAD			;			
			movlw	.1				;
			addwf	Te_zad_lo,f		;
			btfsc	STATUS,C		;
			incf	Te_zad_hi,f		;
		goto	end_TMZAD			; 
umde_TMZAD	movlw	.10				;
			addwf	Te_zad_lo,f		;
			btfsc	STATUS,C		;
			incf	Te_zad_hi,f		;
		goto	end_TMZAD			; 
kk_TMZAD							; 
			btfsc	f_RB3			; - ??????????
	goto	end_TMZAD				; 
			movfw	Dn_alr_hi		; tavr niz
			movwf	peAsh			;		
			movfw	Dn_alr_lo		;
			movwf	peAsl			;
			movfw	Gi_zad_lo		;
			addwf	peAsl,f			;
			btfsc	STATUS,C		;
			incf	peAsh,f			;
			movlw	.10				;
			addwf	peAsl,f			;
			btfsc	STATUS,C		;
			incf	peAsh,f			;
			
			movf	Te_zad_hi,w		;
			movwf	peBsh			;
			movf	Te_zad_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	MEN				;
	goto	end_TMZAD				; 
			btfsc	TOCHKA3			; ???????????? ?????? ? ??????????? ?? ???? ?????????
		goto	uvde_TMZAD			;
			movlw	.1				;
			subwf	Te_zad_lo,f		;
			btfss	STATUS,C		;
			decf	Te_zad_hi,f		;
	goto	end_TMZAD				; 
uvde_TMZAD	movlw	.10				;
			subwf	Te_zad_lo,f		;
			btfss	STATUS,C		;
			decf	Te_zad_hi,f		;
end_TMZAD							;
	goto	TMZAD_d					;
;====================================
; ZAD?V?N? HYSTEREZE (0 - 5.0)
u_GIZAD
			btfsc	f_RB2			; + ZVY?OV?N??
		goto	kk_GIZAD			;


			movfw	Te_zad_hi		; tavr veh 
			movwf	peAsh			;
			movfw	Te_zad_lo		;
			movwf	peAsl			;
			movfw	Dn_alr_lo		;
			subwf	peAsl,f			;
			btfss	STATUS,C		;
			decf	peAsh,f			;
			movfw	Dn_alr_hi		;
			subwf	peAsh,f			;
			movlw	.10				; zm?na z .10
			subwf	peAsl,f			;
			btfss	STATUS,C		;
			decf	peAsh,f			;

			movfw	Up_alr_hi		; tavr veh
			movwf	peBsh			;
			movfw	Up_alr_lo		;
			movwf	peBsl			;
			movfw	Te_zad_lo		;
			subwf	peBsl,f			;
			btfss	STATUS,C		;
			decf	peBsh,f			;
			movfw	Te_zad_hi		;
			subwf	peBsh,f			;
			movlw	.10				; zm?na z .10
			subwf	peBsl,f			;
			btfss	STATUS,C		;
			decf	peBsh,f			;

			call	sravnenie		;
			btfsc	MEN_RAV			;
		goto	$+.5
			movfw	peBsh			;
			movwf	peAsh			;			
			movfw	peBsl			;
			movwf	peAsl			;
			
			clrf	peBsh			;
			movlw	0xC8			; +10.0 =  0x64,+15.0=96
			movwf	peBsl			;
			
			call	sravnenie		;
			btfsc	MEN_RAV			;
		goto	igis
			clrf	peAsh			;
			movlw	0xC8			; +10.0  0x64,0x01
			movwf	peAsl			;
			
igis		clrf	peBsh			;			
			movf	Gi_zad_lo,w		;
			movwf	peBsl			;

			call	sravnenie		;
			btfss	BOL				;
		goto	kk_GIZAD			;
			movlw	.1				;
			addwf	Gi_zad_lo,f		;
		goto	end_GIZAD			; 
kk_GIZAD							; 
			btfsc	f_RB3			; - SNI?OV?N?
	goto	end_GIZAD				; 
			clrf	peAsh			;		
			clrf	peAsl			;
			clrf	peBsh			;
			movf	Gi_zad_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	MEN				;
	goto	end_GIZAD				; 
			movlw	.1				;
			subwf	Gi_zad_lo,f		;
end_GIZAD							;
	goto	GIZAD_d					;
;=========================================
;=========================================
; program kontroly horn? ?rovn? teploty
u_HIALR
			btfsc	f_RB2			; + ??????????
		goto	kk_HIALR			;
			movlw	0x04			; +120,0
			movwf	peAsh			;
			movlw	0xb0			;
			movwf	peAsl			;
			
			movf	Up_alr_hi,w		;
			movwf	peBsh			;
			movf	Up_alr_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	BOL				;
		goto	kk_HIALR			;
			btfsc	TOCHKA3			; ???????????? ?????? ? ??????????? ?? ???? ?????????
		goto	umde_HIALR			;			
			movlw	.1				;
			addwf	Up_alr_lo,f		;
			btfsc	STATUS,C		;
			incf	Up_alr_hi,f		;
		goto	end_HIALR			; 
umde_HIALR	movlw	.10				;
			addwf	Up_alr_lo,f		;
			btfsc	STATUS,C		;
			incf	Up_alr_hi,f		;
		goto	end_HIALR			; 
kk_HIALR							; 
			btfsc	f_RB3			; - ??????????
	goto	end_HIALR				; 
			movfw	Te_zad_hi		; ?????? ???? ?? ???? ????+????+1,0
			movwf	peAsh			;		
			movfw	Te_zad_lo		;
			movwf	peAsl			;
			movfw	Gi_zad_lo		;
			addwf	peAsl,f			;
			btfsc	STATUS,C		;
			incf	peAsh			;
			movlw	.10				; + 1 ???
			addwf	peAsl,f			;
			btfsc	STATUS,C		;
			incf	peAsh,f			;
			
			movf	Up_alr_hi,w		;
			movwf	peBsh			;
			movf	Up_alr_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	MEN				;
	goto	end_HIALR				; 
			btfsc	TOCHKA3			; ???????????? ?????? ? ??????????? ?? ???? ?????????
		goto	uvde_HIALR			;
			movlw	.1				;
			subwf	Up_alr_lo,f		;
			btfss	STATUS,C		;
			decf	Up_alr_hi,f		;
	goto	end_HIALR				; 
uvde_HIALR	movlw	.10				;
			subwf	Up_alr_lo,f		;
			btfss	STATUS,C		;
			decf	Up_alr_hi,f		;
end_HIALR							;
	goto	HIALR_d					;
;=========================================
;=========================================
;kontrola spodn? ?rovn? teploty 
u_LOALR
			btfsc	f_RB2			; + ??????????
		goto	kk_LOALR			;
			movfw	Te_zad_hi		; ??????????? ?? ??????? ????????????? ????????
			movwf	peAsh			; ?????? ???? ?? ???? ????-????-1,0
			movfw	Te_zad_lo		; ??????? ?????? ???????????
			movwf	peAsl			;
			movfw	Gi_zad_lo		; ?????? ??????????
			subwf	peAsl,f			;
			btfss	STATUS,C		;
			decf	peAsh,f			;
			
			movlw	.10				; ?????? 1 ???
			subwf	peAsl,f			;
			btfss	STATUS,C		;
			decf	peAsh,f			;
			
			movf	Dn_alr_hi,w		;
			movwf	peBsh			;
			movf	Dn_alr_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	BOL				;
		goto	kk_LOALR			;
			btfsc	TOCHKA3			; ???????????? ?????? ? ??????????? ?? ???? ?????????
		goto	umde_LOALR			;			
			movlw	.1				;
			addwf	Dn_alr_lo,f		;
			btfsc	STATUS,C		;
			incf	Dn_alr_hi,f		;
		goto	end_LOALR			; 
umde_LOALR	movlw	.10			;
			addwf	Dn_alr_lo,f		;
			btfsc	STATUS,C		;
			incf	Dn_alr_hi,f		;
		goto	end_LOALR			; 
kk_LOALR							; 
			btfsc	f_RB3			; - ??????????
	goto	end_LOALR				; 
			movlw	0xfe			; -40,0
			movwf	peAsh			;		
			movlw	0x70			;
			movwf	peAsl			;
			movf	Dn_alr_hi,w		;
			movwf	peBsh			;
			movf	Dn_alr_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	MEN				;
	goto	end_LOALR				; 
			btfsc	TOCHKA3			; ???????????? ?????? ? ??????????? ?? ???? ?????????
		goto	uvde_LOALR			;
			movlw	.1				;
			subwf	Dn_alr_lo,f		;
			btfss	STATUS,C		;
			decf	Dn_alr_hi,f		;
	goto	end_LOALR				; 
uvde_LOALR	movlw	.10				;
			subwf	Dn_alr_lo,f		;
			btfss	STATUS,C		;
			decf	Dn_alr_hi,f		;
end_LOALR							;
	goto	LOALR_d					;
;=========================================
;=========================================
u_VRZDR	; ??? ??????? ????????? ?????? ????????????
			btfsc	f_RB2			; + ??????????
		goto	kk_VRZDR			;
			movlw	0x03			; 900 cer
			movwf	peAsh			;
			movlw	0x84			;
			movwf	peAsl			;
			
			movf	Vr_zak_hi,w		;
			movwf	peBsh			;
			movf	Vr_zak_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	BOL				;
		goto	kk_VRZDR			;
			movlw	.1				;
			addwf	Vr_zak_lo,f		;
			btfsc	STATUS,C		;
			incf	Vr_zak_hi,f		;
		goto	end_VRZDR			; 
kk_VRZDR							; 
			btfsc	f_RB3			; - ??????????
	goto	end_VRZDR				; 
			clrf	peAsh			; 0 cek	- OFF	
			clrf	peAsl			;

			movf	Vr_zak_hi,w		;
			movwf	peBsh			;
			movf	Vr_zak_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	MEN				;
	goto	end_VRZDR				; 
			movlw	.1				;
			subwf	Vr_zak_lo,f		;
			btfss	STATUS,C		;
			decf	Vr_zak_hi,f		;
end_VRZDR							;
	goto	VRZDR_d					;
;=========================================
;=========================================
u_VRPZK	; ?as zadr?en? op?tovn?ho sepnut? kompresoru
			btfsc	f_RB2			; + ??????????
		goto	kk_VRPZK			;
			movlw	0x03			; 900 cer
			movwf	peAsh			;
			movlw	0x84			;
			movwf	peAsl			;
			
			movf	Vr_pov_hi,w		;
			movwf	peBsh			;
			movf	Vr_pov_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	BOL				;
		goto	kk_VRPZK			;
			movlw	.1				;
			addwf	Vr_pov_lo,f		;
			btfsc	STATUS,C		;
			incf	Vr_pov_hi,f		;
		goto	end_VRPZK			; 

kk_VRPZK							; 
			btfsc	f_RB3			; - ??????????
	goto	end_VRPZK				; 
			clrf	peAsh			; 0 cek		
			clrf	peAsl			;
	
			movf	Vr_pov_hi,w		;
			movwf	peBsh			;
			movf	Vr_pov_lo,w		;
			movwf	peBsl			;
			call	sravnenie		;
			btfss	MEN				;
	goto	end_VRPZK				; 
			movlw	.1				;
			subwf	Vr_pov_lo,f		;
			btfss	STATUS,C		;
			decf	Vr_pov_hi,f		;
end_VRPZK							;
	goto	VRPZK_d					;
;=========================================
;=========================================











;*************************************************************************************************
big_str								; ???????????? ??????? ??????
			movwf	perem2			; 		
			clrf	flag_i1			; ????? ???? ????????? 	
			call 	och_left		; ??????? ??????????
			movfw	perem2			; ?????? ?????? ??????
			movwf	schet_sim2		; 
			call 	text_1			; ??????????? ??????
			movwf 	schet_sim1		; ?????? ?????????? ???????? ?????? ? ???????
infch		incf	schet_sim2,f	; ?????????? ???????? ?????? ???????
			decfsz	schet_sim1,f	; ?????????? ????. ?????? ?? 1 ? ???????? ?? 0
			goto	pr				; ?????? ???????
	return
pr			clrwdt					; ????? ??????????? ???????++++++
			movfw	ind_2			; ?????? 2 ?? ? 1 ??
			movwf	ind_1			; ???????? ? ??????????
			movfw	ind_3			; ?????? 3 ?? ? 2 ??
			movwf	ind_2			; ???????? ? ??????????
			movfw	schet_sim2		; ????? ???????? ? ???????????
			call 	text_1			; ????? ???????? ???????
			movwf	ind_3			; ???????? ? ??????????
			clrwdt					; ????? ??????????? ???????++++++
			movf	b_zad_ind,f		;	
			BNZ		$-3				;
			movlw	.65				;
			movwf	b_zad_ind		;
			goto	infch			; ?????? ???????
;*************************************************************************************************
big_str_re							; ???????????? ??????? ?????? ? ???? ?? ?????
			movwf	perem2			; 		
			clrf	flag_i1			; ????? ???? ????????? 	
			call 	och_ring		; ??????? ??????????
			movfw	perem2			; ?????? ?????? ??????
			movwf	schet_sim2		; 
			call 	text_1			; ??????????? ??????
			movwf 	schet_sim1		; ?????? ?????????? ???????? ?????? ? ???????
			;movfw	perem2
			addwf	schet_sim2,f
infch_re	decf	schet_sim2,f	; ?????????? ???????? ?????? ???????
			decfsz	schet_sim1,f	; ?????????? ????. ?????? ?? 1 ? ???????? ?? 0
			goto	pr_re			; 	?????? ???????
			;call 	och_ring		; ??????? ??????????
	return
pr_re		clrwdt					; ????? ??????????? ???????++++++
			movfw	ind_2			; ?????? 2 ?? ? 1 ??
			movwf	ind_3			; ???????? ? ??????????
			movfw	ind_1			; ?????? 3 ?? ? 2 ??
			movwf	ind_2			; ???????? ? ??????????
			movfw	schet_sim2		; ????? ???????? ? ???????????
			call 	text_1			; ????? ???????? ???????
			movwf	ind_1			; ???????? ? ??????????
			clrwdt					; ????? ??????????? ???????++++++
			movf	b_zad_ind,f		;	
			BNZ		$-3				;
			movlw	.65				;
			movwf	b_zad_ind		;
			goto	infch_re		; 	?????? ???????
;*************************************************************************************************
			; ??????? ?????????? "<-"
och_left	movlw	.4				; ?????????? ????????? ?????????? +1
			movwf	schet_sim2		; ???????? ???????? ??????
dec_left	decfsz	schet_sim2,f	; ?????????? ????. ?????? ?? 1 ? ???????? ?? 0
			goto	$+.2			; 	?????? ???????
		return						; 	????? ???????
			clrwdt					; ????? ??????????? ???????++++++
			movfw	ind_2			; ?????? 2 ?? ? 1 ??
			movwf	ind_1			; ???????? ? ??????????
			movfw	ind_3			; ?????? 3 ?? ? 2 ??
			movwf	ind_2			; ???????? ? ??????????
			clrf	ind_3			; ???????? 3 ??????????
			clrwdt					; ????? ??????????? ???????++++++
			movf	b_zad_ind,f		;	
			BNZ		$-3				;
			movlw	.65				;
			movwf	b_zad_ind		;
			goto	dec_left		; 	?????? ???????
;*************************************************************************************************
			; ??????? ?????????? "->"
och_ring	movlw	.4				; ?????????? ????????? ?????????? +1
			movwf	schet_sim2		; ???????? ???????? ??????
dec_ring	decfsz	schet_sim2,f	; ?????????? ????. ?????? ?? 1 ? ???????? ?? 0
			goto	$+.2			; 	?????? ???????
		return						; 	????? ???????
			clrwdt					; ????? ??????????? ???????++++++
			movfw	ind_2			; ?????? 2 ?? ? 1 ??
			movwf	ind_3			; ???????? ? ??????????
			movfw	ind_1			; ?????? 3 ?? ? 2 ??
			movwf	ind_2			; ???????? ? ??????????
			clrf	ind_1			; ???????? 3 ??????????
			clrwdt					; ????? ??????????? ???????++++++
			movf	b_zad_ind,f		;	
			BNZ		$-3				;
			movlw	.65				;
			movwf	b_zad_ind		;
			goto	dec_ring		; 	?????? ???????
;*************************************************************************************************
;==================INDIKACE?=================================================================
;nastaven? port? vstup/v?stup procesoru	
;============================================================================================
indic								; ????????? ????????? ??????????
;=============================================	
			btfsc	TOCHKA1			; ???????? ?????????? ?????
			bsf		ind_1,0			; 
			btfsc	TOCHKA2			; 
			bsf		ind_2,0			; 
			btfsc	TOCHKA3			; 
			bsf		ind_3,0			; 
;=============================================	
;=============================================	
i1ry		btfss	reg_ind,0		; 
		goto	i2ry				; 
			movfw	ind_1			; ????? ???? ????????? ??????? ?????????? (??????)
			movwf	r_PORTB			; ???????? ????? ?
			btfss	RAZR1			; 
			goto	ir1t			; ????????? ??????? ?????????
;=========================			; 
			btfss	B_MIG			; ???????
			goto	ir1t			; ???? ??? 0 ?????????? ?????
			movlw	b'00000001'		; 
			andwf	r_PORTB,f		; ???? ??? 1 ?????????? ????????
			goto	ir1t			; 
;=========================			; 	
ir1t		btfss	TOCHm1			; 
			goto	ir1				; ????? ?? ??????
;=========================			; 
			btfss	B_MIG			; ??????? ?????
			bcf		r_PORTB,0		; ???? ??? 0 ????? ?????
;=========================			; 
ir1			call	indiprot		; 
			clrf	reg_ind			; 
			bsf		reg_ind,1		; 
	return							; 
;=============================================	
;=============================================		
i2ry		btfss	reg_ind,1		; 
		goto	i3ry				; 
			movfw	ind_2			; ????? ???? ????????? ??????? ??????????? (????????)
			movwf	r_PORTB			; ???????? ????? ?
			btfss	RAZR2			; 
			goto	ir2t			; ????????? ??????? ?????????
;=============================================		
			btfss	B_MIG			; ???????
			goto	ir2t			; ???? ??? 0 ?????????? ?????
			movlw	b'00000001'		; 
			andwf	r_PORTB,f		; ???? ??? 1 ?????????? ????????
			goto	ir2t			; 
;=========================			; 		
ir2t		btfss	TOCHm2			; 
			goto	ir2				; ????? ?? ??????
;=========================			; 
			btfss	B_MIG			; ??????? ?????
			bcf		r_PORTB,0		; ???? ??? 0 ????? ?????
;=========================			; 
ir2			call	indiprot		; 
			clrf	reg_ind			; 
			bsf		reg_ind,2		; 
	return							; 
;=============================================	
;=============================================	
i3ry								; 
			movfw	ind_3			; ????? ???? ????????? ???????? ??????????? (???????)
			movwf	r_PORTB			; ???????? ????? ?
			btfss	RAZR3			; 
			goto	ir3t			; ????????? ??????? ?????????
;=============================================		
			btfss	B_MIG			; ???????
			goto	ir3t			; ???? ??? 0 ?????????? ?????
			movlw	b'00000001'		; 
			andwf	r_PORTB,f		; ???? ??? 1 ?????????? ????????
			goto	ir3t			; 
;=========================			; 		
ir3t		btfss	TOCHm3			; 
			goto	ir3				; ????? ?? ??????
;=========================			; 
			btfss	B_MIG			; ??????? ?????
			bcf		r_PORTB,0		; ???? ??? 0 ????? ?????
;=========================			; 
ir3			call	indiprot		;
			clrf	reg_ind			;
			bsf		reg_ind,0		;
	return							; 
;=============================================	
;=============================================	
indiprot	; ?????????? ??????? ????? ?????? 				
			; ?????????? ????????? c ?????????? ????????? ?????? ?????????? (????)			
			movfw	PORTB			; ???????? 
			movwf	d_PORTB			; 
			movfw	PORTA			; 
			movwf	d_PORTA			; 
;====================================
			movlw	CL_PA			; ??????? ????? A (c ?????? RA4/3 ?????? ?? ????)  
			andwf	d_PORTA,f		;			
			movlw	SE_PA			; ????????? ????? ???????? ????????? ? off
			iorwf	d_PORTA,f		; 

			movlw	CL_PB			; ??????? ????? A (c ?????? RA4 ?????? ?? ????)  
			andwf	d_PORTB,f		;			
			movlw	SE_PB			; ????????? ????? ???????? ????????? ? off
			iorwf	d_PORTB,f		; 
;====================================			
			movfw	d_PORTA			; ?????????? ?????????
			movwf	PORTA			; 
			movfw	d_PORTB			; 
			movwf	PORTB			;   
;====================================
			
			btfsc	r_PORTB,0		; ?????????? ???????
			bsf		S_H				; ? ????????? ??????
			btfsc	r_PORTB,1		;
			bsf		S_A				;			
			btfsc	r_PORTB,2		;
			bsf		S_B				;
			btfsc	r_PORTB,3		;
			bsf		S_C				;
			btfsc	r_PORTB,4		;
			bsf		S_D				;
			btfsc	r_PORTB,5		;
			bsf		S_E				;
			btfsc	r_PORTB,6		;
			bsf		S_F				;
			btfsc	r_PORTB,7		;
			bsf		S_G				;			

			btfsc	reg_ind,0		; ????? ????????? ???????
			bcf		SOT				; 
			btfsc	reg_ind,1		; 
			bcf		DES				; 
			btfsc	reg_ind,2		; 
			bcf		EDI				; 
;=====================================
			btfsc	RELE1			; ??????????? ???? ???????????
		goto	$+3					; 
			bcf		d_PORTA,0		; 
		goto	$+2					; 
			bsf		d_PORTA,0		; 			
;=====================================			
			btfsc	RELE2			; ?????????? ???? ??????
		goto	$+3					; 
			bcf		d_PORTA,4		; 
		goto	$+2					; 
			bsf		d_PORTA,4		; 			
;=====================================
			movfw	d_PORTA			; ???????? ??????
			movwf	PORTA			; 
			movfw	d_PORTB			; 
			movwf	PORTB			; 
	return							; 
;============================================================================================	
;******************** cyklus indikace *************************************************************
ind_zad								; ??????? ?????? ?????????
			clrwdt					; ????? ??????????? ???????++++++
			movf	b_zad_ind,f		;	
			BNZ		$-3				;
			movlw	.60				;
			movwf	b_zad_ind		;
		return						; 					; 
;*************************************************************************************************
;============================================================================================
;********************????????????? ??????*********************************************************
vost_data								; 
			movlw	(end_stek-flag_0)+1	; 
			movwf	chtteep				; 
			movlw	flag_0
			movwf	FSR				;  ???????? ?????? ????? ??????
			clrf	adr_e				; 			
povch			
			call	prov_eep			; ????????? ?????? ? EEPROM
			movwf	INDF				; ????????? ? ??? ? ????????? ?????????
			incf	FSR,f			
			incf	adr_e,f				; ????????? ????? EEPROM
			decfsz	chtteep,f				; ????????? ??????? ? ????????? ?? ????
			goto	povch				; ???????? ???? ?? ????
	return								; 
;********************
;=================================================================================================
prov_eep	call	rd_eeprom			; ??????? ??????
			movf	data_e,w
			movwf	perem1				; 
			incf	adr_e,f				; ????? ??? EEPROM
			call	rd_eeprom			; ??????? ?????? (?????)
			movf	data_e,w			;
			subwf	perem1,w			; ???????? ?? ????????? ?????? ? EEPROM
			btfss	STATUS,Z			; 
			goto	$+3					; 
			movf	data_e,w			; ?????? ?????
		return							; 
			btfss	STATUS,C			; 
			goto	$+3					; 
			movf	data_e,w			; 
			goto	$+2					; 
			movf	perem1,w			; 
			bsf		E_data				; ?????? ? EEPROM
		return							; 
;=================================================================================================
rd_eeprom	movfw	adr_e			; ????????? ???????? ?????? ??????
			bsf		STATUS,RP0		; ????? ????? 1
			movwf	EEADR			; ????????? ??????? ?????
			bsf		EECON1,RD		; ?????? ?????? ?  EEPROM
			movfw	EEDATA			; ????????? ??????
			bcf		STATUS,RP0		; ????? ????? 0
			movwf	data_e			; ????????? ? ??????????
	return
;=================================================================================================
zap_eeprom								; ?????? ? EEPROM
			movf	INTCON,w
			movwf	perem5				; ????????? ???????? ???????? INTCON			
			bcf		INTCON,GIE			; ????????? ??? ??????????			

			movlw	(end_stek-flag_0)+1	;	; ??? ?????? ???????????? ?????? ? ?????? Tzad_h1 ?? kol_oh_vv	
			movwf	chtteep				; 
			movlw	flag_0
			movwf	FSR					; ???????? ?????? ????? ??????
			clrf	adr_e				; 			

povch1		
			movf	INDF,w				; ????????? ? ??? ? ????????? ?????????
			call	zap_2byt_eeprom		;
			incf	FSR,f
			incf	adr_e,f				; ????????? ????? EEPROM
			decfsz	chtteep,f				; ????????? ??????? ? ????????? ?? ????
			goto	povch1				; ???????? ???? ?? ????
			
;				?????? ?????? ? EEPROM
stop_wr_e		
			bsf		STATUS,RP0		; ??????? ???? 1
			btfsc	EECON1,WR		; ???????? ????????? ?????????? ?????? ? EEPROM
			goto	$-1
			bcf		EECON1,WREN		; ????????? ??????			
			bcf		STATUS,RP0		; ??????? ???? 0

			
			movf	perem5,w
			movwf	INTCON				; ??????????? ???????? ???????? INTCON
	return								;
;********************************************************************************************
zap_2byt_eeprom							;
			movwf	data_e				;
			movwf	perem2				;
			call	wr_eeprom			;
			incf	adr_e,f				; ?????????? ?????? ? EEPROM 
			movf	perem2,w			;
			movwf	data_e				;
			call	wr_eeprom			;
	return								;
;********************************************************************************************				
;********************************************************************************************				
;				z?pis do  EEPROM
wr_eeprom		
			bsf		STATUS,RP0		; ????? ????? 1
			btfsc	EECON1,WR		; ???????? ????????? ?????????? ?????? ? EEPROM
		goto	$-1					; 
			bsf		EECON1,WREN		; ????????? ??????
			bcf		STATUS,RP0		; ????? ????? 0
			movfw	adr_e			; ????????? ?????
			bsf		STATUS,RP0		; ????? ????? 1
			movwf	EEADR			; ????????? ?????? 1
			bcf		STATUS,RP0		; ????? ????? 0
			movfw	data_e			; ? ????? ????????? ????????? ??? ??????????
			bsf		STATUS,RP0		; ????? ????? 1
			movwf	EEDATA			; ? EEPROM
			movlw	0x55			; ????????? ????? ?????? ? EEPROM
			movwf	EECON2			;
			movlw	0xAA			;
			movwf	EECON2			;
			bsf		EECON1,WR		; ?????? ??????
			bcf		STATUS,RP0		; ??????? ???? 0
	return
;********************************************************************************************
;********************************************************************************************

;********************************************************************************************
;============================================================================================
;============================================================================================
;***??????????? ?????????????? 24/16 ??????? ????????? ?? ?????? ? 7 ????? ??????? ??????????? ****************
; ???????? ????? ??? 24 ????  - - 8 388 607 ?? + 8 388 607
; ??? 16 ???  - - 32767 ?? + 32767
										; ??????? ?????? binl, binh, binu
										; ???????? edin,dest,sotn,tysc,dtys,stys,mlon
										; B24 0 ??????????????? 16 ???, 1- 24 (16 ?? ?????????)
										; BTE ??? ?????????????? ???? 00 ??? 0
										; BTE0_00	????????? "???????? ????" ??? ????? ???? - 0,00
bin_dec
;===============================================
	;			movfw	binu			; 
	;			movwf	t_binu			; 
				movfw	binh			; 
				movwf	t_binh			; 
				movfw	binl			; 
				movwf	t_binl			; 
;===============================================							
				bcf		MINUS			; ???????? ???? ????????????? ???????????
				btfsc	B24				; ???? ?????????? ???
			goto	bi0p				; 
				clrf	binu			; ???????? ??????? ???? ???? ????????? 16 ?????? ?????
				btfss	binh,7			; ????????? ??????????? ?????????????			
				goto	bi0				; ???
			goto	comfd				;
bi0p			btfss	binu,7			; ????????? ????? ?????????????
			goto	bi0					; ???
				comf	binu,f			; ?????????????? ?????????????? ????? ? ????????????? ??? ?????????	
comfd			bsf		MINUS			; ?? ?????????? ??? ????????????? ???????????
				comf	binl,f			; 
				comf	binh,f			; 
				movlw	.1				; 
				addwf	binl,f			; 
			BNC		bi0					; 
				addwf	binh,f			; 
			BNC		bi0					; 
				incf	binu,f			; 
;===============================================
bi0				bcf		B24				; ???????? ??? ????????? 24 ?????? ?????
	 			bcf     STATUS,0        ; clear the carry bit
				movlw   .24				; 
				movwf   count			; 
				clrf    R3				; 
				clrf    R2				; 
				clrf    R1				; 
				clrf    R0				; 
loop24  		rlf     binl, F			; 
				rlf     binh, F			; 
				rlf     binu, F			; 
				rlf     R0, F			; 
				rlf     R1, F			; 
				rlf     R2, F			; 
				rlf     R3, F			; 
				decfsz  count, F		; 
			goto    adjDEC				; 
;===============================================
				movfw	R3				; 
				andlw	b'00001111'		; 
				movwf	mlon			; 
				swapf	R2,w			; 
				andlw	b'00001111'		; 
				movwf	stys			; 
				movfw	R2				; 
				andlw	b'00001111'		; 
				movwf	dtys			; 
				swapf	R1,w			; 
				andlw	b'00001111'		; 
				movwf	tysc			; 
				movfw	R1				; 
				andlw	b'00001111'		; 
				movwf	sotn			; 
				swapf	R0,w			; 
				andlw	b'00001111'		; 
				movwf	dest			; 
				movfw	R0				; 
				andlw	b'00001111'		; 
				movwf	edin			; 
;===============================================
		; ????????? ??????? ?????????? ?????		
gnn				movlw	.10				; ??? ??????? ?????????? (?????)
				movf	mlon,f			; ????????? ?? ????
				BNZ		preo01			; ?????????? ???? ??????? ???? ????
				movwf	mlon			; ???????? ??? ?????? ??????????
				
				movf	stys,f			; ????????? ?? ????
				BNZ		preo01			; ?????????? ???? ??????? ???? ????
				movwf	stys			; ???????? ??? ?????? ??????????
				
				movf	dtys,f			; ????????? ?? ????
				BNZ		preo01			; ?????????? ???? ??????? ???? ????
				movwf	dtys			; ???????? ??? ?????? ??????????
				
				movf	tysc,f			; ????????? ?? ????
				BNZ		preo01			; ?????????? ???? ??????? ???? ????
				movwf	tysc			; ???????? ??? ?????? ??????????	
				
				movf	sotn,f			; ????????? ?? ????
				BNZ		preo01			
				btfss	BTE0_00			; ????????? ??? ????????? 0 ??? 00
			goto	tuns				; ??? ????????? 0
				bcf		BTE0_00			; ???????? ??? ???? ?????????
			goto	preo01				; ??? ????????? 00				
tuns			movwf	sotn			; ???????? ??? ?????? ??????????	
				movf	dest,f			; ????????? ?? ????
				BNZ		preo01			; 
				btfss	BTE				; ????????? ??? ????????? 0 ??? 00
			goto	tunn				; ??? ????????? 0
				bcf		BTE				; ???????? ??? ???? ?????????
			goto	preo01				; ??? ????????? 00				
tunn			movwf	dest			; ???????? ??? ?????? ??????????				
;===============================================
preo01		; ????????? ??????? ????? ????? ???? ????? ????????????
				btfss	MINUS			;
			goto 	concis				;
				movlw	.10				; ????????? ?? ??? ????? ? ????????
				subwf	dest,w			; ??????????
				btfss	STATUS,Z		;
				goto 	mt60			; 
				movlw	.11				;
				movwf	dest			; ??????????? ????? ? ????????
			goto 	concis				;
mt60			movlw	.10				; ????????? ?? ??? ????? ? ????????
				subwf	sotn,w			; ??????????
				btfss	STATUS,Z		;
				goto 	mt61			; 
				movlw	.11				;
				movwf	sotn			; ??????????? ????? ? ????????
			goto 	concis				;
mt61			movlw	.10				; ????????? ?? ??? ????? ? ????????
				subwf	tysc,w			; ??????????
				btfss	STATUS,Z		;
				goto 	mt62			; 
				movlw	.11				;
				movwf	tysc			; ??????????? ????? ? ????????
			goto 	concis				;
mt62			movlw	.10				; ????????? ?? ??? ????? ? ????????
				subwf	dtys,w			; ??????????
				btfss	STATUS,Z		;
				goto 	mt63			; 
				movlw	.11				;
				movwf	dtys			; ??????????? ????? ? ????????
			goto 	concis				;
mt63			movlw	.10				; ????????? ?? ??? ????? ? ????????
				subwf	stys,w			; ??????????
				btfss	STATUS,Z		;
				goto 	mt64			; 
				movlw	.11				;
				movwf	stys			; ??????????? ????? ? ????????
			goto 	concis				;
mt64			movlw	.11				;
				movwf	mlon			; ?????????? ????? ? ??????					
;===============================================
			; ????????????? ??? ????? ? ???? ??????????
concis			movf	mlon,w			; 
				call 	deshif			; 
				movwf	mlon			;
				movf	stys,w			; 
				call 	deshif			; 
				movwf	stys			;			
				movf	dtys,w			; 
				call 	deshif			; 
				movwf	dtys			;
				movf	tysc,w			; 
				call 	deshif			; 
				movwf	tysc			;
				movf	sotn,w			; 
				call 	deshif			; 
				movwf	sotn			;
				movf	dest,w			; 
				call 	deshif			; 
				movwf	dest			;
				movf	edin,w			; 
				call 	deshif			; 
				movwf	edin			;
;===============================================
	;			movfw	t_binu			; 
	;			movwf	binu			; 
				movfw	t_binh			; 
				movwf	binh			; 
				movfw	t_binl			; 
				movwf	binl			; 
;===============================================
		retlw   0			; ????? ????????? ??????????????
;===============================================
adjDEC 		 	movlw   R0				;
				movwf   FSR				;
				call    adjBCD			;
		 		movlw   R1				;
				movwf   FSR				;
				call    adjBCD			;
				movlw   R2				;
				movwf   FSR				;
				call    adjBCD			;
				movlw   R3				;
				movwf   FSR				;
				call    adjBCD			;
			goto    loop24				;
;===============================================
adjBCD 			movlw   3				;
				addwf   0,W				;
				movwf   temp			;
				btfsc   temp,3          ; test if result > 7
				movwf   0				;
				movlw   30				;
				addwf   0,W				;
				movwf   temp			;
				btfsc   temp,7          ; test if result > 7
				movwf   0    	        ; save as MSD
		RETLW   0						;
;============================================================================================


;============================================================================================
sravnenie								; 16 & 16 ?????? ?????
; ??????? peAsh,peAsl ? peBsh,peBsl
; ???????? ????? ????????? RAV,BOL,MEN,BOL_RAV,MEN_RAV

			clrf	flag_srv			; ??????? ?????? ?????????
			clrf	regsr				; ???????? ?????????? ??????????? ??????

sr16z		btfsc	peAsh,7				; ????????? 7 ??? ???? 0 ???????
			bsf		regsr,0				; ???? 1 ?????. ???????? 1 ? 0 ???.
			btfsc	peBsh,7				; ????????? 7 ??? ???? 0 ???????
			bsf		regsr,1				; ???? 1 ?????. ???????? 1 ? 1 ???.
										; 0 ??? ????? ?????????????
										; 1 ?????? ?????.
										; 2 ?????? ?????
										; 3 ??? ?????.
						; ?????????????? ??????? ?????????
						; ????????????? ?????? ??????????????
uzs			movf	regsr,f				;
			BZ		srv					; ??? ????? ??????? ??????? ?? ????????? ????? ?????
			movlw	.1					; 
			subwf	regsr,w				; ???? ????? 5 = 1, ?? peAsh ?????, ?????, ? peBsh ?????
			BNZ		$+4					;
			bsf		MEN					; ?????? peBsh>peAsh 
			bsf		MEN_RAV				;
		return							; 
			movlw	.2					; ???? ???? 5 = 2 ?? ?? peBsh ?????, ?????, ? peAsh ?????
			subwf	regsr,w				;
			BNZ		srv					; ??? ????? ???????????? ??????? ?? ????????? ??? ????? ?????
			bsf		BOL					; ?????? peBsh<peAsh  
			bsf		BOL_RAV				;
		return							; 
	;=================================== ????????? ????????????? ?????
srv										;
			movf	peAsh,w				; ????????? ????? ??????
			subwf	peBsh,w				;(?????????? ???? ?????)
			btfss	STATUS,Z
			goto	$+2					; ????? ?? ?????
			goto	prs					; ????? ????? ????????? ???? ????
			movf	peAsh,w				; 
			subwf	peBsh,w				; ?????????? ???? ??????
			btfsc	STATUS,C			;
			goto	$+4					;
			bsf		BOL					; peAsh>peBsh ????????? ???? ???????? ????
			bsf		BOL_RAV				;
		return							; 
			bsf		MEN					; peAsh<peBsh ????????? ???? ???????? ???? 			
			bsf		MEN_RAV				;
		return							;
prs			movf	peAsl,w				; ????????? ?????? ????
			subwf	peBsl,w				;(?????????? ???? ?????)
			btfss	STATUS,Z
			goto	$+.5				; ????? ?? ?????
			bsf		RAV					; peAsh=peBsh ? perem2=peBsh
			bsf		MEN_RAV				; 
			bsf		BOL_RAV				; 		
		return
			movf	peAsl,w				; 
			subwf	peBsl,w				; ?????????? ???? ??????
			btfsc	STATUS,C
			goto	$+4					;
			bsf		BOL					; peAsh=peBsh ? perem2>
			bsf		BOL_RAV
		return							; 
			bsf		MEN					; peAsh=peBsh ? perem2< 
			bsf		MEN_RAV				;
		return							;
;============================================================================================

;============================================================================================
kondosdata			; ???????? ????????????? ??????
;		;???????? ???????? ??????? ?????? ???????????
			movf	Te_zad_lo,w		;
			movwf	peAsl			; ????????? ?????? ?? ?????????? ??????	
			movf	Te_zad_hi,w		;
			movwf	peAsh			;			
			movlw	0xe2			;+ 125.0
			movwf	peBsl			; ???????? ??????
			movlw	0x04			; 
			movwf	peBsh			; ???????? ??????
			call    sravnenie		;
			btfsc	BOL				; ???? ?????? ??????
		goto	vos_data			;
;		;kontrola zony hystereze
			movf	Gi_zad_lo,w		;
			movwf	peAsl			; ????????? ?????? ?? ?????????? ??????	
			clrf	peAsh			;			
			movlw	0xC8			;+ 10.0
			movwf	peBsl			; ???????? ??????
			clrf	peBsh			; ???????? ??????
			call    sravnenie		;
			btfsc	BOL				; ???? ?????? ??????
		goto	vos_data			;
;		;???????? ???????? ??????? ????????? ???????
			movf	Up_alr_lo,w		;
			movwf	peAsl			; ????????? ?????? ?? ?????????? ??????	
			movf	Up_alr_hi,w		;
			movwf	peAsh			;			
			movlw	0xe2			;+ 125.0
			movwf	peBsl			; ???????? ??????
			movlw	0x04			; 
			movwf	peBsh			; ???????? ??????
			call    sravnenie		;
			btfsc	BOL				; ???? ?????? ??????
		goto	vos_data			;
;		;???????? ???????? ?????? ????????? ???????
			movf	Dn_alr_lo,w		;
			movwf	peAsl			; ????????? ?????? ?? ?????????? ??????	
			movf	Dn_alr_hi,w		;
			movwf	peAsh			;			
;			movlw	0xe2			;+ 125.0
;			movwf	peBsl			; ???????? ??????
;			movlw	0x04			; 
;			movwf	peBsh			; ???????? ??????
			call    sravnenie		;
			btfss	BOL				; ???? ?????? ??????
	return	
;====================================
vos_data	
			; ???????????? ?????? ? ?????????? ???? ? ?????????? ? EEPROM
			bsf		STATUS,RP0		; ??????? ???? 1
			clrf	TRISB			; ? ????????? ??? ????? ????? ?? ????? 
			bcf		STATUS,RP0		; ??????? ???? 0
						
			movlw	0x01			;		
			movwf	flag_0			; 
			movwf	Te_zad_hi			;* 	30,0 ?	
			movlw	0x2c				;
			movwf	Te_zad_lo			;*
			
			movlw	0x0a				;	 1,0 ?
			movwf	Gi_zad_lo			;*

			movlw	0x03				;		80,0 ?		
			movwf	Up_alr_hi			;* 
			movlw	0x20				;
			movwf	Up_alr_lo			;*

			movlw	0xff				;		
			movwf	Dn_alr_hi			;* -20,0 ?
			movlw	0x38				;
			movwf	Dn_alr_lo			;*
			
			clrf	Vr_zak_hi			;* 
			clrf	Vr_zak_lo			;*

			clrf	Vr_pov_hi			;* 
			movlw	0xb4				;
			movwf	Vr_pov_lo			;*
			
			call	zap_eeprom			; ???????? ? ?????? ????????? ????????? 
alr_d
			
			bcf		RELE1				; ????? ???? 
			bcf		RELE2				; ????? ???? 		
			clrf	flag_i1				; 
			
			movlw	.34					; 
			call	big_str				;??????? ?????? ?????? ??????
		goto	alr_d					; 
;============================================================================================
;============================================================================================
;============================================================================================
;DALLAS ???????????? (?????? ? ??????? ???????? 3 ????, Vdd, Vss, QD)
;============================================================================================
;============================================================================================
;============================================================================================
RESET_DALLAS				; ???????????? ???????? ?????? ? ???????????? ??????????? ???????
			call 	DOUT_LOW 			; ???????????? ??????? ?????? 480-960 mks
			
 			movlw	.152				; ????????? ??????? ??????
 			movwf	TEMP0				; 152-481 ??c
 			decfsz 	TEMP0,F				;
 			goto 	$-.1				;
			
			call 	DOUT_HIGH 			; ?????????? ??????? ???????

			clrf	TEMP0				; ???????? ???????? ?????? ?? ??????? ???????????
GT_1  		clrwdt						; ????? ??????????? ???????++++++
			decfsz	TEMP0,f				; 
			goto	kip_1				; 

neitdtt		bsf		ERROR_D				; ?????? ??????????
			bcf		CON					; ???????? ??? ???????????????, ??? ??????????? ??????????, ??? ??????????? ???????
		return							; 
kip_1		
			btfsc 	DALLAS 				; ??????? ??????? ???????????
			goto 	GT_1				;
			clrf	TEMP0				; 

GT_2  		clrwdt						; ????? ??????????? ???????++++++			
			decfsz	TEMP0,f				; 
			goto	kip_2				; 
			goto	neitdtt				; 
kip_2
			btfss 	DALLAS 				; ??????? ????????? ??????? ???????????
			goto 	GT_2				; 

end_fu
			bcf		ERROR_D				; ?????? ????????
 			movlw	.152					; 70-200
 			movwf	TEMP0				; 152-481
 			decfsz 	TEMP0,F				; 152-481
 			goto 	$-.1				;.152

		return							; 
;============================================================================================
;DOUT_HIGH: ??? ???????????? ????????????? ????? ???????? ??? ????, ???????????? ??????? ??????? ????,
;? ????? ????????? ????? ?? ?????, ??????? ???????? ?????????? ??????? ???????
DOUT_HIGH
			bsf		STATUS,RP0			; ??????? ???? 1
 			bsf		TRISDAL,LINE		; ????????? ???? ?? ???? (???????? ????????? ??????????)
			bcf		STATUS,RP0			; ??????? ???? 0
			nop							; ??????? ??? ??????? ????? ??? 
			nop							; ???????????? ???????? ??????????????
			nop							; 
			nop							; 
;			nop							; 
;			nop							; 
;			nop							; 
;			nop							;/ 
		retlw	.0						; 
;============================================================================================
; DOUT_LOW: ??? ???????????? ????????????? ????? ????????  ??  ????? ? ????????????? ?? ??? "0"
DOUT_LOW
 			bcf		DALLAS				; ?????????? ?????? ??????? ?? ????
			bsf		STATUS,RP0			; ??????? ???? 1
 			bcf		TRISDAL,LINE		; ????????? ???? ?? ?????
			bcf		STATUS,RP0			; ??????? ???? 0
			nop							; 
			nop							; 
		retlw	.0						; 
;============================================================================================

; DLIT_WR: ??? ???????????? ???????????? ? ???? ?????? ??????????? ?????
; ???????? 60 mks, ? ??????? ?????????? DS1820 ??? ?????? ??? ?????? ???? ??????.
; ?????????? ?? ?????????: 		DSEND	; 
; ???????????? ???????: 		TEMP0	; 
; ???????????? ????????????: 	???		; 
DLIT_WR									; 
			MOVLW 	.20					;.20 - 60mks
			MOVWF 	TEMP0				; 
	 		decfsz 	TEMP0,F				; 
 			goto 	$-.1				;
		retlw H'00'						; 
;============================================================================================
; DRECEIVE: ??? ???????????? ???????? ?????? ?? ??????????? ????.
DRECEIVE
			MOVLW 	H'08' 				; ?????????? ?????????? ???
			MOVWF 	TEMP1				; ???????? ???????? ????????
C_DRECEIVE	CALL 	DOUT_LOW 			; ????? ?????? ???? ?????????? ?????? ???????)
			CALL 	DOUT_HIGH 			; ?????? ??????
			btfss 	DALLAS 				; ????????? ??????? ?? ????? DALLAS1			
			bcf 	STATUS,C 			; ?????????? ? ? "0" 
			btfsc 	DALLAS 				; ????????? ??????? ?? ????? DALLAS1			
			bsf 	STATUS,C			; ??? ?????????? ? ? "1" 
			RRF 	COM_REG,F 			; ????? ?????? ??? ?????? ? ???????? COM_REG
			call 	DLIT_WR 			; ??????? ??? ????????? ???????????? ???????? ????
			decfsz 	TEMP1,F				; 
			goto 	C_DRECEIVE			; 
		retlw 	H'00'					; 
;============================================================================================
; DSEND: ??? ???????????? ???????? ??????? ? DS1820. ??????
; ?????????? ??????? ????? ??????? ??? ????????, ????????, ??? ????? ??????
; ?????????? ?? ?????????: 		GET_TEMPERATURE
; ???????????? ????????: 		COM_REG, GPIO, STATUS, TEMP1
; ???????????? ????????????: 	DOUT_HIGH, DOUT_LOW, DLIT_WR
DSEND
 			movwf 	COM_REG 			; ???????? ?????? ?????? ??? ?????????
 			movlw 	H'08' 				; ?????????? ????? ??? ?????????
 			movwf 	TEMP1				; 
C_DSEND		call 	DOUT_LOW 			; Start the write slot
 			RRF 	COM_REG,F 			; ????? ??????, ????? ?????????? ????? ??? ? ?????? ??? ??? ?????????
			btfss 	STATUS,C 			; ???????? ??? ? == 1 
 		goto 	SEND0					; 
 			call 	DOUT_HIGH 			; ?????????? ????? ? "1" ???? ??? ? == 1
 		goto 	DS_1					; 
SEND0 		call 	DOUT_LOW       	 	; ?????????? ????? ? "0", ???? ??? ? == 0
DS_1 		call 	DLIT_WR 			; ??????? 60uS, ????? ????????? DS1820 ????????? ???????
 			call 	DOUT_HIGH 			; ?????????? ???? ? "1"
 			decfsz 	TEMP1,F 			; ????????? ??????? ?????????? ????? ? ????????? ????????? ?? ????
 			goto 	C_DSEND				; ????????? ???????? ????
		retlw H'00'						; 
;============================================================================================
;============================================================================================
										; ?????? ??????????? ?? ??????????
celsio									; 
;========================================
; ????????? ???????????					; 
			CALL 	DOUT_LOW 			; ???? ?????? ??? ???????? 
			CALL 	DOUT_HIGH 			; ????????? ???????????????
			btfss	DALLAS 				; 
		return  						;
			btfsc	CON					; ???????? ??? ?????? ?????? 0 - ???? ??????????????
		goto	chtenie					; 1 - ??????????????? ????
			call	RESET_DALLAS		; 
			btfsc	ERROR_D				;
		return				; ?????? ?????????? ???????? ??????????????? ???????????
;========================================
			MOVLW 	H'CC' 				; ??????? ??????? ?????????? ROM
			CALL 	DSEND				;
			MOVLW 	H'44' 				; ??????? ??????? ?????????????? ???????????
			CALL 	DSEND				;
;========================================
			bsf		CON					; ???? ???????????????
		return							; 
;========================================
chtenie									; ?????? ???????????
			bcf		CON					; ??????????????? ?????????
;========================================
			call	RESET_DALLAS		; 
			btfsc	ERROR_D				;
		return							;
			MOVLW 	H'CC' 				; ??????? ??????? ?????????? ROM
			CALL 	DSEND				;
			MOVLW 	H'BE' 				; ??????? ??????? ?????? ??????
			CALL 	DSEND				;
			CALL 	DRECEIVE 			; ?????? 1 ????
			MOVF 	COM_REG,W			;
			MOVWF 	TEMP_LO				;
			CALL 	DRECEIVE 			; ?????? 2 ????
			MOVF 	COM_REG,W			;
			MOVWF 	TEMP_HI				;
;========================================
		; ?????????????? ?????? ??????? ? ???????????
		; ?????? ??????????? ???????? ????? ??? ?????, ??? ? ??? ??????? ?????????? ?????? ????? ?????????????? ??????? ???? ???????
			bcf		MINUS_d				; ???????? ???? ????????????? ???????????
			btfss	TEMP_HI,7			; ????????? ??????????? ?????????????
			goto	qwe					; ??? (?????????????? ???? ????? ???????)
			bsf		MINUS_d				; ?? ?????????? ??? ????????????? ???????????
qwe			movlw	b'00001111'			; ????????? ??????? ???????? ?????
			andwf	TEMP_LO,w			; ??????? ???????? ?????????
			btfss	MINUS_d				; 
			goto	konv				; 
			movwf	TEMP0				; 
			decf	TEMP0,f				; 
			comf	TEMP0,w				; 
			andlw	b'00001111'			; 
konv		call	con_dro				; ? ???????? ??????????? ? ??????? ????
			
			movwf	t_binl
			
			swapf	TEMP_HI,f			; ?????????????? ????? ?????
			movlw	b'11110000'			; ????????? ??????? ???????? ?????
			andwf	TEMP_HI,f			; ??????? ???????? ?????????
			movlw	b'11110000'			; ????????? ??????? ???????? ?????
			andwf	TEMP_LO,f			; ??????? ???????? ?????????
			swapf	TEMP_LO,w			; 
			iorwf	TEMP_HI,w			; 			
			
			movwf	t_binh				; 			
			
			btfss	MINUS_d				; 
		goto		vdt1				; 
			comf	t_binh,f			;
			incf 	t_binh,f			; 
vdt1			
			btfss	MINUS_d				; 
		goto		vdt6				; 
			movf	t_binl,f			; 
			BZ		vdt6				; 
			decf	t_binh,f			; 
vdt6		
			; ????????? ?? ??????
			movf	t_binh,w			;
			movwf	TEMP0				; ????????? ???????? binh

			clrf	t_binu
			bcf		STATUS,C			; 
			rlf		t_binh,f			; x2
			rlf		t_binu,f			;			
			rlf		t_binh,f			; x2
			rlf		t_binu,f			;
			rlf		t_binh,f			; x2 (8)
			rlf		t_binu,f			;
			
			movf	TEMP0,w				;+9
			addwf	t_binh,f			; 
			btfsc	STATUS,C			;			
			incf	t_binu,f			; 

			movf	TEMP0,w				;+10
			addwf	t_binh,f			; 
			btfsc	STATUS,C			;			
			incf	t_binu,f			; 
	;?o??? ????????? ????????? ?? 10			

			movf	t_binl,w			; 
			addwf	t_binh,f			; 
			btfsc	STATUS,C			; 		
			incf	t_binu,f			; 
			
			movf	t_binh,w			; 
			movwf	t_binl				; 
			movf	t_binu,w			; 
			movwf	t_binh				; 
			clrf	t_binu				; 
			
			btfss	MINUS_d				; 
		goto		vdt4				; 
		  	comf	t_binl,F   			; ?????????? bin
			incf    t_binl,F	     	;
			btfsc   STATUS,Z     		;
			decf    t_binh,F     		;
			comf    t_binh,F     		;
vdt4			
			movf	t_binl,w			; 
			movwf	T_izm_lo			; ????????? ? ?????????? ??????? ???????????
			movf	t_binh,w			; 
			movwf	T_izm_hi			; ????????? ? ?????????? ??????? ???????????
		return							;
;============================================================================================
;============================================================================================


;============================================================================================
;============================================================================================
conv_t								; ??????????????? ???????? ???????????
			bcf		oh_te			; ???????? ??? ?????? ???????????
			btfsc	ERROR_D			; ???????? ??????????? ??????? ???????????
		goto	Erro				; 
				; ???????? ?? ???????? ????????? -55 + 125 ? ???
			movf	binh,w			;????????? ???? ??? >125
			movwf	peAsh			;			
			movf	binl,w			;
			movwf	peAsl			;
			movlw	0x04			;
			movwf	peBsh			;
			movlw	0xE2			;
			movwf	peBsl			;
			call    sravnenie		;
			btfss	BOL				;
		goto	nam_55				;
			movlw	.40  			; 
			call	big_str			; ??????? ?????? - ??????
		goto	ochinoh
nam_55			
			movlw	0xfd			;????????? ???? ??? -55
			movwf	peBsh			;
			movlw	0xda			;
			movwf	peBsl			;
			call    sravnenie		;
			btfss	MEN				;
		goto	p_ind_r1			;
			movlw	.44  			; 
			call	big_str			; ??????? ?????? - ???????
ochinoh			
			call 	och_left		; ??????? ??????????
			bsf		oh_te			; ?????? ??????.
	return						
;				??? ?????????
p_ind_r1
			movf	binh,w			; ????????? ???? ??? <100.0
			movwf	peAsh			;			
			movf	binl,w			;
			movwf	peAsl			;
			movlw	0x03			;
			movwf	peBsh			;
			movlw	0xE8			;
			movwf	peBsl			;
			call    sravnenie		;
			btfss	MEN				;
		goto	obind				;	
			movlw	0xFF			;????????? ???? ??? >-10.0
			movwf	peBsh			;
			movlw	0x9c			;
			movwf	peBsl			;
			call    sravnenie		;
			btfss	BOL				;
		goto	obind				;

			btfss	RELE1			; ???? ?????????? ??????????? ??????????
			goto	$+3				;
			bsf		TOCHm2			;
			goto	$+2				;
			bcf		TOCHm2			;
			bcf		TOCHm3			;			
			
			bcf		TOCHKA3			;
			bsf		TOCHKA2			;
			movfw	edin			; 
			movwf	ind_3			; 
			movfw	dest			; 
			movwf	ind_2			; 
			movfw	sotn			; 
		goto	fing

obind
			btfss	RELE1			; ???? ?????????? ??????????? ??????????
			goto	$+3				;
			bsf		TOCHm3			;
			goto	$+2				;
			bcf		TOCHm3			;
			bcf		TOCHm2			;
			
			bsf		TOCHKA3
			bcf		TOCHKA2
			movfw	dest			; 
			movwf	ind_3			; 
			movfw	sotn			; 
			movwf	ind_2			; 
			movfw	tysc			; 
fing		movwf	ind_1			; 				
		return						;

Erro			
			bcf		CON				; ???????? ??? ???????????????, ??? ??????????? ??????????, ??? ??????????? ???????
			bcf		RELE1			; ????????? ??????????
			bsf		RELE2			; ???????? ?????? ??????		
			btfsc	UST
		return	
			movlw	.12				; ??? ?????? ???????
			call	big_str			; ???????????? ??????? ??????
			call 	och_left		; ??????? ??????????
;			clrf 	flag_i2			; 
;			clrf 	flag_i1			; 
;			movlw	cE				; 
;			movwf	ind_1			; 
;			movlw	cr				; 
;			movwf	ind_2			; 
;			movlw	ct				; 
;			movwf	ind_3			; 
		return						; 
;********************************************************************************************************


;============================================================================================
;********************************************************************************************
				FILL(goto 0x00),0x0800-$   ; ????????? ??? ?????????? ????? ?????



;============================================================================================











; initialize eeprom locations
;============================================================================================										
;++++++++++++++++++++++++++?????? ??? ?????? ? EEPROM +++++++++++++++++++++++++++++++++++++++
			ORG		0x2100						; 							
			DE		.01,.01 					;flag_0							* ????? ????????? ?????? ???????????
			DE		0x01,0x01,0x2c,0x2c			;Te_zad_hi,Te_zad_lo	30,0 ?	* ??????? ?????? ???????????
			DE		0x0a,0x0a					;Gi_zad_lo	 			 1,0 ?	* ???? ???????????
			DE		0x03,0x03,0x20,0x20			;Up_alr_hi,Up_alr_lo	80,0 ?	* ??????? ????????? ???????
			DE		0xff,0xff,0x38,0x38			;Dn_alr_hi,Dn_alr_lo 	-20,0 ?	* ?????? ????????? ???????
			DE		0x00,0x00,0x00,0x00			;Vr_zak_hi,Vr_zak_lo	 600 cek - 10 ???	* ????? ??????? ???????????? ?????????? ????? ? ??????? ????????? ??? ????? ?????????
			DE		0x00,0x00,0xb4,0xb4			;Vr_pov_hi,Vr_pov_lo	 180 cek -  3 ???	* ????? ???????? ?????????? ??????? ???????????
			DE		.0,.0						; 							
;============================================================================================

	END                       ; directive 'end of program'

;=======================================================================================================
