PIC DAS User Instructions
By: Steve Hageman - shageman@sonic.net
PIC DAS Software Support
The software support for the PIC DAS ranges from native RS232
Prints and Inputs as would be used with a DOS based BASIC to an
ActiveX control [1] that I developed to make Windows programming more
automated. In addition to control with more traditional programming
languages, the PIC DAS may be controlled with any Terminal Emulator
(such as Hyper-terminal, supplied with Windows).
The PIC DAS has a built in power switch that is connected to the
DTR line of the RS232 connection. When the DTR is low (as it usually
is when a COM port is closed) the power to the PIC DAS will be off.
When the COM port that the PIC DAS is connected to is opened (which
usually asserts the DTR line, even with no handshaking) the battery
is connected to the internal circuits of the PIC DAS powering it up
(of course all previous settings are forgotten when the power is
cycled).
In all there are ten commands that the PIC DAS understands. Seven
of these have to do with the Digital I/O, two deal with the analog
I/O and one is an identification command.
The command structure to the PIC DAS is as follows,
COMMAND [Parameter 1] [Parameter 2] {CR}
The command is always required however it may be abbreviated to
just the first two characters. A space character follows the command
if required for the command Parameter 1. Likewise a space is required
between parameter 1 and 2. The command is finished and executes when
a Carriage Return is received by the PIC DAS.
Note that not all commands have parameters. Commands may have
none, one or two parameters. If the proper number of parameters are
not received by the PIC DAS the results of the command will be
unpredictable.
In QBasic [2] the Direction command would be sent as,
PRINT #1 “DIR 255”
When the print command finishes, it terminates the string with a
carriage return and the PIC DAS then parses the command and executes
it. As was stated above, alternative methods of sending the command
are,
PRINT #1 “DI 255”
PRINT #1 “dir 255”
PRINT #1 “di 255”
Remember only the first two characters of the command are looked
at and the commands are not case sensitive.
The standard mode is for the PIC DAS to execute the command then
send back any data (if any) followed by a carriage return (or a Line
Feed if UNIX Mode is set). Even if no data is sent back a change
return is returned, this can be used to keep a really fast PC from
getting ahead of the PIC DAS.
If the PIC DAS encounters a command it does not recognize, it
sends back the string “UNKNOWN COMMAND”. This can be useful in
debugging code that should be working but isn’t.
For Windows programming I have written an ActiveX control, while
it is possible to work directly with the serial port under Windows,
The ActiveX control reduces every PIC DAS command to a simple single
function call. ActiveX controls are like component plug-in’s. They
are reusable libraries of commands that are usable across a wide
variety of Windows applications and programming languages. Even the
spreadsheet Excel can use the ActiveX control to control the PIC DAS
and all modern 32-bit Windows programming languages can use ActiveX
technology.
Table 1 - PIC DAS Command Summary
Command
|
Parameter 1
|
Parameter 2
|
Description
|
DIR
|
num
|
n/a
|
Sets the data direction on the digital I/O port. num = 0
to 255. 0 = Output, 1 = Input
|
BSET
|
pin
|
n/a
|
Sets pin to a logic 1
|
BCLEAR
|
pin
|
n/a
|
Clears pin to a logic 0
|
BIN
|
pin
|
n/a
|
Returns the state of pin 1 or 0
|
IN
|
n/a
|
n/a
|
Returns the entire port as a byte. Returns the port value
(0-255)
|
OUT
|
num
|
n/a
|
Sets the entire port to byte num
|
PULLUP
|
state
|
n/a
|
state = 1 for pull-ups on, state = 0 for pull-ups off
|
AIN
|
ch
|
n/a
|
Reads A/D channel ch (0-7). Returns the A/D code read
(0-4095)
|
AOUT
|
ch
|
val
|
Sets D/A channel ch (0-3) to value val (0-4095)
|
VER
|
n/a
|
n/a
|
Returns a string identifying the firmware version
|
Note: All commands and states are reset when the power is cycled
to the PIC DAS.
Note: The command parser in the PIC DAS actually only decodes the
first two letters in the command string. For example: DIR 255 works
exactly the same as sending DI 255 to the PIC DAS. This is perhaps a
less readable but faster form of communication, especially for the
longer commands.