![Chino LT830 Series Скачать руководство пользователя страница 22](http://html.mh-extra.com/html/chino/lt830-series/lt830-series_instructions-manual_2602191022.webp)
−20−
6.3.5.2 Calculation of LRC
The data from its slave address to its end is calculated in the following procedure.
1) Create a message in RTU mode.
2) Add the start (slave address) to end of the data.
→
X
3) Complement X (bit reverse)
→
X
4) Add 1 (X = X + 1)
5) Add X as an LRC to the end of the message.
6) Convert the whole data to ASCII characters.
Example) For the data 02H 07H , LRC is F7H which will be 02H 07H F7H as a binary message,
so that the ASCII message will be 30H 32H 30H 37H 46H 37H .
Example1 )C programming
/***** LRC PROGRAM *****/
#include <stdio.h>
#include <conio.h>
void main(void)
{
unsigned short usData;
unsigned short usLrcData;
int
iDummy;
usLrcData = 0;
printf("Hex DATA ([q] = END) >¥n");
while( scanf("%x",&usData) != 0 ){
usL= usData;
usLrcData = usLrcData & 0xff;
}
usLrcData = usLrcData ^ 0xff;
usLrcData = us+;
usLrcData = usLrcData & 0xff;
printf( "LRC‑16 DATA = %xH ¥n", usLrcData );
iDummy = getch();
}