; ; Example program #1 for use with the OATLEY Electronics PICAXE Development System ; ; This program is an example of using a UHF Receiver to receive 3 bytes of data ; ; Author Jeff Monegal ; ; Microcontroller PICAXE 18X ; ; Compile date 28/3/2010 ; ;-------------------------------------------------------------------------------------------------- ; ; NOTES ; ;-------------------------------------------------------------------------------------------------- ; ; The 3 bytes of data to be transmitted are contained in the 3 byte registers. The checksum ; value is first calculated by exclusivly ORing byte_1 with byte_2. The result is stored in the ; checksum register which is then placed on the end of the data frame to be sent. A checksum is ; used to ensure that the received data is as error free as possible. At the receiver the checksum ; is compared with the result of exclusively OR ing the same 2 registers. ; ;-------------------------------------------------------------------------------------------------- symbol byte_1 = b2 symbol byte_2 = b3 symbol byte_3 = b4 symbol checksum = b5 symbol rx_checksum = b6 symbol led = 7 ;-------------------------------------------------------------------------------------------------- ; ; Here the received data frame comes in on pin 7. The PICAXE stores the data in the defined ; registers. Next the same 2 bytes are XOred to get a calculated RX checksum. Last this checksum ; value is checked against the TX calculated checksum. If the data frame was received succesfully ; then the 2 checksum values will be the same. start: serin 7,t2400,("code"),byte_1,byte_2,byte_3,checksum ;receive 4 bytes on pin7 rx_checksum = byte_1 xor byte_3 ;calculate rx checksum if checksum <> rx_checksum then data_error ;compare calculated checksum against rx'ed checksum high led ;turn on led to say data received OK ; User program goes in here ; The 3 data bytes can be used for what ever the programmer wants ; goto start data_error: byte_1 = 0 byte_2 = 0 byte_3 = 0 low led goto start ; The routine is exited with the 3 bytes of data stored in the 3 byte registers. If there was ; a checksum error the software ignors the 3 data bytes and exits the routine with the 3 data bytes ; all clear. To other parts of the program this will indicate the frame was not received correctly. ; ; It is also important to note that although only byte_1 and byte_3 have been used in the checksum ; calculations, any of the 3 bytes could have been used and even all 3 bytes could be used.