Manual Number: 00650-146-1
Page 13
Chapter 5: Programming
Sample Programs
There are two sample programs installed with the diskette with the PCI-COM485/8 card. These
are:
Sample 1
This program is provided in C, Pascal, and QuickBASIC. It performs a test of the loopback feature
of the UART. It requires no external hardware and no interrupts.
Sample 2
This program is provided in C only and demonstrates interrupt-driven RS-485 half-duplex opera-
tion. The program requires at least two computers with one card in each and a two-wire cable
interconnecting them. That cable must connect the Tx pins from card 1 to the Rx pins respectively
of card 2 and the Tx pins from card 2 to the Rx pins at card 1.
Card 1
Card 2
RS-485 Programming
Programming the UART for RS-485 communication can be divided into three distinct sections:
initialization, reception, and transmission. Initialization deals with option setup on the chip includ-
ing baud rate selection. Reception deals with incoming-character processing which can be done
using either polling or interrupts. Transmission deals with the process of sending the data out.
Initialization
Initializing the chip requires knowledge of the UART’s register set. The first step is to set the baud
rate divisor. You do this by first setting the DLAB (Divisor Latch Access Bit) high. This bit is Bit
7 at Base A3. In C code, the call would be:
outportb(BA3,0x80);
You then load the divisor into Base A0 (low byte) and Base A1 (high byte). The
following equation defines the relationship between baud rate and divisor:
desired baud rate = (UART Clock Frequency) / (32 * divisor)