' ' Program: RF Receiver module ' Author: (c) 2008 by A Fox Consulting & Design ' http://www.afox-consulting.com ' Date: 01/23/2008 ' ' {$STAMP BS2} ' {$PBASIC 2.5} _RFIn PIN 0 _LED PIN 1 _LED2 PIN 2 _LED3 PIN 3 BAUD CON 16780 ' N2400 junk CON $55 ' Wake-up sync CON $83 ' This is our 16-byte data packet we will use for our RF ' communications. Format: ' b00 b01 b02 b03 b04 b05 b06 b07 b08 b09 b10 b11 b12 b13 b14 b15 ' $83 ...................data................................ CRC DataPacket VAR Byte DataBlock VAR Byte(14) crc_in VAR Byte i VAR Nib j VAR Nib k VAR Byte b VAR Byte crc VAR Byte DIRA = %0110 Main: SERIN _RFIn, BAUD, [WAIT(sync), STR DataBlock\14, crc_in] DataPacket = sync ' DEBUG "Data Packet: " ' FOR i = 0 TO 15 ' DEBUG DEC DataPacket(i)," " ' NEXT ' DEBUG CR IF DataBlock(0) = "F" THEN ' Check CRC GOSUB CalcCRC IF crc = crc_in THEN PULSOUT _LED, 25000 ' Flash blue LED for 50ms. ELSE PULSOUT _LED2, 25000 ' Flash yellow LED for 50ms. ENDIF ELSE PULSOUT _LED3, 25000 ' Flash red LED for 50ms. ENDIF GOTO Main CalcCRC: crc = 0 FOR i = 0 TO 13 b = DataBlock(i) FOR j = 0 TO 7 k = b ^ CRC & %0001 IF k > 0 THEN k = $8C crc = crc >> 1 ^ k b = b >> 1 NEXT NEXT RETURN