DM5210 analog input module 4-8 RTD Embedded Technologies, Inc.
Programming the DM210/DM5210
This section gives you some general information about programming and the 210/5210, and then walks you
through the major 210/5210 programming functions. These descriptions will help you as you use the example
programs included with the module and the programming flow diagrams at the end of this chapter. All of the pro-
gram descriptions in this section use decimal values unless otherwise specified.
The 210/5210 is programmed by writing to and reading from the correct I/O port locations on the module. These
I/O ports were defined in the previous section. Most high-level languages such as BASIC, Pascal, C, and C++, and of
course assembly language, make it very easy to read/write these ports. The table below shows you how to read from
and write to I/O ports using some popular programming languages.
Language
Rea d
Wr ite
BAS IC
Data=INP(Address)
OUT Address,Data
Turbo C
Data=inportb(Address)
outportb(Address,Data)
Turbo Pascal
Data:=Port[Address]
Port[Address]:=Data
Assemb ly
mov dx,Address
in al,dx
mov dx,Address
mov al,Data
out dx,al
Language
Modules
Integer Division
AND
OR
C
%
a = b % c
/
a = b / c
&
a = b & c
|
a = b | c
Pascal
MOD
a := b MOD c
DIV
a := b DIV c
AND
a := b AND c
OR
a := b OR c
BASIC
MOD
a = b MOD c
\
a = b \ c
AND
a = b AND c
OR
a = b OR c
In addition to being able to read/write the I/O ports on the 210/5210, you must be able to perform a variety of
operations that you might not normally use in your programming. The table below shows you some of the operators
discussed in this section, with an example of how each is used with Pascal, C, and BASIC. Note that the modulus
operator is used to retrieve the least significant byte (LSB) of a two-byte word, and the integer division operator is
used to retrieve the most significant byte (MSB).
Many compilers have functions that can read/write either 8 or 16 bits from/to an I/O port. For example, Turbo
Pascal uses Port for 8-bit port operations and PortW for 16 bits, Turbo C uses inportb for an 8-bit read of a port
and inport for a 16-bit read. Be sure to use only 8-bit operations with the 210/5210!
Clearing and Setting Bits in a Port
When you clear or set one or more bits in a port, you must be careful that you do not change the status of the
other bits. You can preserve the status of all bits you do not wish to change by proper use of the AND and OR binary
operators. Using AND and OR, single or multiple bits can be easily cleared in one operation.
To clear a single bit in a port, AND the current value of the port with the value b, where b = 255 - 2
bit
.
Example: Clear bit 5 in a port. Read in the current value of the port, AND it with 223
(223 = 255 - 2
5
), and then write the resulting value to the port. In BASIC, this is programmed as:
V = INP(PortAddress)
V = V AND 223
OUT PortAddress, V
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com