Code:
TempRom: 'Read & Store 2 x I2C DS18B20 Temp Sensor Rom Codes
debug 27,67,"Ins 1st sensor",10,13,"Any key to scan" 'Video Display
pause 2000 'Pause for 2 seconds
LoopA: 'Loop here to wait for button press
gosub MenuButtons 'Gosub MenuButtons gets button data (0,1,2,3,4,5 = no button) in VarC2
If VarC2 = 5 then LoopA 'If no button pressed goto loopA
OWOUT DigitalTemp, 1, [$33] 'Issue Read ROM command
OWIN DigitalTemp, 0, [STR I2C1\8] 'Read 64-bit device data into the 8-byte array "I2C1"
debug 27,67,"Ins 2nd sensor",10,13,"Any key to scan",10,13 'Video Display
pause 2000 'Pause for 2 seconds
LoopB: 'Loop here to wait for button press
gosub MenuButtons 'Gosub MenuButtons gets button data (0,1,2,3,4,5 = no button) in VarC2
If VarC2 = 5 then LoopB 'If no button pressed goto loopB
OWOUT DigitalTemp, 1, [$33] 'Issue Read ROM command
OWIN DigitalTemp, 0, [STR I2C2\8] 'Read 64-bit device data into the 8-byte array "I2C2"
'Save 2 x I2C Temp sensor data into first 16 bytes of AT24C512B External EEPROM
VarA = 1
I2CWRITE Scdeeprom,Sckeeprom,AT24C512B,VarA,[STR I2C1\8] 'Load data into I2c eeprom
pause 10 'Pause for 10ms
VarA = 9
I2CWRITE Scdeeprom,Sckeeprom,AT24C512B,VarA,[STR I2C2\8] 'Load data into I2c eeprom
For VarA = 1 to 16 'Load I2C1 data from eeprom
I2CREAD Scdeeprom,Sckeeprom,AT24C512B,VarA,[VarB1] 'Read data from I2c eeprom
DEBUG HEX2 VarB1," "
Next VarA
The code allows a user to connect two DS18B20 temp sensors in turn to the input, the program reads and then stores the device data into the external eeprom.
Bookmarks