Go to Triangle Digital Support Home Page TDS2020F TECHNICAL MANUAL
Hardware support
Parallel input & output
Live website search
Enter key words
 

PARALLEL INPUT & OUTPUT

DEFINITIONS

!

( n a - )

Write the 16-bit n to address a and a+1, a is even

!ODD

( n a - )

Same but a can be odd address

?BIT

( ca n - f )

Test bit n of address ca

@

( a - n )

Fetch 16-bit n from address a and a+1, a is even

@ODD

( a - n )

Same but a can be odd address

C!

( n a - )

Write lower byte of n to output byte address a

C@

( a - n )

Fetch lower byte of n from input byte address a

CFIGM

(   - a )

User variable with same content as configuration register for ports A & B

ONE

( a n - )

Set bit n (0 to 7) of byte address a to logic 1

PC@

( a - n )

Fetch the lower byte of n from input byte address a. Use with Ports A & B and other peripherals which use the E clock for synchronisation

PC!

( n a - )

Write the lower byte of n to output byte address a. Use with Ports A & B and other peripherals that use the E clock for synchronisation

ZERO

( a n - )

Clear bit n (0 to 7) of byte address a to logic 0

ALLOCATING I/O BITS

The parallel port capability of TDS2020F depends on whether the analog and other facilities are used or not. There can be up to 41 bits of input or output, PIN CONNECTIONS, page 38, has details. This is a summary:

 

Port A

All 8 bits input or all 8 bits output.

Port B

All 8 bits input or all 8 bits output. Alternatively can be used for external matrix keypad.

Port 1

Bits 4 5 6 & 7 can be individually inputs or outputs, bit 0 input only. Also used for on-card clock/RAM, I2C bus and external masked interrupts. See ABOUT THE I 2C BUS, page 119.

Port 7

The 8 bits can be individually inputs or outputs. Also can be used for timer functions.

Port 8

All 8 bits input only. Also can be used for A to D converter.

Port 9

Bits 2 3 4 & 7 can be individually inputs or outputs. Also used for serial I/O and D to A converter.

 

In allocating I/O study the pin connections and circuit diagram to make sure that pins are not used that have second functions needed later.

DRIVE CAPABILITY & INPUT LEVELS

See section 20 in the Hardware Manual for more electrical specifications.

 

INPUTS

 

Logic 1 Input

Logic 0 Input

Port A

min 3.5V/5�A

max 1.5V/5�A

Port B

min 3.5V/5�A

max 1.5V/5�A

Port 1

min 2.2V/1�A

max 0.8V/1�A

Port 7

min 3.5V/1�A

max 1.0V/1�A

Port 8

min 2.2V/1�A

max 0.8V/1�A

Port 9

min 2.2V/1�A

max 0.8V/1�A

 

Port 7 has Schmitt trigger inputs VT- 1.0 to 2.5V and VT+ 2.0 to 3.5V. There is a guaranteed minimum of 0.4V hysteresis. Maximum input capacitance on parallel ports is 15pF.

 

OUTPUTS

 

Logic 1 Output

Logic 0 Output

Port A

min 2.8V @ 1.0mA

max 0.4V @ 3.2mA

Port B

min 2.8V @ 1.0mA

max 0.4V @ 3.2mA

Port 1

min 3.5V @ 1.0mA

max 0.4V @ 1.6mA

Port 7

min 3.5V @ 1.0mA

max 0.4V @ 1.6mA

Port 9

min 3.5V @ 1.0mA

max 0.4V @ 1.6mA

DIRECTION OF PORTS A & B

At power-up all are inputs, you must set up any outputs needed. In the data direction registers a 1 means output and a 0 is input. For Port A and Port B use the write-only register at address hex 81F0. This has 3 bits:

 

Bit 0

0=Port A input (all 8 bits)

1=Port A output (all 8 bits)

Bit 1

0=Port B input (all 8 bits)

1=Port B output (all 8 bits)

Bit 2

0=Not keypad

1=Keypad mode

 

