ISR_Start: IF hasCmd = 1 THEN ISR_Exit ' exit if holding command IF rxCmd = 1 THEN Check_Bit ' receiving now? IF IR = 1 THEN ISR_Exit ' exit if IR line idle Start_Packet: rxCmd = 1 ' set rx flags rxBit = 1 cmdWork = 0 ' clear work vars bitWidth = 0 bitCount = 0 GOTO ISR_Exit Check_Bit: IF IR = 0 THEN Update_BitWidth ' still in bit? IF rxBit = 0 THEN ISR_Exit ' in idle period? rxBit = 0 ' no, clear bit flag IF bitCount > 0 THEN Test_DBit ' start or data bit? Test_SBit: IF bitWidth > 74 THEN Next_Bit ' proper start bit? rxCmd = 0 ' no, reset GOTO ISR_Exit Test_DBit: cmdWork = cmdWork >> 1 ' prep for next bit IF bitWidth < 34 THEN Next_Bit ' "1" bit? cmdWork.6 = 1 ' yes, set it Next_Bit: bitWidth = 0 ' clear for next bit INC bitCount ' update count IF bitCount < 8 THEN ISR_Exit ' done? hasCmd = 1 ' set available flag cmdCode = cmdWork ' copy work to output rxCmd = 0 ' clear rx flag GOTO ISR_Exit Update_BitWidth: INC bitWidth ' else inc width rxBit = 1 ' refresh in bit flag ISR_Exit: RETURNINT 104 ' 26 uS @ 4 MHz