DM5816/DM6816
RTD Embedded Technologies, Inc.
28
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 C, Pascal, 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 DM5816!
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. Note that most registers in the DM5816 cannot be read back; therefore, you must save the
value in your program.
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:
To
set
a single bit in a port, OR the current value of the port with the value b, where b = 2
bit
.
Example:
Set bit 3 in a port. Read in the current value of the port, OR it with 8 (8 = 2
3
),
and then write the resulting value to the port. In Pascal, this is programmed as:
Setting or clearing more than one bit at a time is accomplished just as easily. To
clear
multiple bits in a
port, AND the current value of the port with the value b, where b = 255 - (the sum of the values of the bits
to be cleared). Note that the bits do not have to be consecutive.
Summary of Contents for DM5816
Page 1: ...BDM 610010027 Rev A DM5816 DM6816 Triggered User s Manual...
Page 7: ...DM5816 DM6816 RTD Embedded Technologies Inc 7...
Page 15: ...DM5816 DM6816 RTD Embedded Technologies Inc 15 Fig 1 7 Base Address Switch S1...
Page 22: ...DM5816 DM6816 RTD Embedded Technologies Inc 22...
Page 42: ...DM5816 DM6816 RTD Embedded Technologies Inc 42 P3 Connector P6 Connector...