Shop OBEX P1 Docs P2 Docs Learn Events
DS1822 multi code — Parallax Forums

DS1822 multi code

ArchiverArchiver Posts: 46,084
edited 2003-10-09 06:08 in General Discussion
This is the code I am using to read Temps w/DS1822

TRes VAR Nib ' Low order nibble of LSB
TmpHi VAR Nib ' High order nibble of Temp
TmpLo VAR Nib ' Low order nibble of Temp
TSgn VAR Nib ' High order nibble of sign flags
Temp VAR Byte ' Changed from word
tempdata VAR Byte (9)
Scratch1 VAR Byte
Scratch2 VAR Byte
TmpRes VAR Word

FTemp1 VAR Byte
FTemp2 VAR Byte
FTemp3 VAR Byte

PAUSE 1000

start:
OWOUT 2, 1, [noparse][[/noparse]$55,$22,$A0,$2C,$08,$00,$00,$00,$0C, $44]
PAUSE 25
OWIN 2, 4, [noparse][[/noparse]Temp]
IF Temp = 0 THEN PAUSE 25
OWOUT 2, 1, [noparse][[/noparse]$55, $22,$A0,$2C,$08,$00,$00,$00,$0C, $BE]
OWIN 2, 2, [noparse][[/noparse]STR tempdata\9]
Scratch1 = tempdata(0)
TRes = Scratch1.LOWNIB
TmpRes = TRes * 0625
TmpLo = Scratch1.HIGHNIB
Scratch2 = tempdata(1)
TmpHi = Scratch2.LOWNIB
Temp.HIGHNIB = TmpHi
Temp.LOWNIB = TmpLo
FTemp1 = ((Temp*9)/5)+32
PUT 121, FTemp1
GOTO SECOND

SECOND:
OWOUT 2, 1, [noparse][[/noparse]$55, $22,$69,$3D,$08,$00,$00,$00,$B4, $44]
PAUSE 25
OWIN 2, 4, [noparse][[/noparse]Temp]
IF Temp = 0 THEN PAUSE 25
OWOUT 2, 1, [noparse][[/noparse]$55, $22,$69,$3D,$08,$00,$00,$00,$B4, $BE]
OWIN 2, 2, [noparse][[/noparse]STR tempdata\9]
Scratch1 = tempdata(0)
TRes = Scratch1.LOWNIB
TmpRes = TRes * 0625
TmpLo = Scratch1.HIGHNIB
Scratch2 = tempdata(1)
TmpHi = Scratch2.LOWNIB
Temp.HIGHNIB = TmpHi
Temp.LOWNIB = TmpLo
FTemp2 = ((Temp*9)/5)+32
PUT 122, FTemp2
GOTO THIRD

THIRD:
OWOUT 2, 1, [noparse][[/noparse]$55, $22,$15,$2F,$08,$00,$00,$00,$AE, $44]
PAUSE 25
OWIN 2, 4, [noparse][[/noparse]Temp]
IF Temp = 0 THEN PAUSE 25
OWOUT 2, 1, [noparse][[/noparse]$55, $22,$15,$2F,$08,$00,$00,$00,$AE, $BE]
OWIN 2, 2, [noparse][[/noparse]STR tempdata\9]
Scratch1 = tempdata(0)
TRes = Scratch1.LOWNIB
TmpRes = TRes * 0625
TmpLo = Scratch1.HIGHNIB
Scratch2 = tempdata(1)
TmpHi = Scratch2.LOWNIB
Temp.HIGHNIB = TmpHi
Temp.LOWNIB = TmpLo
FTemp3 = ((Temp*9)/5)+32
PUT 123, FTemp3
' DEBUG DEC3 FTemp1, " F ", DEC3 FTemp2, " F ", DEC3 FTemp3, "
F", CR
' SEROUT 0, lcdspeed, [noparse][[/noparse]12, 14, DEC FTemp1, " F Inside", CR, DEC
FTemp3, " F Outside", CR] ' Read as byte for each key
' SLEEP 3
' GOTO start
RUN 3
END
Sign In or Register to comment.