User manual

117
Program Notes
* Initialization of GPC card */
if(port_number == 1) PORTADD=0x3F0;
if(port_number == 2) PORTADD=0x2F0;
if ((port_number >= 3) && (port_number <=5))
{
PORTADD=0x300;
outportb(0x303,0xC0);/* Mode=2 of 8255 */
outportb(0x303,0x05);/* PC2=1 of 8255 :Disable IRQ2 */
outportb(0x301,0xFF);/* PB0=1 of 8255 :Sending Enable RS-
485*/
outportb(0x303,0x01);/* PC0=1 of 8255 :Serial Input Enable*/
if(port_number == 3) outportb(0x303,0x02);/* PC1=0 of 8255
:Select RS-232 */
if(port_number == 4) outportb(0x303,0x03);/* PC1=1 of 8255
:Select RS-485 */
if(port_number == 5) outportb(0x303,0x00);/* PC0=0 of 8255
:Disable SerialInput*/
}
else
outportb(PORTADD+0x09,(inportb(PORTADD+0x09)&0xF0));/
*Disable Interrupt*/
/* Initialization of USART-Chip : 8250 */
if (port_number != 5)
{
outportb(PORTADD+0x0B,0x80);/* Set of DLAB=1 */
outportb(PORTADD+0x09,0x00);/* Set of High Byte DIVISOR */
outportb(PORTADD+0x08,DIVISOR);/* Set of Low Byte DIVISOR
*/
outportb(PORTADD+0x0B,0x03); /* Parity=None/Stop=1/
Length=8 */
}
/* Processing communication of Read & Write */
for( ; ; )
{
printf("----------------\nPLC-ID (CPU ID) :");
scanf("%d",&PlcID);
Mword_reading();
Kword_writing();
}
}
void RR_occuring(void)
{
receiving_frame[2]=0;
receiving_frame[3]=1;
receiving_frame[4]=0;
}
void Trsport(unsigned int data)
{
if (port_number == 5) outportb(PORTADD,data);
else outportb(PORTADD+0x08,data);
}
unsigned int Recport(void)
{
unsigned int dt;
if (port_number == 5) dt=inportb(PORTADD);
else dt=inportb(PORTADD+0x08);
return(dt);
}
BOOL sending_occuring(void)
{
BOOL tf;
if (port_number == 5) tf=((inportb(PORTADD+0x02) &
0x80)==0x80);
else tf=((inportb(PORTADD+0x0D) & 0x20)==0x20);
return(tf);
}
BOOL receiving_occuring(void)
{
BOOL rf;
if (port_number == 5) rf=((inportb(PORTADD+0x02) &
0x20)==0x20);
else rf=((inportb(PORTADD+0x0D) & 0x01)==0x01);
return(rf);
}
void Crc16(unsigned int data)
{
unsigned int i;
Crc=Crc^(data & 0x00FF);
for(i=0;i<=7;i++)
{
if((Crc & 0x0001) == 0x0001) Crc=(Crc>>1)^0xA001; /* 0x0001 :
multi-nominal expression */
else Crc=Crc>>1;
}
}
GPC-300 card Setting (8255chip setting)
Uses the communication card that is connected, and sets the environment
according to the PLC communication specifications, so that
communication is possible.
CPU-ID: Input PLC ID (0 to 255)
Reads the register value for the M area (M0 to M127)
Stores the value for the M area in the K area. (K0 to K127)
RR (Request Response) request function
Sends data to the communication port.
Reads the received data from the communication port.
Outputs the data when a Send event occurs..
Inputs the data when a Receiver event occurs.
CRC calculation
Encodes the communication data in the byte stream. Any completed
communication function will be attached to the latest frame or will be
compared with the attached CRC to check for data errors.
(Note: The CRC method can be implemented in several ways within the
rule specified as shown in the left code.)