2x DS1820 Thermometer



Dual DS1820 thermometer circuit schematic

2xDS1820 Thermometer circuit

Dual thermometer with Ericsson A2628 lcd

Download code.


Source code file for 2xDS1820 Thermometer
;=====lcd digital thermometer with 2xds18s20 Version 1.1======15/12/08==
;	iic lcd driver: real PCF8548, custom screen wiring
;	ra0,ra1     S1, S2 ds1820 data I/O 
;	ra2,ra3	reset, sclock, sdata
;	internal clock
;;	 http://www.module.ro 
;------------------------------------------------------------
;------------------------------------------------------------
;     LIST P=16F627;f=inhx8m
;       #include "P16F627.INC" 
;------------------------------------------------------------
     LIST P=16F628;f=inhx8m
        #include "P16F628.INC"  ; Include header file
	__CONFIG	_PWRTE_ON  & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _LVP_OFF & _CP_OFF & _MCLRE_OFF
;------------------------------------------------------------
	cblock 0x20	; Beginn General Purpose-Registerstatus	
	transo
	count1	
	count2	
	count3	
	count4
	dig
	dig1
	dig2
	dig3
	thmp
	semn
	afisaj
	endc
;------------------------------------------------------------
#DEFINE rset	PORTA,2
#DEFINE sclk	PORTA,3
#DEFINE sdta	PORTA,4
#DEFINE sth2	PORTA,1
#DEFINE sth1	PORTA,0
;------------------------------------------------------------
	org		0x00
	goto	init
	org		0x04
;------------------------------------------------------------
init
	nop
	bcf		STATUS,RP0	; Bank 0
	movlw	0x07		; Turn comparators off and enable pins for I/O 
	movwf	CMCON	
	bsf		STATUS,RP0	; Bank 1
	movlw	0x00
	movwf	TRISA
	movlw	0x00	; output
	movwf	TRISB
	bcf		STATUS,RP0	; Bank 0
	clrf	semn
;***************************************************
start
	bcf		rset
	;bcf	pwroff
	call	halta	; rset time - min. 100ns
	bsf		rset	; reset finished
;***************************************************
;* Lcd init commands                               *
;***************************************************
	call	iict	; i2c start
	movlw	0x7A	; device write address 
	call	act	; i2c send subroutine
	movlw	0x00	; many command bytes follow - see pcf8548 data sheet	
	call	act	; i2c send subroutine
	movlw	0x21	; extended set command
	call	act
	movlw	0x15	; bias
	call	act
	movlw	0xEA	; Vop
	call	act
	movlw	0x0F 	; DO=1 lcd configuration - LSB up, BRS=TRS=1
	call	act
	movlw	0x20	; normal command set
	call	act
	movlw	0x0C	; normal lcd mode
	call	act
	call	iicp	; i2c stop
;***************************************************
;* Lcd data commands                               *
;***************************************************
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x40	; multiple data bytes
	call	act
	call	cbild	; clear screen
	call	iicp	; i2c stop
;***************************************************
;* Display TEMP 1 & 2				   *
;***************************************************
	call	lin1
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x40	; multiple data bytes
	call	act
	movlw	0x23
	movwf	count4
	movlw	0x00
	movwf	dig
afi1
	call	logo
	call	act
	incf	dig,F	
	decfsz  count4,F
	goto	afi1
	call	iicp	; i2c stop
	call	lin2
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x40	; multiple data bytes
	call	act
	movlw	0x23
	movwf	count4
afi2
	call	logo
	call	act
	incf	dig,F	
	decfsz  count4,F
	goto	afi2
	call	iicp	; i2c stop
nou	
	call	rdset1	;reset th1
	call	rdset2	;reset th2
	movlw	0xCC	;skip rom th1
	call	schtx1
	movlw	0xCC	;skip rom th2
	call	schtx2
	movlw	0x44	;convert th1
	call	schtx1
	movlw	0x44	;convert th2
	call	schtx2
	call	haltb	; 800ms conversion time
	call	rdset1
	movlw	0xCC	;skip rom
	call	schtx1
	movlw	0xBE	;read scratchpad
	call	schtx1
	call	schrx1	
	call	mux
	call	pos1
	call	plus
	movf	dig2,W
	call	afisare
	movf	dig1,W
	call	afisare
	call	virgula
	movf	dig3,W
	call	afisare
;------------------------------------------------------------
	call	rdset2
	movlw	0xCC	;skip rom
	call	schtx2
	movlw	0xBE	;read scratchpad
	call	schtx2
	call	schrx2	
	call	mux
	call	pos2
	call	plus
	movf	dig2,W
	call	afisare
	movf	dig1,W
	call	afisare
	call	virgula
	movf	dig3,W
	call	afisare
	goto	nou
