Calcul de CRC

k = POLYNOMIAL. CrcAdd1: crc = crc / 2 ^ k tbyte = tbyte / 2 next tmp return picaxe.free.fr http://picaxe.free.fr. Propulsé par Joomla! Généré: 26 July, 2018, 23:58.Missing:
3KB taille 3 téléchargements 267 vues
picaxe.free.fr

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

Propulsé par Joomla!

Généré: 29 October, 2018, 22:46

picaxe.free.fr

'is probably corrupt.

'Example: 'crc=$FFFF 'tbyte=first_byte 'gosub CrcAdd 'tbyte=second_byte 'gosub CrcAdd 'serout serout_pin, serout_speed, (first_byte,second_byte,b8,b9)

CrcAdd: for tmp = 0 to 7 k = tbyte ^ crc & 1 if k = 0 then CrcAdd1 k = POLYNOMIAL CrcAdd1: crc = crc / 2 ^ k tbyte = tbyte / 2 next tmp return

http://picaxe.free.fr

Propulsé par Joomla!

Généré: 29 October, 2018, 22:46