Serial Programming - upload.wikimedia....
Serial Programming - upload.wikimedia....
Serial Programming - upload.wikimedia....
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Serial</strong> DOS<br />
the Escape key will be used to quit the program, which will in fact be where most of<br />
the changes to the program will happen. We are also introducing for the first time<br />
direct output into the UART instead of going through the standard I/O libraries with this line:<br />
Port[ComPort[1] + THR] := Ord(OutputLetter);<br />
The Transmit Holding Register (THR) is how data you want to transmit gets into<br />
the UART in the first place. DOS just took care of the details earlier, so now we<br />
don't need to open a "file" in order to send data. We are going to assume, to keep<br />
things very simple, that you can't type at 9600 baud, or roughly 11,000 words per<br />
minute. Only if you are dealing with very slow baud rates like 110 baud is that going<br />
to be an issue anyway (still at over 130 words per minute of typing... a very fast typist indeed).<br />
program SimpleTerminal;<br />
uses<br />
Crt;<br />
const<br />
THR = 0;<br />
RBR = 0;<br />
LCR = 3;<br />
LSR = 5;<br />
Latch_Low = $00;<br />
Latch_High = $01;<br />
{Character Constants}<br />
NullLetter = #0;<br />
EscapeKey = #27;<br />
var<br />
ComPort: array [1..4] of Word absolute $0040:$0000;<br />
InputLetter: Char;<br />
OutputLetter: Char;<br />
begin<br />
Writeln('Simple <strong>Serial</strong> Data Terminal Program. Press "Esc" to<br />
quit.');<br />
{Change UART Settings}<br />
Port[ComPort[1] + LCR] := $80;<br />
Port[ComPort[1] + Latch_High] := $00;<br />
Port[ComPort[1] + Latch_Low] := $0C;<br />
Port[ComPort[1] + LCR] := $03;<br />
{Scan for serial data}<br />
OutputLetter := NullLetter;<br />
repeat<br />
if (Port[ComPort[1] + LSR] and $01) > 0 then begin<br />
InputLetter := Chr(Port[ComPort[1] + RBR]);<br />
Write(InputLetter);<br />
end; {if}<br />
if KeyPressed then begin<br />
OutputLetter := ReadKey;<br />
Port[ComPort[1] + THR] := Ord(OutputLetter);<br />
end; {if}<br />
until OutputLetter = EscapeKey;<br />
end.<br />
62