7 example of crc-16 calculations – TOHO ELECTRONICS TTX-700 User Manual

Page 26

Advertising
background image

6.6.8 Changing the settings (SV or SV2) by communications during auto-tuning

Even if the settings (SV or SV2) used in control for auto-tuning are changed by communications,
the changes (SV or SV2) will not be changed until the auto-tuning ends.


6.7 Example of CRC-16 calculations

Following is an example of calculating CRC-16 with VisualBasic6.0.

Variables are declared as shown below.
VisualBasic6.0 cannot use code-free variables. It therefore uses code-equipped 16-bit integer
variables as data. Similarly, the CRC calculation results are entered into code-equipped 32-bit
integer variables.

Dim CRC As Long
Dim i, j, arry_count As Integer

Dim c_next, c_carry As LongDim crc_arry(64) As Integer


Then enter calculable data into the crc_arry(), and enter the number of data items into the arry_count.
After that, run the following program to cause the calculation results to enter the CRC.

i = 0
CRC = 65535
For i = 0 To arry_count
c_next = crc_arry(i)
CRC = (CRC Xor c_next) And 65535
For j = 0 To 7
c_carry = CRC And 1
CRC = CRC ¥ 2
If c_carry Then
CRC = (CRC Xor &HA001) And 65535
End If
Next
Next


To affix an error code to the end of the message, affix first the low-level byte and then the high-level
byte of the CRC.











26

Advertising