this should get close to it
Code:define OSC 48 some vars bits var byte[13] ' an array to hold the 100 bits I_data var PORTB.2 'lets call this the input bit_count var byte 'a subroutine bit_read: t4con=0 ' timer off tmr4=0 ' clear timer bit_count = 0 while ( i_data) : wend ' wait here till input goes idle while ( ! i_data) : wend 'wait here till input goes high to sync up t4con=$7e '256:1// count of 45 or so = 1mS while ( i_data) : wend ' wait here till input goes low t4con=0 ' timer off if (tmr4 >43 ) and (tmr4 < 47) then goto start_ok ' bit of latitude might need more goto bit_read start_ok: while bit_count < 100 tmr4=0 ' clear timer pir3.3=0 'clear timer overflow flag while ( ! i_data) : wend 'wait here till input goes high t4con=6 ; prescale 16 timer on while ( i_data) : wend ' wait here till input goes low t4con=0 ' timer off if pir3.3 then bits.0[bit_count]=1 ; ontime > 340 uS else bits.0[bit_count]=0 ' the ontime < 340 uS endif bit_count=bit_count+1 wend return




Bookmarks