Programming
the projects with BBC BASIC for Windows
For any program to work you must have installed the K8055D.dll file
supplied
with the board. The latest version of this program can be found on
Velleman's website.
To access the separate routines in the K8055D.dll library, BBC BASIC
uses the SYS
command. The process is quite simple and an examples or two will make
the point. To start any program, the card address has to be supplied to
the
system. Somewhere in your program should be a PROCinit which gets
called at the very beginning. This finds out the start addresses of the
various routines and assigns variables to them, which can then be
called from BASIC. For instance, somewhere in the K8055D.dll library is
a routine which sets a single output port high or low. In Velleman's
documentation this routine is called "SetDigitalChannel'. Two lines of
programming will fetch the address of this routine. First you have to
find the address of the library routine with
SYS"LoadLibrary","K8055D.dll"
TO K8055_Board%
The looked for address is now in the BASIC variable K8055_Board% You can now look for the address of the desired subroutine.
Like this:
SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel"
TO K8055_SetDigitalChannel%
You can now set or clear any output port with
SYS K8055_SetDigitalChannel%,Port%
where Port% is any number from 1 to 8, representing the
number of the port you want to control.
Below is my procedure,
which is part of every program. It contains all possible calls in the
same order as in the manual, so it should be easy enough to
cross-reference.
Here is a link to the code:
180 DEFPROCK8055_init
190 REM Typing errors in routine name do not generate an error message - they just hang up the program.
200 REM These are all the system calls in the order found in the manual
210 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
220 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
230 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
240 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
250 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
260 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
270 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
280 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
290 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog
300 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
310 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog" TO K8055_SetAllAnalog%
320 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
330 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
340 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
350 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
360 SYS"GetProcAddress",K8055_Board%,"SetAllDigital" TO K8055_SetAllDigital%
370 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
380 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital" TO K8055_ReadAllDigital%
390 SYS"GetProcAddress",K8055_Board%,"ResetCounter" TO K8055_ResetCounter%
400 SYS"GetProcAddress",K8055_Board%,"ReadCounter" TO K8055_ReadCounter%
410 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime" TO K8055_SetCounterDebounceTime%
420 ENDPROC
Line 210 supplies the address of the link library, the
following lines interrogate the link library for the addresses of the
individual routines and assign them to BBC Basic variables.. If for instance you want to read the value of
analogue channel 1, you can now use:
SYS K8055_ReadAnalogue%,1 TO Value%
Value% will now contain a number between 0 and 255, reflecting the
voltage at the analogue port. To do the same thing with analogue port
2 you would use:
SYS K8055_ReadAnalogue%,2 TO Value%
Some calls to not supply or return values, they just
have a
single function. For instance, to clear all digital channels you simply
use:
SYS K8055_ClearAllDigital%
The various programs supplied with the projects will hopefully make
things even clearer. Notice the routine at 'OpenDevice'. All your
programs should begin with
the line. I have found that during develiopment of a program, it is a good idea to use the line
SYS K8055_CloseDevice%
This makes sure that the device is closed, as it may be still open from a previous error.
SYS K8055_OpenDevice%,N%
will open the device, where N% is the address of your Velleman K8055 board.
This
can be between 0 and 3 and is set with two link switches on the PCB. If
you use two different boards at the same time, they should obviously
have different addresses and each command must be called in turn. Say
you wanted to set Port 1 on two different Velleman boards with
addresses 0 and 1. This would look like this:
SYS K8055_OpenDevice%,0
SYS K8055_SetDigitalChannel%,1
SYS K8055_CloseDevice%,0
SYS K8055_OpenDevice%,1
SYS K8055_SetDigitalChannel%,1
SYS K8055_CloseDevice%,1
Have fun.
|