Clearing And Setting Bits In - Real Time Devices AD1200 User Manual

Table of Contents

Advertisement

Programming the 1200
This section gives you some general information about programming and the 1200 board, and then walks you
through the major 1200 programming functions. These descriptions will help you as you use the example programs
included with the board and the programming flow diagrams at the end of this chapter. All of the program descrip-
tions in this section use decimal values unless otherwise specified.
The 1200 is programmed by writing to and reading from the correct VO port locations on the board. 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 pors. The table below shows you how to read from
and write to I/O ports using some popular programming languages.
Language
REad
Write
BASIC
Data = INP(Address)
OUT Address, Data
Turbo C
Data = inportb(Address) outportb(Address,
Data)
Turbo Pascal
Data := Port[Address]
Port[Address] := Data
Assembly
mov dx, Address
in al, dx
mov dx, Address
mov al, Data
out dx, al
In addition to being able to read/write the I/O [nrts on the 1200, you must be able o 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).
Language
Modulus
Integer Divlsion
AND
OR
c
2 , = b o / o C
a = b / c
&
a = b & c
I
a = b l c
Pascal
MOD
a : = b M O D c
DIV
a : = b D l V c
AND
a : = b A N D c
OR
a : = b O R c
BASIC
MOD
a = b M O D c
\ (backslash)
a = b \ c
AND
a = b A N D c
OR
a = b O R c
Many compilers have functions that can read/write eittrer 8 or 16 bia 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 ofa port
and inport for a 16-bit read. Be sure to use only 8-bit operations with the 1200!
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 satus 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 = /JJ - 2tat.
Example: Clear bit 5 in a port. Read in the current value of the porr, AND itwith223
(223 =255 -X), and then write the resulting value to the port. In BASIC, ttris is programmed as:
V = I N P ( P o r t A d d r e s s )
V = V A N D 2 2 3
O U T P o r t A d d r e s s ,
V
4-9

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ada1200

Table of Contents