28.12.2013 Views

Serial Programming - upload.wikimedia....

Serial Programming - upload.wikimedia....

Serial Programming - upload.wikimedia....

SHOW MORE
SHOW LESS

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 />

program Hello<strong>Serial</strong>;<br />

var<br />

DataFile: Text;<br />

begin<br />

Assign(DataFile,'COM1');<br />

Rewrite(DataFile);<br />

Writeln(DataFile,'Hello World');<br />

Close(DataFile);<br />

end.<br />

All of this works because in DOS (and all version of Windows as well... on this particular<br />

point) has a "reserved" file name called COM1 that is the operating system hooks into the<br />

serial communications ports. While this seems simple, it is deceptively simple. You still<br />

don't have access to being able to control the baud rate or any of the other settings for the<br />

modem. That is a fairly simple thing to add, however, using the knowledge of the UART<br />

discussed in the previous chapter <strong>Programming</strong> the 8250 UART 2 .<br />

To try something even easier, you don't even need a compiler at all. This takes advantage<br />

of the reserved "device names" in DOS and can be done from the command prompt.<br />

C:\>COPY CON COM1<br />

What you are doing here is taking input from CON (the console or the standard keyboard<br />

you use on your computer) and it "copies" the data to COM1. You can also use variations<br />

of this to do some interesting file transfers, but it has some important limitations. Most<br />

importantly, you don't have access to the UART settings, and this simply uses whatever the<br />

default settings of the UART might be, or what you used last time you changed the settings<br />

to become with a serial terminal program.<br />

4.3 Finding the Port I/O Address for the UART<br />

The next big task that we have to work with is trying to find the base "address" of the Port<br />

I/O so that we can communicate with the UART chip directly (see the part about interface<br />

logic in the Typical RS232-Hardware Configuration 3 module for information what this is<br />

about). For a "typical" PC system, the following are usually the addresses that you need to<br />

work with:<br />

<strong>Serial</strong> Port Name Base I/O Port Address<br />

IRQ (interrupt) Number<br />

COM1 3F8 4<br />

COM2 2F8 3<br />

COM3 3E8 4<br />

COM4 2E8 3<br />

2 http://en.wikibooks.org/wiki/<strong>Serial</strong>%20<strong>Programming</strong>%3A8250%20UART%20<strong>Programming</strong><br />

http://en.wikibooks.org/wiki/<strong>Serial</strong>_<strong>Programming</strong>%3ATypical_RS232-Hardware_<br />

3<br />

Configuration<br />

56

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!