Programming

The User Port

This is fairly straight forward to program because the operating system does most of the work for you. Don't worry about the peculiar numbers - they are there for historical reasons. We need to make use of two registers, the data direction register which determines which of the eight lines are input and which are output and the actual port register.

To set all eight lines to be output use:

SYS"OS_Byte",151,&62,&FF

151 writes to a register, (150 reads from it). &62 is the number of the data direction register and &FF (1111 1111 in binary), puts a one into every location making all lines output. If you need four output lines and four input lines you would use:

SYS"OS_Byte",151,&62,&0F

You only need to set the register at &62 once in your program, not every time you write to the port. To write to the output port use:

SYS"OS_Byte",151,&60,Value

Where value is the pattern you want to write to the port and &60 is the number of the port. Here is a small example. Say you have built the LED board and want every other LED to be ON. The pattern in binary would be: 0101 0101 ie 55 in hexadecimal. Here is the program:

SYS"OS_Byte",151,&62,&FF: REM All eight lines output
SYS"OS_Byte",151,&60,&55: REM Turn every other line ON

A small program that counts from 0 to 255 and holds each state for half a second looks like this:

SYS"OS_Byte",151,&62,&FF : REM All lines output
FOR Count%= 0 TO 255
SYS"OS_Byte",151,&60,Count% : Write to port
TIME=0:REPEAT UNTIL TIME > 50: REM Waste time
NEXT

To read from the port you use:

SYS"OS_Byte",150,&60 TO ,,Byte%

Byte% will now contain whatever value was in the port register.


The Printer Port

Most of what I know about the printer port comes from a gentleman who contacted me years ago but I have lost his e-mail. Sorry sir.

Basically we only use two registers and the operating system does most of the work for us - like finding where precisely the port is and so on. To initiate the printer port use:

SYS"Parallel_Op",2,10,0

This will prepare it for output only. You need only do this once in your program. The port can be switched to input as well, more about that later. To write to the port use:

SYS"Parallel_Op",1,Value

This will send the second variable to the printer port. So the above program that counts to the user port looks like this for the printer port:

SYS"Parallel_Op",2,10,0 : REM All lines output
FOR Count%= 0 TO 255
SYS"Parallel_Op",1,Count% : Write to port
TIME=0:REPEAT UNTIL TIME > 50: REM Waste time
NEXT

That's all there is to it. If you built my LED board you have the ideal method to test your program.


Return to interfacing index

Back to the start
Tudor with sign