Here's one idea:I can't compile this let alone test it but it serves to show the genereal idea of a software only solution.Code:HighTime VAR WORD LowTime VAR WORD BitArray VAR WORD [2] LSB VAR BitArray.LowWord MSB VAR BitArrat.HighWord WaitForStartBit: GOSUB MeasureLow IF (LowTime < 9500) OR (LowTime > 10500) THEN WaitForStartBit ' 9.5-10.5ms qualifies GOSUB MeasureHigh IF (HighTime < 1500) OR (HighTime > 2500) THEN WaitForStartBit ' 1.5-2.5ms qualifies NextLevel: For i = 0 to 31 GOSUB MeasureLow IF (LowTime > 400) AND (LowTime < 800) THEN BitArray.0[i] = 1 ' 500-700us qualifies as 1 IF (LowTime > 1700) AND (LowTime < 2320) THEN BitArray.0[i] = 0 ' 1800-2200us qualifies as 0 NEXT LCDOUT $FE,$01, "HighWord", DEC MSB LCDOUT $FE,$C0, "LowWord", DEC LCB Pause 1000 Goto WaitForStartBit MeasureLow: LowTime = 0 While Signal = 1 : WEND ' Wait for low level While Signal = 0 ' Measure low level LowTime = LowTime + 100 ' Resolution is 100us, change if needed PauseUS 92 ' Tweak to calibrate, depends on actual loop time WEND RETURN MeasureHigh: HighTime = 0 WhileSignal = 0 : WEND ' Wait for low While Signal = 1 ' Measure high level HighTime = HighTime + 1 ' Resolution is 100us, change if needed PauseUS 92 ' Tweal to calibrate, depends on actual loop time WEND RETURN
Bookmarks