
KBE	EQU		9Dh
KBLS	EQU		9Ch
KBF	EQU		9Eh
IEN0	EQU		0A8h
IEN1	EQU		0B1h

MAXTH	EQU		37h		;maximum temperature  seted
MINTH		EQU		1Eh		;minimum 	"			"

LCD     DATA     P2          ;define LCD data port on port 1
BUSY    BIT      LCD.7       ;define LCD busy flag
;*************************************************************
DATA_SEG	SEGMENT 	DATA
MAIN_SEG	SEGMENT 	CODE
BITS_SEG    SEGMENT     BIT

RSEG	DATA_SEG
Temp:	DS		1
BitCnt: DS 		1
Thermk:	DS		1

RSEG	BITS_SEG
FLAG1:		DBIT	1
Buncb_7:	DBIT	1
Buncb_6:	DBIT	1		
;***************************************************
; INTERRUPT VECTOR DEFINITIONS
;---------------------------------------------------

CSEG    AT      0000H               ; reset vector
        JMP     POWER_UP            ; power-on entry point

CSEG    AT      0003H               ; intr 0 vector
        RETI                        ; not used

CSEG    AT      000BH               ; timer 0 vector
        RETI                        ; not used

CSEG    AT      0013H               ; intr 1 vector
        CLR     EX1                 ; external int 1
        RETI                        ; not used

CSEG    AT      001BH               ; timer 1 vector
        RETI                  		;  NOT used

CSEG    AT      003BH               ; Kyeboard vector
        JMP		SCANK               ; used
;***************************************************
; MAIN PROGRAM INITIALIZATION
;---------------------------------------------------
RSEG	MAIN_SEG
	USING   0                   ; use register block 0

POWER_UP:
        MOV     SP,#7Fh        ; set stack pointer

	CALL  	Keyb_Init
	mov		Temp,#3Ch	;a number which i make some 		                 
	MOV		IEN0,#80h	;EA=1 and ET1=1 
	MOV		IEN1,#01h          ;KBD=1 Keyboard enable bit
		
AgainSc:
		MOV		A,KBF
		ANL		A,#0A0h
		JZ		Nokey
		MOV		IEN1,#00h	;disable key inderrupt
		MOV		A,#03h		;start delay
ly3:		DEC		A
		JNZ		ly3
		MOV		A,#0FFh
ly4:		DEC		A
		JNZ		ly4		;end  delay
		CLR		A
		MOV		KBF,A	;enable detection
		MOV		IEN1,#01h			
Nokey:		JMP     AgainSc
;*****************************************************************************
Keyb_Init:
		MOV		KBE,#0E0h		;enable interrupt only by the last 3 bits
		MOV		KBLS,#00h		;enable bit only by low level (zero)
		MOV		KBF,#00h
RET
;===============================================================
;ISR routine for scanning and showing on the dispaly the user preferences and the 
;actual temperature
;===============================================================
SCANK:	  
		
DISPLAY:push	acc
		MOV      A,#80h	
        		CALL    COMMAND	;where to be schowed
        		MOV      DPTR,#TEST
        		ACALL    DISP_STRING
		MOV	A,#85h
		CALL    COMMAND
		
		CALL	Show
		MOV      A,#0C1h
        		CALL    COMMAND		
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;the following assemby code is for subtraction of the stored number
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		MOV	A,KBF	;check which key used ,only the key Number 5	
		ANL	A,#20h
		JZ	Next_Key

		MOV	A,Temp
		CJNE	A,#MINTH,KNex1		;the set value can not be smaller than the MINTH
KNex1:		JC		KExod		
		
		CLR 	C
		SUBB	A,#01				;decriment 1
		MOV	Temp,A		
		CALL	Hex_to_Dec			;reform the data to decimal
		CALL	Show
KExod:		
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;the following assemby code is for addition the stored number
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Next_Key:
	
		MOV	A,KBF			;check which key used ,only the key Number 7	
		ANL	A,#80h
		JZ	Out
		
		MOV	A,Temp
		CJNE	A,#MAXTH,Nex1		;the set value can not be biger than the MAXTH
Nex1:		JNC	Out		
		
		CLR 	C
		ADDC	A,#01				;increment 1
		MOV	Temp,A		
		CALL	Hex_to_Dec			;reform the data to decimal
		CALL	Show	
Out: 		POP		acc
RETI

		END   
