I developed the following code in PBP3. I am having trouble getting it to work. I would like to see the temperature data that gets stored in the AmbTemp and ObjTemp memory by the I2C command. The data in each of these memory locations are WORD length. I can't find a command in PBP3 that allows me to read these 16 bit data on two of the ports. Am I missing something? Also, can you tell me what is wrong with my code?
Thank you, TravisM
Temperature:
i2cread SDA, SCL, SAdef, LocAmbTemp, [AmbTemp] 'read amb temperature Ta & save in AmbTemp
gosub SwapAmbBytes: 'I2C reads the highest byte first; Go swap the bytes
i2cread SDA, SCL, SAdef, LocObjTemp, [ObjTemp] 'read object temperature (Tobj) & save in ObjTemp
gosub SwapObjBytes:
if AmbTemp >= ObjTemp then Temperature 'Object is not heating, continue to loop
if (ObjTemp - AmbTemp) >= ThresTemp then ObjHeating 'differance between Amb & Obj temperature has exceeded threshold temp
Reset: 'Reset time count and turn motion sensor off if (ObjTemp - AmbTemp) is less that threshold temp.
cnt = 1
low 6 'turns motion sensor off
goto Temperature
ObjHeating:
high 6 'obj is heating; turn motion detector on (by setting RB6 high) to check for motion in room .
for cnt = 1 to MaxTime 'measure time by counting # of loops of approx one sec each.
If portb.1 = 1 then Temperature 'motion occured in room, do a reset
i2cread SDA, SCL, SAdef, LocAmbTemp, [AmbTemp] 'read amb temperature Ta & save in AmbTemp
gosub SwapAmbBytes:
i2cread SDA, SCL, SAdef, LocObjTemp, [ObjTemp] 'read object temperature (Tobj) & save in ObjTemp
gosub SwapObjBytes:
if AmbTemp >= ObjTemp then Temperature 'Object is not heating, start new loop
if (ObjTemp - AmbTemp) < ThresTemp then Temperature 'differance between Amb & Obj temperature is less than threshold temp
next cnt
Alarm: 'object temperature has exceeded threshold temp for more than the MaxTime, so sound alarm
high portb.0
pause 2000
low portb.0
pause 15000
if portb.5 = 0 then Temperature
goto Alarm
end
SwapAmbBytes: 'swap the MSB and LSB of the amb and obj temperatures
swap AmbTemp.byte1, AmbTemp.byte0
return
SwapObjBytes:
swap ObjTemp.Byte1, ObjTemp.byte0
return
Thank you, TravisM
Temperature:
i2cread SDA, SCL, SAdef, LocAmbTemp, [AmbTemp] 'read amb temperature Ta & save in AmbTemp
gosub SwapAmbBytes: 'I2C reads the highest byte first; Go swap the bytes
i2cread SDA, SCL, SAdef, LocObjTemp, [ObjTemp] 'read object temperature (Tobj) & save in ObjTemp
gosub SwapObjBytes:
if AmbTemp >= ObjTemp then Temperature 'Object is not heating, continue to loop
if (ObjTemp - AmbTemp) >= ThresTemp then ObjHeating 'differance between Amb & Obj temperature has exceeded threshold temp
Reset: 'Reset time count and turn motion sensor off if (ObjTemp - AmbTemp) is less that threshold temp.
cnt = 1
low 6 'turns motion sensor off
goto Temperature
ObjHeating:
high 6 'obj is heating; turn motion detector on (by setting RB6 high) to check for motion in room .
for cnt = 1 to MaxTime 'measure time by counting # of loops of approx one sec each.
If portb.1 = 1 then Temperature 'motion occured in room, do a reset
i2cread SDA, SCL, SAdef, LocAmbTemp, [AmbTemp] 'read amb temperature Ta & save in AmbTemp
gosub SwapAmbBytes:
i2cread SDA, SCL, SAdef, LocObjTemp, [ObjTemp] 'read object temperature (Tobj) & save in ObjTemp
gosub SwapObjBytes:
if AmbTemp >= ObjTemp then Temperature 'Object is not heating, start new loop
if (ObjTemp - AmbTemp) < ThresTemp then Temperature 'differance between Amb & Obj temperature is less than threshold temp
next cnt
Alarm: 'object temperature has exceeded threshold temp for more than the MaxTime, so sound alarm
high portb.0
pause 2000
low portb.0
pause 15000
if portb.5 = 0 then Temperature
goto Alarm
end
SwapAmbBytes: 'swap the MSB and LSB of the amb and obj temperatures
swap AmbTemp.byte1, AmbTemp.byte0
return
SwapObjBytes:
swap ObjTemp.Byte1, ObjTemp.byte0
return