'Temperature aquisition computer '20.09.2016 $regfile = "89c4051.dat" 'bluetooth rs232 converter $crystal = 18432000 $baud = 9600 $large Enable Interrupts Enable Timer0 'Enable Serial Config Scl = P3.3 Config Sda = P3.4 Config I2cdelay = 10 Config Timer0 = Timer , Gate = Internal , Mode = 1 On Timer0 Timer_0_int Priority Set Timer0 'On Serial Serial_int 'Two EEPROMs 24LC256 Declare Sub Write_eeprom_bank0 'address, value Declare Sub Read_eeprom_bank0 'address, value Declare Sub Write_eeprom_bank1 'address, value Declare Sub Read_eeprom_bank1 'address, value Declare Sub Send_all 'licznik Declare Sub Read_temp 'sensors, licznik, tnew1, tnew2 Declare Sub Read_sensor 'sensor, tnew1, tnew2 Declare Sub Save_temp 'licznik, tnew1, tnew2 Dim Address As Word Dim Value As Byte Dim Adr0 As Byte Dim Adr1 As Byte Dim Licznik As Word Dim Licznik0 As Word Dim Licznik1 As Word Dim Licz As Word Dim Tnew1 As Byte Dim Tnew2 As Byte Dim Sensors As Byte Dim Sensor As Byte Dim Count As Byte Dim Seconds As Word Dim Command As Byte Dim Period As Word Dim Limit As Word Dim Dat1 As Byte Dim Dat2 As Byte Dim Tim1 As Byte Dim Tim2 As Byte 'DS18B20 sensors T0 Alias P1.7 T1 Alias P1.6 T2 Alias P1.5 T3 Alias P1.4 T4 Alias P1.3 T5 Alias P1.2 T6 Alias P1.1 T7 Alias P1.0 T8 Alias P3.7 T9 Alias P3.5 Light Alias P3.2 Reset Light Waitms 100 Set Light P1 = 255 P3 = 255 'up to 10 sensors can be connected Sensors = 10 'interval for temperature reading (3600 sec.) Period = 3600 'memory size 'Limit = 8190 Limit = 32760 Do Inputbin Command If Command = 73 Then 'I Stop Timer0 Inputbin Dat1 Inputbin Dat2 Inputbin Tim1 Inputbin Tim2 'EEPROMs test Address = Tim1 Value = Dat1 Call Write_eeprom_bank0 Address = Tim1 Call Read_eeprom_bank0 If Value = Dat1 Then Tnew1 = 1 Else Tnew1 = 0 End If Address = Tim2 Value = Dat2 Call Write_eeprom_bank1 Address = Tim2 Call Read_eeprom_bank1 If Value = Dat2 Then Tnew2 = 1 Else Tnew2 = 0 End If Print "EEPROM-0:" Print Tnew1 Print " EEPROM-1:" Print Tnew2 'init Licznik = 0 Count = 0 Tnew1 = 0 Tnew2 = 0 Seconds = Period - 5 Mov tl0,#h'00 Mov th0,#h'10 Call Read_temp Licznik = 0 Tnew1 = 0 Tnew2 = 0 Count = 0 Seconds = Period - 5 Mov tl0,#h'00 Mov th0,#h'10 Start Timer0 Print " OK " End If If Command = 71 Then 'G Stop Timer0 Print "DATA" Print Dat1 Print Dat2 Print Tim1 Print Tim2 Print Seconds Print Licznik If Licznik > 0 Then Call Send_all End If Start Timer0 Print "END" End If If Command = 67 Then 'C Print Seconds End If If Command = 115 Then 's Stop Timer0 Print " System zatrzymany! " End If 'If Command = 65 Then 'A ' Inputbin Tnew1 ' Print "Test of memory: EEPROM-0..." ' Tnew2 = 0 ' For Licz = 0 To Limit ' Address = Licz ' Value = Tnew1 ' Call Write_eeprom_bank0 ' Address = Licz ' Call Read_eeprom_bank0 ' If Value = Tnew1 Then ' Incr Tnew2 ' End If ' Next ' Tnew1 = Limit + 1 ' If Tnew2 = Tnew1 Then ' Print "OK" ' Else ' Print "ER" ' End If 'End If Loop End 'The Interrupt Handler For The Timer0 Interrupt Timer_0_int: Inc Count If Count = 25 Then 'Interrupt occured after 1 sec" Incr Seconds If Seconds = Period Then Call Read_temp 'each sensor takes approx. 1 sec. Seconds = Sensors End If Count = 0 End If Mov tl0,#h'00 Mov th0,#h'10 Return Sub Write_eeprom_bank0 Adr0 = Address And 255 Shift Address , Right , 8 Adr1 = Address And 255 I2cstart 'start condition I2cwbyte 160 'slave address I2cwbyte Adr1 'address of EEPROM I2cwbyte Adr0 'address of EEPROM I2cwbyte Value 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub Sub Read_eeprom_bank0 Adr0 = Address And 255 Shift Address , Right , 8 Adr1 = Address And 255 I2cstart 'generate start I2cwbyte 160 'slave address I2cwbyte Adr1 'address of EEPROM I2cwbyte Adr0 'address of EEPROM I2cstart 'repeated start I2cwbyte 161 'slave address (read) I2crbyte Value , Nack 'read byte I2cstop 'generate stop End Sub Sub Write_eeprom_bank1 Adr0 = Address And 255 Shift Address , Right , 8 Adr1 = Address And 255 I2cstart 'start condition I2cwbyte 162 'slave address I2cwbyte Adr1 'address of EEPROM I2cwbyte Adr0 'address of EEPROM I2cwbyte Value 'value to write I2cstop 'stop condition Waitms 10 'wait for 10 milliseconds End Sub Sub Read_eeprom_bank1 Adr0 = Address And 255 Shift Address , Right , 8 Adr1 = Address And 255 I2cstart 'generate start I2cwbyte 162 'slave address I2cwbyte Adr1 'address of EEPROM I2cwbyte Adr0 'address of EEPROM I2cstart 'repeated start I2cwbyte 163 'slave address (read) I2crbyte Value , Nack 'read byte I2cstop 'generate stop End Sub Sub Send_all If Licznik > Limit Then Licznik1 = Licznik - Limit Decr Licznik1 Licznik0 = Limit - 1 Else Licznik1 = 0 Licznik0 = Licznik - 1 End If For Licz = 0 To Licznik0 Address = Licz Call Read_eeprom_bank0 Print Value Next If Licznik1 > 0 Then For Licz = 0 To Licznik1 Address = Licz Call Read_eeprom_bank1 Print Value Next End If End Sub Sub Save_temp If Licznik < Limit Then Address = Licznik Value = Tnew1 Call Write_eeprom_bank0 Incr Licznik Address = Licznik Value = Tnew2 Call Write_eeprom_bank0 Incr Licznik Else Licznik1 = Licznik - Limit Address = Licznik1 Value = Tnew1 Call Write_eeprom_bank1 Incr Licznik Licznik1 = Licznik - Limit Address = Licznik1 Value = Tnew2 Call Write_eeprom_bank1 Incr Licznik End If End Sub Sub Read_temp Reset Light Licz = Sensors - 1 For Sensor = 0 To Licz Call Read_sensor Call Save_temp Next Set Light End Sub Sub Read_sensor If Sensor = 0 Then 1wreset T0 1wwrite &HCC T0 'skipping serial number 1wwrite &H44 T0 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T0 1wwrite &HCC T0 'skipping serial number 1wwrite &HBE T0 'read converted temperature Tnew1 = 1wread(t0) 'read first byte from sensor Tnew2 = 1wread(t0) 'read second byte from Tsensor 1wreset T0 End If If Sensor = 1 Then 1wreset T1 1wwrite &HCC T1 'skipping serial number 1wwrite &H44 T1 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T1 1wwrite &HCC T1 'skipping serial number 1wwrite &HBE T1 'read converted temperature Tnew1 = 1wread(t1) 'read first byte from sensor Tnew2 = 1wread(t1) 'read second byte from Tsensor 1wreset T1 End If If Sensor = 2 Then 1wreset T2 1wwrite &HCC T2 'skipping serial number 1wwrite &H44 T2 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T2 1wwrite &HCC T2 'skipping serial number 1wwrite &HBE T2 'read converted temperature Tnew1 = 1wread(t2) 'read first byte from sensor Tnew2 = 1wread(t2) 'read second byte from Tsensor 1wreset T2 End If If Sensor = 3 Then 1wreset T3 1wwrite &HCC T3 'skipping serial number 1wwrite &H44 T3 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T3 1wwrite &HCC T3 'skipping serial number 1wwrite &HBE T3 'read converted temperature Tnew1 = 1wread(t3) 'read first byte from sensor Tnew2 = 1wread(t3) 'read second byte from Tsensor 1wreset T3 End If If Sensor = 4 Then 1wreset T4 1wwrite &HCC T4 'skipping serial number 1wwrite &H44 T4 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T4 1wwrite &HCC T4 'skipping serial number 1wwrite &HBE T4 'read converted temperature Tnew1 = 1wread(t4) 'read first byte from sensor Tnew2 = 1wread(t4) 'read second byte from Tsensor 1wreset T4 End If If Sensor = 5 Then 1wreset T5 1wwrite &HCC T5 'skipping serial number 1wwrite &H44 T5 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T5 1wwrite &HCC T5 'skipping serial number 1wwrite &HBE T5 'read converted temperature Tnew1 = 1wread(t5) 'read first byte from sensor Tnew2 = 1wread(t5) 'read second byte from Tsensor 1wreset T5 End If If Sensor = 6 Then 1wreset T6 1wwrite &HCC T6 'skipping serial number 1wwrite &H44 T6 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T6 1wwrite &HCC T6 'skipping serial number 1wwrite &HBE T6 'read converted temperature Tnew1 = 1wread(t6) 'read first byte from sensor Tnew2 = 1wread(t6) 'read second byte from Tsensor 1wreset T6 End If If Sensor = 7 Then 1wreset T7 1wwrite &HCC T7 'skipping serial number 1wwrite &H44 T7 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T7 1wwrite &HCC T7 'skipping serial number 1wwrite &HBE T7 'read converted temperature Tnew1 = 1wread(t7) 'read first byte from sensor Tnew2 = 1wread(t7) 'read second byte from Tsensor 1wreset T7 End If If Sensor = 8 Then 1wreset T8 1wwrite &HCC T8 'skipping serial number 1wwrite &H44 T8 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T8 1wwrite &HCC T8 'skipping serial number 1wwrite &HBE T8 'read converted temperature Tnew1 = 1wread(t8) 'read first byte from sensor Tnew2 = 1wread(t8) 'read second byte from Tsensor 1wreset T8 End If If Sensor = 9 Then 1wreset T9 1wwrite &HCC T9 'skipping serial number 1wwrite &H44 T9 'start convert temperature Waitms 250 'conversion time Waitms 250 'conversion time Waitms 250 'conversion time 1wreset T9 1wwrite &HCC T9 'skipping serial number 1wwrite &HBE T9 'read converted temperature Tnew1 = 1wread(t9) 'read first byte from sensor Tnew2 = 1wread(t9) 'read second byte from Tsensor 1wreset T9 End If End Sub