I've tried to incorporate the code (modified to suit my variables) in post #17 so that it will display "NC" on an LCD if the sensor is faulty or not present... but it doesn't work.
This is the CRC check subs - the only change is the TempT variable insted of DQ
I then have this as the main part of my program loopCode:GetCRC: for x = 0 to 7 ; Get CRC for each of the 8 bytes DataByte = TempT[x] ; Assign array pointer using value of x gosub CalcCRC ; Get CRC value next x ; Repeat until all bytes are done if TempT[8] <> CRCCalc then ; Do the CRC values match? CRCError = 1 ; Set flag indicating a problem with this sensor else CRCError = 0 ; Set flag indicating no problem with this sensor endif CRCCalc = 0 ; Reset CRC calculation variable return ;--------------------- CRC Bit Calcuation Method ------------------------------- CalcCRC: for i = 0 to 7 ; Do for all 8 bits in DataByte DataBit = CRCCalc.0 ^ DataByte.0 ; XOR bit0 of DataByte and CRC DataByte = DataByte >> 1 ; Position DataByte for next bit test if DataBit = 0 then Shift ; If test bit not set, just shift CRCCalc CRCCalc = CRCCalc ^ $18 ; If set, account for EXOR feedback shift: CRCCalc = CRCCalc >> 1 ; Shift right the CRCCalc byte CRCCalc.7 = DataBit ; CRC bit 0 to bit bucket next i ; Data bit rotates into CRC bit 7 return
With teh DS18B20 connected I get a true temperature displayed on the screen, but If I remove the DS18B20 from the inpt pin the LCD displays 163.7c on the display (presumably it's the maximum value for a word variable and the the formulat applied to convert it to a temperature) rather than "NC"Code:gosub GetCRC ; Calculate the CRC for comparison OWOUT TEMPIN,1,[$CC,$44] HIGH TEMPIN PAUSE 1000 OWOUT TEMPIN,1,[$CC,$BE] OWIN TEMPIN,0,[TempT.LowByte,TEMPT.HighByte] TempC = (TempT*/1600) if CRCError = 1 then LCDout $FE,$80+5,"N/C " endif if CRCError = 0 then LCDout $FE,$80,"Temp ",DEC (TempC/100),".",#TempC dig 1,"C" endif
Any suggestions ?
EDIT:
OK I thought about it a bit more and realised I needed to read the sensor first and then do the check and then apply the if then condition.... but now all I get is "NC" on the screen even when the sensor is connected !




Bookmarks