A copy of the content of address 81F0 should always be written to the user variable CFIGM . You can then change direction on just Port A or Port B without affecting the direction of the other. Read CFIGM , then AND or OR to give the new value, and put it to both address 81F0 and CFIGM . This is necessary because of the write-only nature of 81F0. You can always get its value from CFIGM , it is a mirror of the content of 81F0. Note that address 81F0 is a single byte, but CFIGM is a 16-bit word (as are all user variables). For example:

 

To set A and B as outputs:

3 DUP CFIGM ! $81F0 PC!

 

To change Port B to input:

CFIGM @ 5 AND DUP CFIGM ! $81F0 PC!

 

Posts A and B have an unspecified direction at power-up, but will be inputs within 200ms. External circuitry will need to take this into account.

ADDRESSING INPUT & OUTPUT

The ports are all memory-mapped and have these addresses in hex:

 

Input/Output

Data

Direction Register (1=output 0=input)

Port A

81E0

81F0 bit 0 (for all 8 bits of Port A)

Port B

81D0

81F0 bit 1 (for all 8 bits of Port B)

Port 1

FF82

FF80

Port 7

FF8E

FF8C

Port 8

FF8F

None, input only

Port 9

FFFF

FFFE

 

It is usually convenient to stay in the DECIMAL base and to define hex characters with the $ prefix. E.g. to output decimal 24 to Port 7:

 

24 $FF8E C!

 

Whenever you use a 16-bit input or output with @ or ! the top byte on the stack (which is the left two digits of the hex number) will be taken from, or put to, the lesser of the two adjacent addresses. The other byte corresponds to the greater of the two addresses.

Take care when using @ or ! because they will only work if the address is even. For example it is permissible to set both data direction register and data output on Port 9 with the instructions $FF34 $FFFE ! . This puts FF to address FFFE (direction register) and 34 to address FFFF (data register). Execution on an odd address will cause an ADDRESS ERROR trap. @ODD and !ODD can be used at any address, however.

The word pairs PC! C! and PC@ C@ have identical functions but the choice of which one to use depends on the memory being addressed. In summary:

 

C! and C@

for RAM and all ports on TDS2020F except Ports A and B

PC! and PC@

for Ports A & B and externally connected chips which have an E clock input, e.g. most graphics displays

 

If just one bit in an I/O or memory needs changing use the special bit set and clear words ONE and ZERO . Do not use them with write only addresses such as data direction registers, or with addresses shown above as needing special PC! & PC@ instructions, in particular ports A and B.

Parallel input and output can be almost indefinitely expanded, see the suggestions in PARALLEL INPUT & OUTPUT EXPANSION, page 299. This also has more software examples for using I/O.

USING ASSEMBLER FOR I/O

Fastest access to input and output is through assembly code. Simple primitive assembler I/O words can often result in the complete program running close to machine code speeds. Use MOVO, to output words or bytes. For input use MOVI, or any of the test, add, compare instructions etc. E.g.

 

CODE !PORT7 ( n - ) \ Output data n to Port 7

   @R7+ R3 MOVI,       \ pull n from stack to R3

   B $FF8E )) R3 MOVO, \ move bottom byte of n out

                       \ to address hex FF8E

 END-CODE

 

Now !PORT7 will write the top of the stack to Port 7. Use of the immediate with memory instructions can manipulate I/O bits directly and so are even faster. E.g.

 

CODE PULSE ( - ) \ Output narrow pulse on bit 7

                 \  of Port 7

   B $FF8E )) 7 ## BSETI, \ set bit to logic 1

   B $FF8E )) 7 ## BCLRI, \ clear it to logic 0

 END-CODE

 

For Ports A & B and other clock synchronised peripherals the assembler equivalents to PC! PC@ are as shown in these examples:

 

CODE !A ( n - ) \ Output byte n to Port A

   @R7+ R3 MOVI,          \ pull n from stack B

   $81E0 )) R3 MOVTPE,    \ MOVe byte To Peripheral

                          \ with E clock

 END-CODE

 

CODE @A ( - n ) \ Input byte n from Port A

   B $81E0 )) R3 MOVFPE,  \ MOVe byte From

                          \ Peripheral with E clock

   @-R7 R3 MOVO,          \ push n to stack

 END-CODE

Go to Triangle Digital Support Home Page Go to top   Next page