Calcul de CRC Soumis par Administrator 15-12-2007 Dernière mise à jour : 17-12-2007
Ce code permet d'introduire un calcul de CRC, utile lors d'une transmission sans fil par exemple. Le but est d'inclure une valeur calculée lors de l'émission dans le message envoyé. Le récepteur refera le calcul et comparera le résultat obtenu à la valeur reçue : si les deux valeurs diffèrent, on pourra considérer que le message reçu est mauvais.
symbol tmp = b5 symbol tbyte = b6 symbol k
= w5 'b10 b11
symbol crc = w4 'b8 b9 symbol POLYNOMIAL = $A001 'other possible value : $8408
'usage: 'crc can be initialized to 0 or to (hex)FFFF, but the same 'initialization must be done in the TX code as in the RX code.
'Before sending the serial data, each byte is put in the 'tbyte variable, and a call to CrcAdd is done. When all 'bytes have been processed, the data is sent, and the 'CRC is also sent as the 2 last bytes, or anywhere in the 'message. 'When the message is received, the same procedure is 'applied (ie each byte, in the same order, is put in the 'tbyte variable and a call to CrcAdd is done). 'The CRC computed is compared to the CRC received : 'if they are the same, one can consider the serial data 'received as correct. If they differ, the message received http://picaxe.free.fr