;------------------------------------------------------------
cbild
	movlw	0x08	; 64 rows 
	movwf	count4
	bcf		sdta	
linee	
	movlw	0x66	; 102 columns
	movwf	count3
wdh	movlw	0x08	; 8 bit data
	movwf	count2
wbit
	bcf		sclk
	call	haltd
	bsf		sclk
	call	haltd
	bcf		sclk
	decfsz	count2,F
	goto	wbit
	call	ackp
	decfsz	count3,F	
	goto 	wdh 	
	decfsz	count4,F
	goto 	linee
	retlw	0x00 

;***************************************************
rdset1
	bcf		sth1
	call	halte	; 510 us
	bsf		sth1
	call	usain
	call	haltd	; 61 us
	btfsc	sth1	
	bsf		PORTB,0 ; check th1 presence
	btfss	sth1
	bcf		PORTB,0
	call	halte	; 510us
	call	usaex
	retlw	0x00
;***************************************************
rdset2
	bcf		sth2
	call	halte	; 510 us
	bsf		sth2
	call	usain
	call	haltd	; 61 us
	btfsc	sth2	
	bsf		PORTB,1 ; check th2 presence
	btfss	sth2
	bcf		PORTB,1
	call	halte	; 510us
	call	usaex
	retlw	0x00
;***************************************************
schtx1
	movwf	thmp	; 
	movlw	0x08
	movwf	count3
;***************************************************
gbit
	btfsc	thmp,0	; data reverse flow	
	call	unu
	btfss	thmp,0
	call	nul
	rrf		thmp,F
	decfsz	count3,F
	goto	gbit
	retlw	0x00
;***************************************************
;***************************************************
schtx2
	movwf	thmp	; 
	movlw	0x08
	movwf	count3
;***************************************************
gbit2
	btfsc	thmp,0	; data reverse flow	
	call	unu2
	btfss	thmp,0
	call	nul2
	rrf		thmp,F
	decfsz	count3,F
	goto	gbit2
	retlw	0x00
;***************************************************
schrx1
	movlw	0x08
	movwf	count3
sampl
	rrf		thmp,F
	bcf		sth1
	call	usain
	call	haltcc	; 11us
	btfsc	sth1	; data reverse flow	
	bsf		thmp,7
	btfss	sth1
	bcf		thmp,7
	call	haltd	; 61 us
	call	usaex
	decfsz	count3,F
	goto	sampl
	bcf		sth1
	call	usain
	call	haltc	; 11us
	btfsc	sth1	; data bit flow	
	bsf		semn,0
	btfss	sth1
	bcf		semn,0
	call	haltd	; 61 us
	call	usaex
	btfsc	semn,0
	call	negativ
	movlw	0x00
	btfsc	thmp,0
	addlw	0x05
	movwf	dig3
	rrf		thmp,0
	andlw	0x7F
	movwf	thmp	
	return
;***************************************************
;***************************************************
schrx2
	movlw	0x08
	movwf	count3
sampl2
	rrf		thmp,F
	bcf		sth2
	call	usain
	call	haltcc	; 11us
	btfsc	sth2	; data reverse flow	
	bsf		thmp,7
	btfss	sth2
	bcf		thmp,7
	call	haltd	; 61 us
	call	usaex
	decfsz	count3,F
	goto	sampl2
	bcf		sth2
	call	usain
	call	haltc	; 11us
	btfsc	sth2	; data bit flow	
	bsf		semn,0
	btfss	sth2
	bcf		semn,0
	call	haltd	; 61 us
	call	usaex
	btfsc	semn,0
	call	negativ
	movlw	0x00
	btfsc	thmp,0
	addlw	0x05
	movwf	dig3
	rrf		thmp,0
	andlw	0x7F
	movwf	thmp	
	return
;***************************************************
negativ	
	movf	thmp,0
	xorlw	0xFF
	addlw	0x01
	movwf	thmp
	return
;***************************************************
;***************************************************
unu	bcf	sth1
	call	haltc	; 11 us
	bsf	sth1
	call	haltd	; 65 us
 	retlw	0x00
;***************************************************
nul	bcf	sth1
	call	haltc	; 11 us
	call	haltd	; 65 us
	bsf	sth1
 	retlw	0x00
;***************************************************
;***************************************************
unu2
	bcf	sth2
	call	haltc	; 11 us
	bsf	sth2
	call	haltd	; 65 us
 	retlw	0x00
;***************************************************
nul2
	bcf	sth2
	call	haltc	; 11 us
	call	haltd	; 65 us
	bsf	sth2
 	retlw	0x00
