ASDA-A3 MODBUS Communication
9-13
9
CRC program example:
This function calculates the CRC value in the C language. It needs two parameters:
unsigned char* data;
unsigned char length
//The function returns the CRC value as a type of unsigned integer.
unsigned int crc_chk(unsigned char* data, unsigned char length) {
int j;
unsigned int reg_crc=0xFFFF;
while( length-- ) {
reg_crc^= *data++;
for (j=0; j<8; j++ ) {
if( reg_crc & 0x01 ) {
/*LSB(bit 0 ) = 1 */
reg_crc = (reg_crc >> 1)^0xA001;
} else {
reg_crc = (reg_crc>>1);
}
}
}
return reg_crc;
}
Example of a PC communication program:
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<process.h>
#define PORT 0x03F8
/* the address of COM 1 */
#define THR 0x0000
#define RDR 0x0000
#define BRDL 0x0000
#define IER 0x0001
#define BRDH 0x0001
#define LCR 0x0003
#define MCR 0x0004
#define LSR 0x0005
#define MSR 0x0006
unsigned char rdat[60];
/* read 2 data from address 0200H of ASD with address 1 */
unsigned char
tdat[60]={‘:’,’0’,’1’,’0’,’3’,’0’,’2’,’0’,’0’,’0’,’0’,’0’,’2’,’F’,’8’,’\r’,’\
n’};
void main() {
int I;
outportb(PORT+MCR,0x08);
/* interrupt enable */
outportb(PORT+IER,0x01);
/* interrupt as data in */
outportb(PORT+LCR,( inportb(PORT+LCR) | 0x80 ) );
/* the BRDL/BRDH can be access as LCR.b7 == 1 */
outportb(PORT+BRDL,12);
Содержание ASDA-A3 Series
Страница 15: ... This page is intentionally left blank ...
Страница 89: ...Wiring ASDA A3 3 38 3 Pin assignment for the CN1 quick connector J2 and J1 ...
Страница 91: ...Wiring ASDA A3 3 40 3 Wiring for CN1 quick connector and installation Installation ...
Страница 296: ...ASDA A3 Motion Control 7 99 7 Figure 7 3 4 6 ASDA Soft Speed fitting setting interface for creating E Cam table ...
Страница 320: ...ASDA A3 Motion Control 7 123 7 Figure 7 3 7 14 ASDA Soft rotary shear intermittent printing machine setting interface ...
Страница 373: ...Motion Control ASDA A3 7 176 7 This page is intentionally left blank ...
Страница 605: ...Parameters ASDA A3 8 232 8 This page is intentionally left blank ...
Страница 623: ...MODBUS Communication ASDA A3 9 18 9 This page is intentionally left blank ...
Страница 645: ...Absolute System ASDA A3 10 22 10 This page is intentionally left blank ...
Страница 661: ...Linear Motor ASDA A3 11 16 11 This page is intentionally left blank ...
Страница 793: ...Troubleshooting ASDA A3 13 48 13 This page is intentionally left blank ...
Страница 819: ...Specifications ASDA A3 A 26 A This page is intentionally left blank ...
Страница 841: ...Accessories ASDA A3 B 22 B This page is intentionally left blank ...