#rem
Reads the BMP085 breakout board and converts the readings to temperature & pressure. The raw value of UT & UP are also displayed (order UT,T,UP,P).
#endrem
#terminal 4800
#picaxe 18m2
#no_data
hi2csetup i2cmaster, %11101110, i2cslow_8, i2cbyte ; set up bmp085 i2c device
pause 100
'hi2cin $AA,(b3,b2) : sertxd("AA=",#w1,cr,lf)
lp:
'w1=23153 'ac6 -----------------------------------------------------
hi2cin $B4,(b3,b2)
pause 10
'w2=27898 'ut -----------------------------------------------------
hi2cout $F4,($2E)
pause 50
hi2cin $F6,(b5,b4)
pause 10
'w2=24730 '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sertxd(#w2,", ")
'w3=32757 'ac5 -----------------------------------------------------
hi2cin $B2,(b7,b6)
pause 10
w4=w2-w1*2**w3
'sertxd("X1=",#w4,cr,lf)
'w1=-8711 'mc -----------------------------------------------------
hi2cin $BC,(b3,b2)
pause 10
if w1>32768 then: w1=0-w1: endif
'w2=2868 'md --------------------------------------------------------
hi2cin $BE,(b5,b4) '2432
pause 10
w2=w4+w2 '(x1+MD)
w3=w1/w2
for b0=1 to 11
w3=w3*2
w1=w1//w2*2
w3=w1/w2+w3
next b0
'w3=w3+1/2 'round up last digit
'w1=-8711 'mc -----------------------------------------------------
hi2cin $BC,(b3,b2)
pause 10
if w1>32768 then: w3=0-w3: endif
'sertxd("X2=",#w3,cr,lf)
w2=w3+w4
'sertxd("b5=",#w2,cr,lf)
w1=w2+8/16
sertxd(#w1,", ")
' --------------------------------------------
w3=w2-4000
'sertxd("b6=",#w3,cr,lf)
w5=w3
if w5>32768 then: w5=0-w5: endif
w5=w5*4
w5=w5**w5
w5=w5*4
'w6=4 'b2 ------------------------------------------------------------
hi2cin $B8,(b13,b12)
pause 10
w5=8*w6**w5
'sertxd("X1=",#w5,cr,lf)
'w4=-72 'ac2 ---------------------------------------------------------
hi2cin $AC,(b9,b8)
pause 10
w7=w4
if w4>32768 then: w7=0-w7: endif
w6=w3
if w6>32768 then: w6=0-w6: endif
w7=w7*8
w6=4*w6**w7
if w4<32768 or w3<32768 then: w6=0-w6: endif 'if either is positive then negate
'sertxd("X2=",#w6,cr,lf)
w7=w5+w6
'sertxd("X3=",#w7,cr,lf)
'w8=408 'ac1 ----------------------------------------------------------
hi2cin $AA,(b17,b16)
pause 10
w8=w8*4+w5+w6+2/4
'sertxd("B3=",#w8,cr,lf)
'w9=-14383 'ac3 ------------------------------------------------------
hi2cin $AE,(b19,b18)
pause 10
w9=0-w9 'assumes that this will always be negative
w10=w3
if w10>32768 then: w10=0-w10: endif
w5=w10*8**w9
'sertxd("X1=",#w5,cr,lf)
w9=w10*4
'w10=6190 'b1 ------------------------------------------------------------
hi2cin $B6,(b21,b20)
pause 10
w6=w9**w9**w10
'sertxd("X2=",#w6,cr,lf)
w7=w5+w6+2/4
'sertxd("X3=",#w7,cr,lf)
'w10=32741 'ac4 -------------------------------------------------------------
hi2cin $B0,(b21,b20)
pause 10
w9=32768+w7
w11=w9**w10
w10=w9*w10
w9=w11*2
w10=w10/32768
w9=w9+w10
'sertxd("B4=",#w9,cr,lf)
'w10=23843 'UP ----------------------------------------------------------------
'24730 213 40204 95329
hi2cout $F4,($F4)
pause 100
hi2cin $F6,(b21,b20)
pause 10
sertxd(#w10,", ")
'w10=40204 '++++++++++++++++++++++++++++++++++++++++++++++++++++++
w10=w10-w8
w8=w10**50000 'high word of B7
w7=w10*50000 'low word of B7
'sertxd("B7=",#w8," : ",#w7,cr,lf)
if w9>32768 then 'need to be able to double the divisor so halve it now
w9=w9/2
b1=1
else
if w8<32768 then 'if can double B7 now, can maintain a higher accuracy
b1=1
w8=w8*2
if w7<32768 then
w7=w7*2
else
w7=w7*2
w8=w8+1
endif
else
b1=0 'remember that doubling hasn't happened so do it later
endif
endif
'w2 will be the LS word of p, w3 will be the MS word
w3=0
w2=w8/w9
for b0=1 to 16
'sertxd ("B7/ ",#w8,", ",#w7,", ",#w3,", ",#w2,cr,lf)
w3=w3*2
if w2>32768 then: w3=w3+1: endif
w2=w2*2
w8=w8//w9*2
if w7>32767 then: w8=w8+1: endif
w7=w7*2
w2=w8/w9+w2
next b0
'sertxd ("B7/ ",#w8,", ",#w7,", ",#w3,", ",#w2,cr,lf)
if b1=0 then
w3=w3*2
if w2<32768 then
w2=w2*2
else
w2=w2*2
w3=w3+1
endif
endif
'sertxd("p=",#w3," : ",#w2,cr,lf)
b9=b6
b8=b5
w5=w4**w4
w4=w4*w4
'sertxd("X1=",#w5," : ",#w4,cr,lf)
w5=w5*3038
w5=w4**3038+w5
'sertxd("X1=",#w5,cr,lf)
w6=w3*7357
w6=w2**7357+w6
'w7=w2*7357
'sertxd ("low=",#w7,cr,lf)
'if w7<32768 then: w6=w6+1: endif 'because its a neg no, it trunctes opposite way
'sertxd("X2=",#w6,cr,lf)
w5=w5-w6+3791
'sertxd("W5=",#w5,cr,lf)
w7=w3
if w5>32768 then
w5=0-w5/16
w6=w2-w5
if w6>w2 then: w7=w7-1: endif
else
w5=w5/16
w6=w2+w5
if w6<w2 then: w7=w7+1: endif
endif
'sertxd("p=",#w7," : ",#w6,cr,lf)
b7=b14
b6=b13
b4=b12
bptr=28
b5=w3//10
@bptrinc=w2//10
w2=w2/10
w3=w3/10
b5=b6
do until w2=0
@bptrinc=w2//10
w2=w2/10
loop
bptr=bptr-1
'sertxd ("Pressure (Pa)= ")
do until bptr <28
sertxd (#@bptrdec)
loop
sertxd (", ",#b24,cr,lf)
b24=b24+1
if b24=60 then: b24=0: endif
b25=b24//30
if b25=0 then
sertxd ("--------------",cr,lf)
endif
'sertxd (cr,lf)
'sertxd (cr,lf)
'pause 500
goto lp