;***************************************************
virgula
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x40	; 
	call	act
	movlw	0x80 
	call	act
	movlw	0x40
	call	act
	call	iicp	; i2c stop
	return
;***************************************************
plus
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x40	; 
	call	act
	movlw	0x08 
	call	act
	btfsc	semn,0
	movlw	0x08
	btfss	semn,0
	movlw	0x1C
	call	act
	movlw	0x08 
	call	act
	movlw	0x00
	call	act
	call	iicp	; i2c stop
	return
;***************************************************
afisare
	movwf	count4
	movlw	0x46
	movwf	dig
	movf	count4,F ; zero bit test if digx=digx=0
	btfsc	STATUS,2
	goto	on_screen
rec
	incf	dig,F	; get PC address
	incf	dig,F
	incf	dig,F
	incf	dig,F
	incf	dig,F
	incf	dig,F	
	decfsz  count4,F
	goto	rec
on_screen
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x40	; 
	call	act
	movlw	0x06	; display 6 bytes of no. font8H
	movwf	count4
afi3
	call	logo
	call	act
	incf	dig,F	
	decfsz  count4,F
	goto	afi3
	call	iicp	; i2c stop
	return
;***************************************************
lin1
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x00	; (0x80 for just one command)
	call	act
	movlw	0x40	; Y address
	call	act
	movlw	0x80	; X address
	call	act
	call	iicp	; i2c stop
	return
;***************************************************
lin2
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x00	; (0x80 for just one command)
	call	act
	movlw	0x43	; Y address
	call	act
	movlw	0x80	; X address
	call	act
	call	iicp	; i2c stop
	return
;***************************************************
pos1
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x00	; (0x80 for just one command)
	call	act
	movlw	0x40	; Y address
	call	act
	movlw	0xA4	; X address
	call	act
	call	iicp	; i2c stop
	return
;***************************************************
pos2
	call	iict	; i2c start
	movlw	0x7A
	call	act
	movlw	0x00	; (0x80 for just one command)
	call	act
	movlw	0x43	; Y address
	call	act
	movlw	0xA4	; X address
	call	act
	call	iicp	; i2c stop
	return
;***************************************************

;***************************************************
act	movwf	transo	; iic data transmission 
	movlw	0x08
	movwf	count3
vbit
	bcf		sclk
	call	haltd
	btfsc	transo,7	
	bsf		sdta
	btfss	transo,7
	bcf		sdta
	call	haltd
	bsf		sclk
	call	haltd
	bcf		sclk
	call	haltd
	rlf		transo,F
	decfsz	count3,F
	goto	vbit
	call	ackp
	retlw	0x00
;***************************************************
iicp
	bcf		sdta	; stop condition module
	call	haltd
	bsf		sclk
	call	haltd
	bsf		sdta	; stop command
	call		haltd
	bcf		sclk
	call	haltd
	retlw	0x00
;***************************************************	
iict
	bsf		sdta	; start condition module 
	bsf		sclk
	call	haltd
	bcf		sdta	; start command
	call	haltd
	bcf		sclk
	call	haltd
	retlw	0x00
;***************************************************
ackp
	bsf		STATUS,RP0  ;switch to bank 1
	movlw	0x10	; sdta set to input
	movwf	TRISA
	bcf		STATUS,RP0  ;switch back to bank 0
	bsf		sclk	; one clock step for acknowledge (no read data)
	call	haltd
	bcf		sclk
	bsf		STATUS,RP0  ;switch to bank 1
	movlw	0x00	; porta set to output
	movwf	TRISA
	bcf		STATUS,RP0  ;switch back to bank 0
	bcf		sclk
	bcf		sdta
	retlw	0x00
;***************************************************
;***************************************************
haltb	
	movlw	0x0A	; cca. 800ms delay
	goto	los
halta	
	movlw	0x04	; cca. 320ms delay 
los	movwf	count3
s3	movlw	0x50
	movwf	count1
s1	movlw	0xFA	  
	movwf	count2
s2	nop
	decfsz	count2,F	
	goto 	s2		
	decfsz	count1,F	
	goto 	s1		
	decfsz	count3,F    
	goto	s3          
	retlw	0x00

;***************************************************
haltc
	nop	;	11us
	nop
haltcc
	movlw	0x01	;	9us	
	movwf	count1
ww1	decfsz	count1,F	
	goto 	ww1
	retlw	0x00
;***************************************************
halte
	movlw	0xAA	;	510 us
	goto	w2
haltd
	movlw	0x13	;	61 us
w2	movwf	count1
w3	decfsz	count1,F	
	goto 	w3
	nop		
	retlw	0x00
;***************************************************

