User`s manual

User’s Manual 47
4.2.4 RS-485 Serial Communication Sample Program
The following sample program illustrates the use of the RS-485 serial drivers. The sample
program shows a byte being transmitted, and then the RS-485 transceiver waits for a reply.
NOTE: If your version of Dynamic C is earlier than 6.55, see Technical Note 117, Jack-
rabbit (BL1800 Series) RS-485 Bulletin, for information on restrictions on using both
DA1 and RS-485 at the same time.
#define DINBUFSIZE 15
#define DOUTBUFSIZE 15
void main( void ){
int nEcho,nReply;
char cChar;
Jr485Init ();// Init RS485 Control (PD5)
serDopen ( 9600 );// Open Serial Port D
for (;;) {// Forever
for (cChar='a';cChar<='z';++cChar){
// Send Alphabet
Jr485Tx ();// Enable RS485 Transmitter
serDputc ( cChar );// Send Byte
while ((nEcho = serDgetc ()) == -1);
// Wait for Echo
Jr485Rx ();// Disable RS485 Transmitter
while ((nReply = serDgetc ()) == -1);
// Wait for Reply
printf ( "%02x -> %02x\n",nEcho,nReply );
}
}
}