DS2450 1-Wire Quad A/D Converter and BS2P Stamp to wed this...
Archiver
Posts: 46,084
Here is some pbasic code to look at for the DS2450. Be sure an look at the
Dallas data sheet for the DS2450.
Chuck
'setup for 1-wire Dallas DS2450
'steps 1 thru 3 per data sheet
'4.7k Ohm 5v pullup on DS2450 pins 5 and 6
'100k Ohm potentimeter pot on DS2450 pin 8 to vary voltage input, 0 to 5v
'9/24/00
r var byte(12)
x var word
y var byte
z var byte
w var byte
j var byte
p var nib
s var nib
afl var y.bit4
afh var y.bit5
s=8
gosub INIT
pollin 0,0
pollin 1,0
pollout 9,1
pollmode 2
p=4
'Step 1 of data sheet, page 16
owout p,1,[noparse][[/noparse]$cc,$55,$08,$00,$c0]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$c0]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$c0]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$0c]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$0d]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
'Step 2 of data sheet, page 17
owout p,1,[noparse][[/noparse]$cc,$55,$16,$00,$64]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$96]
owin p,0,[noparse][[/noparse]r(3),r(4),r(5)]
owout p,1,[noparse][[/noparse]$cc,$3c,$08,$40]
owin p,0,[noparse][[/noparse]r(6),r(7)]
xx:
owin p,0,[noparse][[/noparse]r(8)]
if r(8)=$ff then yy
goto xx
yy:
owout p,1,[noparse][[/noparse]$cc,$aa,$0f,$00]
owin p,0,[noparse][[/noparse]r(9),r(10),r(11)]
z=$c0:w=$c0
zzz:
'Step 3 of data sheet, page 18
owout p,1,[noparse][[/noparse]$cc,$55,$08,$00,z]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(3),r(4),r(5)]
owout p,0,[noparse][[/noparse]w]
owin p,2,[noparse][[/noparse]r(6),r(7),r(8)]
zz:
owout p,1,[noparse][[/noparse]$cc,$55,$0f,$00,$0d]
owin p,2,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,1,[noparse][[/noparse]$cc,$3c,$08,$40]
owin p,0,[noparse][[/noparse]r(0),r(1)]
pause 5 'delay for convert
ww:
owin p,0,[noparse][[/noparse]r(2)]
if r(2)=$ff then vv
goto ww
vv:
owout p,1,[noparse][[/noparse]$cc,$aa,$06,$00]
owin p,2,[noparse][[/noparse]r(0),r(1)]
x=((((r(1)*256)+r(0))/256)*5)*4
debug dec x," mv ",cr
lcdout s,2,[noparse][[/noparse]dec4 x,"mv "]
owout p,1,[noparse][[/noparse]$cc,$aa,$0f,$00]
owin p,2,[noparse][[/noparse]r(0),r(1),r(2)]
if r(0)>$0d then res
pause 500
z=$c0:w=$c0
goto zzz
res:
debug hex2 r(0)," alarm",cr
'goto zz
auxio
y=r(0)
z=$80:w=$80
if afl=1 then res2
z=$c0
goto res5
res2:
lcdout s,128+7,[noparse][[/noparse]$3c]
res5:
if afh=1 then res3
w=$c0
goto res4:
res3:
lcdout s,128+7,[noparse][[/noparse]$3e]
res4:
mainio
pause 500
get 128,j
debug bin8 j,cr
'pollmode 2
goto zzz
INIT
lcdcmd s,48 'set function
pause 5
lcdcmd s,48
pause 0
lcdcmd s,48
pause 0
lcdcmd s,32
pause 0
lcdcmd s,44
pause 0
lcdcmd s,8 'display off
lcdcmd s,12 'display on
lcdcmd s,6 'set mode
return
Dallas data sheet for the DS2450.
Chuck
'setup for 1-wire Dallas DS2450
'steps 1 thru 3 per data sheet
'4.7k Ohm 5v pullup on DS2450 pins 5 and 6
'100k Ohm potentimeter pot on DS2450 pin 8 to vary voltage input, 0 to 5v
'9/24/00
r var byte(12)
x var word
y var byte
z var byte
w var byte
j var byte
p var nib
s var nib
afl var y.bit4
afh var y.bit5
s=8
gosub INIT
pollin 0,0
pollin 1,0
pollout 9,1
pollmode 2
p=4
'Step 1 of data sheet, page 16
owout p,1,[noparse][[/noparse]$cc,$55,$08,$00,$c0]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$c0]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$c0]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$0c]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$0d]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
'Step 2 of data sheet, page 17
owout p,1,[noparse][[/noparse]$cc,$55,$16,$00,$64]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$96]
owin p,0,[noparse][[/noparse]r(3),r(4),r(5)]
owout p,1,[noparse][[/noparse]$cc,$3c,$08,$40]
owin p,0,[noparse][[/noparse]r(6),r(7)]
xx:
owin p,0,[noparse][[/noparse]r(8)]
if r(8)=$ff then yy
goto xx
yy:
owout p,1,[noparse][[/noparse]$cc,$aa,$0f,$00]
owin p,0,[noparse][[/noparse]r(9),r(10),r(11)]
z=$c0:w=$c0
zzz:
'Step 3 of data sheet, page 18
owout p,1,[noparse][[/noparse]$cc,$55,$08,$00,z]
owin p,0,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,0,[noparse][[/noparse]$00]
owin p,0,[noparse][[/noparse]r(3),r(4),r(5)]
owout p,0,[noparse][[/noparse]w]
owin p,2,[noparse][[/noparse]r(6),r(7),r(8)]
zz:
owout p,1,[noparse][[/noparse]$cc,$55,$0f,$00,$0d]
owin p,2,[noparse][[/noparse]r(0),r(1),r(2)]
owout p,1,[noparse][[/noparse]$cc,$3c,$08,$40]
owin p,0,[noparse][[/noparse]r(0),r(1)]
pause 5 'delay for convert
ww:
owin p,0,[noparse][[/noparse]r(2)]
if r(2)=$ff then vv
goto ww
vv:
owout p,1,[noparse][[/noparse]$cc,$aa,$06,$00]
owin p,2,[noparse][[/noparse]r(0),r(1)]
x=((((r(1)*256)+r(0))/256)*5)*4
debug dec x," mv ",cr
lcdout s,2,[noparse][[/noparse]dec4 x,"mv "]
owout p,1,[noparse][[/noparse]$cc,$aa,$0f,$00]
owin p,2,[noparse][[/noparse]r(0),r(1),r(2)]
if r(0)>$0d then res
pause 500
z=$c0:w=$c0
goto zzz
res:
debug hex2 r(0)," alarm",cr
'goto zz
auxio
y=r(0)
z=$80:w=$80
if afl=1 then res2
z=$c0
goto res5
res2:
lcdout s,128+7,[noparse][[/noparse]$3c]
res5:
if afh=1 then res3
w=$c0
goto res4:
res3:
lcdout s,128+7,[noparse][[/noparse]$3e]
res4:
mainio
pause 500
get 128,j
debug bin8 j,cr
'pollmode 2
goto zzz
INIT
lcdcmd s,48 'set function
pause 5
lcdcmd s,48
pause 0
lcdcmd s,48
pause 0
lcdcmd s,32
pause 0
lcdcmd s,44
pause 0
lcdcmd s,8 'display off
lcdcmd s,12 'display on
lcdcmd s,6 'set mode
return