;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
usaex
	bsf	STATUS,RP0  ;switch to bank 1
	movlw	0x00	; PORTA set to out/inputs
	movwf	TRISA
	bcf	STATUS,RP0  ;switch back to bank 0
	return
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
usain
	bsf	STATUS,RP0  ;switch to bank 1
	movlw	0x03	; sth1 , sth2 set to input
	movwf	TRISA
	bcf	STATUS,RP0  ;switch back to bank 0
	return
;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

;***************************************************
mux	clrf	dig1
	clrf	dig2
	movf	thmp,F ; zero bit test if dig=dig=0
	btfss	STATUS,2
	goto	calc
	goto	gatam
calc
	call	digi
	decfsz	thmp,F
	goto	calc
gatam	return
;***************************************************
digi
	incf	dig1,F
	movlw	0x0A
	subwf	dig1,W
	btfss	STATUS,2 ;test zero bit
	goto	gatas
	clrf	dig1
	incf	dig2,F
	movlw	0x0A
	subwf	dig2,W
	btfss	STATUS,2 ;test zero bit
	goto	gatas
	clrf	dig2
gatas
	retlw	0x00	

;************************************************************************
;*	adrese  text in pagina 3							*
;************************************************************************
	ORG	0x0200
logo
	movlw	0x02
	movwf	PCLATH
	movf	dig,W
	addwf	PCL,F
	retlw	0X01	;T
	retlw	0X01
	retlw	0XFF
	retlw	0X01
	retlw	0X01
	retlw	0X00
	retlw	0XFF	;E
	retlw	0X89
	retlw	0X89
	retlw	0X89
	retlw	0X89
	retlw	0X00
	retlw	0XFF	;M
	retlw	0X06
	retlw	0X38
	retlw	0XC0
	retlw	0X38
	retlw	0X06
	retlw	0XFF
	retlw	0X00
	retlw	0XFF	;P
	retlw	0X09
	retlw	0X09
	retlw	0X09
	retlw	0X06
	retlw	0X00
	retlw	0X04	; 1
	retlw	0X02
	retlw	0XFF
	retlw	0X00
	retlw	0X00
	retlw	0X00	
	retlw	0X42	;:
	retlw	0X00
	retlw	0X00
	retlw	0X01	;T
	retlw	0X01
	retlw	0XFF
	retlw	0X01
	retlw	0X01
	retlw	0X00
	retlw	0XFF	;E
	retlw	0X89
	retlw	0X89
	retlw	0X89
	retlw	0X89
	retlw	0X00
	retlw	0XFF	;M
	retlw	0X06
	retlw	0X38
	retlw	0XC0
	retlw	0X38
	retlw	0X06
	retlw	0XFF
	retlw	0X00
	retlw	0XFF	;P
	retlw	0X09
	retlw	0X09
	retlw	0X09
	retlw	0X06
	retlw	0X00
	retlw	0X82	; 2
	retlw	0XC1
	retlw	0XA1
	retlw	0X91
	retlw	0X8E
	retlw	0X00
	retlw	0X42	;:
	retlw	0X00
	retlw	0X00
	retlw	0X00;
 	retlw	0X7E	;0
	retlw	0X81
	retlw	0X81
 	retlw	0X7E
 	retlw	0X00
 	retlw	0X00
 	retlw	0X04	;1
 	retlw	0X02
 	retlw	0XFF
 	retlw	0X00
 	retlw	0X00
 	retlw	0X00
 	retlw	0X82	;2
 	retlw	0XC1
	retlw	0XA1
	retlw	0X91
	retlw	0X8E
 	retlw	0X00
	retlw	0X42	;3
	retlw	0X81
	retlw	0X89
	retlw	0X89
	retlw	0X76
	retlw	0X00
	retlw	0X30	;4
	retlw	0X2C
	retlw	0X22
	retlw	0XFF
	retlw	0X20
	retlw	0X00
	retlw	0X4C	;5
	retlw	0X8B
	retlw	0X89
	retlw	0X89
	retlw	0X71
	retlw	0X00
	retlw	0X7E	;6
	retlw	0X89
	retlw	0X89
	retlw	0X89
	retlw	0X72
	retlw	0X00
	retlw	0X01	;7
	retlw	0XE1
	retlw	0X19
 	retlw	0X07
 	retlw	0X01
 	retlw	0X00
 	retlw	0X76	;8
 	retlw	0X89
 	retlw	0X89
 	retlw	0X89
 	retlw	0X76
 	retlw	0X00
	retlw	0X4E	;9
	retlw	0X91
	retlw	0X91
	retlw	0X91
	retlw	0X7E
	retlw	0X00
	retlw	0X00;
;***************************************************
	end
;============================================================

Links:


Back to my home page
Last updated January, 2009
© Copyright 2009 Bergthaller Iulian-Alexandru