[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]

The DATA DIRECTION REGISTER has its location at 56579 ($DD03 hex). Each of the eight lines in the PORT has a BIT in the eight-bit DATA DIRECTION REGISTER (DDR) which controls whether that line will be an input or an output. If a bit in the DDR is a ONE, the corresponding line of the PORT will be an OUTPUT. If a bit in the DDR is a ZERO, the corresponding line of the PORT will be an INPUT. For example, if bit 3 of the DDR is set to 1, then line 3 of the PORT will be an output. A further example:

If the DDR is set like this:

			 BIT #: 7 6 5 4 3 2 1 0
			 VALUE: 0 0 1 1 1 0 0 0

You can see that lines 5,4, and 3 will be outputs since those bits are ones. The rest of the lines will be inputs, since those lines are zeros.

To PEEK or POKE the USER port, it is necessary to use both the DDR and the PORT itself.

Remember that the PEEK and POKE statements want a number from 0-255. The numbers given in the example must be translated into decimal before they can be used. The value would be:

		    2^5 + 2^4 + 2^3 = 32 + 16 + 8 = 56

Notice that the bit # for the DDR is the same number that = 2 raised to a power to turn the bit value on.

		     (16 = 2^4=2*2*2*2, 8 = 2^3=2*2*2)

The two other lines, FLAG1 and PA2 are different from the rest of the USER PORT. These two lines are mainly for HANDSHAKING, and are programmed differently from port B.

Handshaking is needed when two devices communicate. Since one device may run at a different speed than another device it is necessary to give the devices some way of knowing what the other device is doing. Even when the devices are operating at the same speed, handshaking is necessary to let the other know when data is to be sent, and if it has been received. The FLAG1 line has special characteristics which make it well suited for handshaking.

FLAG1 is a negative edge sensitive input which can be used as a general purpose interrupt input. Any negative transition on the FLAG line will set the FLAG interrupt bit. If the FLAG interrupt is enabled, this will


[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated May 25, 1998.