;---------------------------------------------------------------------------;
;									    									;
;																			;
;	AUTHOR: EDWIN TUGANO JR.												;
;	DATE; AUGUST 03, 2005													;
;	EMAIL ADD: archjet3@hotmail.com											;
;	ADDRESS: MANDAUE CITY CEBU, PHILIPPINES 6014							;
;	TEL NO.: 0915-9476778													;
;	TITLE: TEMPERATURE SENSOR						 						;
;																			;
;---------------------------------------------------------------------------;

			#include "p16f676.inc"

	__CONFIG _WDT_OFF & _INTRC_OSC_NOCLKOUT & _CP_OFF & _MCLRE_OFF

temp	equ	0x20
		
		ORG 	0
		GOTO	Start


		cblock 	0x21
		d1
		d2
		temp1
		digit1
		digit2
		endc
;----------------------------------------------------------------------
Initialize

		bcf		STATUS,RP0
		movlw	B'00000111'	;to make RA0,RA1,RA2
							;not comparator
;		iorwf	CMCON,f
		movwf	CMCON	
		clrf	PORTA
		bsf		STATUS,RP0
		movlw	B'00001000'
		movwf	ANSEL

		movlw	B'00011111'
		movwf	TRISA

		bcf		ADCON1,ADCS2
		bcf		ADCON1,ADCS1
		bsf		ADCON1,ADCS0

		bcf		STATUS,RP0
		movlw	B'11100011'
		andwf	ADCON0,F
		movlw	B'01001100'
		iorwf	ADCON0,F

		bcf		ADCON0,ADFM
		bsf		ADCON0,VCFG
		bsf		ADCON0,ADON
	
		bcf		STATUS,RP0
		clrf	PORTC
		bsf		STATUS,RP0
		movlw	B'00000000'
		movwf	TRISC
		bcf		STATUS,RP0	
		return
;---------------------------------------------------------------
delay1ms
			movlw	3h
			movwf	d1
			movlw	3h
			movwf	d2
			
loopd2		decfsz	d2,f
			goto	loopd2
			decfsz	d1,f
			goto	loopd2
				return
;---------------------------------------------------------------
Display_out
			bcf		PORTC,5
			bsf		PORTC,4
			movlw	B'11110000'
			andwf	PORTC,F
			movf	digit1,w
			iorwf	PORTC,f
			call	delay1ms

			bcf		PORTC,4
			bsf		PORTC,5
			movlw	B'11110000'
			andwf	PORTC,F
			movf	digit2,w
			iorwf	PORTC,f
			call	delay1ms
				return
;---------------------------------------------------------------
sample
			clrf	temp1
			bsf		ADCON0,GO
loop_sample
			btfsc	ADCON0,GO
			goto	loop_sample
			movf	ADRESH,W
			movwf	temp1
			return
;---------------------------------------------------------------
actual_temp
			call	sample	
			movf	temp1,w ;Ha w=0 akkor temp1 -> w,  ha w=1 akkor temp1 -> temp1
			sublw	0x13 ;a W értékének kivonása 19-ből 2-es komplemens módszerrel; az eredmény a W-be kerül.
					     ;Ha az eredmény 0,vagy + akkor C=1, ha - akkor C=0
			btfss	STATUS,C ;Ha C=0 akkor GOTO végrehajtódik.
				goto	$+6
			movlw	8h
			movwf	digit1
			movlw	0h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x15 ;21
			btfss	STATUS,C
				goto	$+6
			movlw	9h
			movwf	digit1
			movlw	0h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x17 ;23
			btfss	STATUS,C
				goto	$+6
			movlw	0h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x19 ;25
			btfss	STATUS,C
				goto	$+6
			movlw	1h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x1B ;27
			btfss	STATUS,C
				goto	$+6
			movlw	2h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x1D ;29
			btfss	STATUS,C
				goto	$+6
			movlw	3h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x1F ;31
			btfss	STATUS,C
				goto	$+6
			movlw	4h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x21 ;33
			btfss	STATUS,C
				goto	$+6
			movlw	5h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x23 ;35
			btfss	STATUS,C
				goto	$+6
			movlw	6h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x24 ;36
			btfss	STATUS,C
				goto	$+6
			movlw	7h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x25 ;37
			btfss	STATUS,C
				goto	$+6
			movlw	8h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x27 ;39
			btfss	STATUS,C
				goto	$+6
			movlw	9h
			movwf	digit1
			movlw	1h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x29 ;41
			btfss	STATUS,C
				goto	$+6
			movlw	0h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x2B ;43
			btfss	STATUS,C
				goto	$+6
			movlw	1h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x2D ;45
			btfss	STATUS,C
				goto	$+6
			movlw	2h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x2F ;47
			btfss	STATUS,C
				goto	$+6
			movlw	3h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x31 ;49
			btfss	STATUS,C
				goto	$+6
			movlw	4h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x33 ;51
			btfss	STATUS,C
				goto	$+6
			movlw	5h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x35 ;53
			btfss	STATUS,C
				goto	$+6
			movlw	6h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x37 ;55
			btfss	STATUS,C
				goto	$+6
			movlw	7h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x39
			btfss	STATUS,C
				goto	$+6
			movlw	8h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x3B
			btfss	STATUS,C
				goto	$+6
			movlw	9h
			movwf	digit1
			movlw	2h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x3D
			btfss	STATUS,C
				goto	$+6
			movlw	0h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x3F
			btfss	STATUS,C
				goto	$+6
			movlw	1h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x41
			btfss	STATUS,C
				goto	$+6
			movlw	2h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x43
			btfss	STATUS,C
				goto	$+6
			movlw	3h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x45
			btfss	STATUS,C
				goto	$+6
			movlw	4h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x47
			btfss	STATUS,C
				goto	$+6
			movlw	5h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x49
			btfss	STATUS,C
				goto	$+6
			movlw	6h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample			
			movf	temp1,w
			sublw	0x4B
			btfss	STATUS,C
				goto	$+6
			movlw	7h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return					
			call	sample	
			movf	temp1,w
			sublw	0x4D
			btfss	STATUS,C
				goto	$+6
			movlw	8h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x4F
			btfss	STATUS,C
				goto	$+6
			movlw	9h
			movwf	digit1
			movlw	3h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x51
			btfss	STATUS,C
				goto	$+6
			movlw	0h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x53
			btfss	STATUS,C
				goto	$+6
			movlw	1h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x55
			btfss	STATUS,C
				goto	$+6
			movlw	2h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x57
			btfss	STATUS,C
				goto	$+6
			movlw	3h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x59
			btfss	STATUS,C
				goto	$+6
			movlw	4h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x5B
			btfss	STATUS,C
				goto	$+6
			movlw	5h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x5D
			btfss	STATUS,C
				goto	$+6
			movlw	6h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x5F
			btfss	STATUS,C
				goto	$+6
			movlw	7h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
			call	sample	
			movf	temp1,w
			sublw	0x61
			btfss	STATUS,C
				goto	$+1
			movlw	8h
			movwf	digit1
			movlw	4h
			movwf	digit2
			return
;---------------------------------------------------------------
Start
			call 	Initialize
			clrf	digit1
			clrf	digit2
;---------------------------------------------------------------
mainloop1

			call	actual_temp
			call	Display_out		
			goto	mainloop1
;---------------------------------------------------------------
			END	

