Interfacing the Serial/RS-232 Port
Interfacing the Serial/RS-232 Port
Interfacing the Serial/RS-232 Port
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Interfacing</strong> <strong>the</strong> <strong>Serial</strong> / <strong>RS</strong><strong>232</strong> <strong>Port</strong> V5.0<br />
Then DTR, RTS and OUT 2 is taken active by <strong>the</strong> instruction outportb(PORT1 + 4,0x0B);.<br />
Some cards (Both of Mine) require OUT2 active for interrupt requests thus I'm normally always take it<br />
high. All that is left now is to set up our interrupts which has be deliberately left to last as to not interrupt<br />
our initialization. Our interrupt handler is only interested in new data being available so we have only set<br />
<strong>the</strong> UART to interrupt when data is received.<br />
Main Routine (Loop)<br />
Now we are left with,<br />
do {<br />
if (bufferin != bufferout){<br />
ch = buffer[bufferout];<br />
bufferout++;<br />
if (bufferout == 1024) bufferout = 0;<br />
printf("%c",ch);<br />
}<br />
if (kbhit()){<br />
c = getch();<br />
outportb(PORT1, c);<br />
}<br />
} while (c !=27);<br />
which keeps repeating until c = 27. This occurs when <strong>the</strong> ESC key is hit.<br />
The next if statement checks to see if a key has been hit. (kbhit()) If so, it gets <strong>the</strong> character<br />
using <strong>the</strong> getch() statement and outputs it to <strong>the</strong> receiver buffer. The UART <strong>the</strong>n transmits <strong>the</strong><br />
character to <strong>the</strong> modem. What we have assumed here, is that <strong>the</strong> person using <strong>the</strong> Communications<br />
Program can't type as fast as <strong>the</strong> UART can send. However if <strong>the</strong> program wishes to send something,<br />
<strong>the</strong>n a check should be made to see if BIT 5 of <strong>the</strong> Line Status Register is set before attempting to send a<br />
byte to <strong>the</strong> transmitter register.<br />
For more information on Interrupts, try Using Interrupts,<br />
http://www.geocities.com/SiliconValley/Bay/8302/interupt.pdf<br />
(62k)<br />
Determining <strong>the</strong> type of UART via software<br />
The type of UART you have installed in your system can be determined without even needing a<br />
screwdriver in most cases. As you can see from <strong>the</strong> Types of UARTs, each UART has minor differences,<br />
all we have to do it test <strong>the</strong>se.<br />
The first procedure we do is to set bit 0 to '1' in <strong>the</strong> FIFO control register. This tries to enable <strong>the</strong><br />
FIFO buffers. Then we read bits 6 and 7 from <strong>the</strong> interrupt identification register. If both bits are '1' <strong>the</strong>n<br />
<strong>the</strong> FIFO buffers are enabled. This would mean <strong>the</strong> UART is a 16550a. If <strong>the</strong> FIFO's were enabled but<br />
not usable <strong>the</strong>n it would be a 16550. If <strong>the</strong>re is no FIFO buffer enabled it is most likely to be a 16450<br />
UART, but could be a 8250, 8250A or 8250B on very old systems.<br />
<strong>Interfacing</strong> <strong>the</strong> <strong>Serial</strong> / <strong>RS</strong><strong>232</strong> <strong>Port</strong> V5.0 Page 31