Code: Select all
program four_ds1820_v2
'depart et modif de :program four_ds1820_v1
'16f628a 4mhz config word= 3f21 and lcd 2lines x24 col
' you must first read the 8 bytes serial of the ds1820 (see others exemples) to put them here
' 16 is the dev type ...rest= serial and crc ..see data sheet at maxim...
' if a ds1820 is not connected lcd gives -127,5 as temp because tie up on the pin and return $ffff..
const serial_1 as byte[8]= (16,139,130,172,0,8,0,108) 'ds1820 n1 serial
const serial_2 as byte[8]= (16,65,248,158,0,8,0,163) 'ds1820 n2 serial
const serial_3 as byte[8]= ($10,$bc,$e4,$c4,$00,$08,$00,$05) 'ds1820 n3 serial
const serial_4 as byte[8]= ($10,$77,$7d,$c4,$00,$08,$00,$26) 'ds1820 n4 serial
dim j as byte
dim scratch as byte[9]
dim text as char[7]
dim a,b,i,x,r as byte
dim deci as char
Sub procedure get_temp (dim lig,col as byte)
Ow_Write(portA, 3, $BE) 'read scratchpad cmd
for i=0 to 8
x = ow_read(PORTA, 3)
scratch[i] = x ' get result 9 bytes in array
next i
a= scratch[1] ' signe temp
if a=0 then
lcd_chr(lig,col,"+")
else
lcd_chr(lig,col,"-")
end if
a=scratch[0]
if a.0 = 0 then 'a.0 is 0.5c value
deci = "0"
else
deci = "5"
end if
a = scratch[0] >>1 ' temp en degre
ByteToStr(a,text)
lcd_out_cp( text)
Lcd_Chr_CP(",")
Lcd_Chr_CP(deci)
'lcd_chr_CP(223)
'Lcd_Chr_CP("c")
end sub
main:
CMCON = 7
porta = 255 ' initialize porte to 255
PORTB = 0 ' initialize portb to 0
trisa = 255 ' designate porte as input
trisb = 0 ' designate portb as output
Lcd_Init(PORTB)
lcd_cmd( LCD_CURSOR_OFF)
Lcd_Cmd(LCD_CLEAR)
while true
'Lcd_Cmd(LCD_CLEAR)
Ow_Reset(PORTA, 3)
Ow_Write(portA, 3, $CC) ' skip rom cmd send cmd to all devices
Ow_Write(portA, 3, $44) 'convert temp cmd for the 2 ds1820 s
Delay_ms(1000) ' conversion delay fonction of precision
Ow_Reset(PORTA, 3)
Ow_Write(portA, 3, $55) ' match rom cmd selection ds1820 n1
for i=0 to 7
b = serial_1[i]
Ow_Write(portA, 3, b) 'serial of ds1820 n1
delay_ms(10)
next i
get_temp(1,1)
Ow_Reset(PORTA, 3)
Ow_Write(portA, 3, $55) ' match rom cmd selection ds1820 n2
for i=0 to 7
b = serial_2[i]
Ow_Write(portA, 3, b) 'serial of ds1820 n2
delay_ms(10)
next i
get_temp(1,7)
Ow_Reset(PORTA, 3)
Ow_Write(portA, 3, $55) ' match rom cmd selection ds1820 n3
for i=0 to 7
b = serial_3[i]
Ow_Write(portA, 3, b) 'serial of ds1820 n3
delay_ms(10)
next i
get_temp(1,13)
Ow_Reset(PORTA, 3)
Ow_Write(portA, 3, $55) ' match rom cmd selection ds1820 n4
for i=0 to 7
b = serial_4[i]
Ow_Write(portA, 3, b) 'serial of ds1820 n4
delay_ms(10)
next i
get_temp(1,19)
Lcd_Cmd(LCD_SECOND_ROW) ' if only 4 ds1820 and sec line for label
text= " gar"
Lcd_out_CP(text)
text= " liv"
Lcd_out_CP(text)
text= " ext"
Lcd_out_CP(text)
text= " ch1"
Lcd_out_CP(text)
delay_ms(1000)
wend ' endless loop
end.