|
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 on the VIA chip, the data direction register which determines which of the eight lines are input and which are output and the input/output register - which connects the port to the outside world. The SWI used is called 'OS_Byte' and the first number we supply it with determines the direction of data flow: 150 is read and 151 is write.. To set all eight lines to be output use:
REMEMBER: 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:
You only need to set the register at &62 once in your program, not every time you write to the port, though it does no harm should you do it. To write to the output port use:
Where Value% is the number you want to write to the port and &60 is the offset of the port.
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:
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:
This can be abbreviated to Notice the two commas in front of Byte% - they must be there. Byte% will now contain whatever value was in the port register. Sometimes it is very useful to latch the port before reading it, this avoids spurious signals. Here is a small program which does this. As it stands, it simply prints the number found at the port to the screen.
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 address. 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:
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:
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:
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. |
Back to the start
|