value. In the full program listing, you’ll find a similar function
for converting values to fixed-width hexadecimal strings.
You can use the BS1 DEBUG Viewer application with
any BS1 program that has at least one DEBUG instruction.
One of the interesting things you’ll see is the manipulation
of W6 by a program that uses GOSUB — W6 is used as the
RETURN stack. You’ll also see that the PINS outputs will
affect the corresponding PINS inputs.
SHOW ME THE TEMPERATURE
As most of you know, I am freakishly sensitive to the
temperature of my environment, hence, I’m constantly
looking at thermometers and adjusting the thermostat.
Perhaps I need professional help ... well, until that day, I
decided to make it easier to check the temperature where I
spend most of my day — in front of my computer.
What I did is take an eight-pin socket and extend the legs
with wire and a 1K resistor to match our standard DS1620 circuit, as shown in Figure 2. I popped a DS1620 into the socket
and plugged my temperature “spider” into the USB-BS1. Figure
3 shows the contraption plugged into my PC’s USB port.
From there, it was a very simple matter to gut and
convert the BS1 DEBUG Viewer application to display
temperature. Since we’ve used the DS1620 so many times
in the past, I’m not going to go through all the details — I
just want to cover shifting data out and in with the BS1.
The BS1 does not have the BS2’s SHIFTOUT and
SHIFTIN instructions, so we’re forced to synthesize these in
code. It’s really pretty simple. One of the things you’ll
notice about my BS1 programs is that I always start assigning variables at B2 (or W1). The reason for this is that I want
to leave B0 and B1 ( W0) free in case I need bit-level access
later ( W0 is the only variable that allows bit-level access).
That is the case with shifting subroutines; let’s have a look.
Here’s a subroutine that will shift an eight-bit value to
the DS1620, LSB first:
DIRS = %00000111
Clock = IsHigh
FOR shift = 1 TO 8
DQ = BIT0
PULSOUT Clock, 10
dByte = dByte / 2
The key section here is the middle of the FOR-NEXT
loop. Notice that DQ (the output pin to the DS1620) is set
to the value of BIT0. This is the LSB of B0 which, in this
program, is aliased as dByte. After placing the bit on the
DQ line, the clock line is blipped with PULSOUT, and then
the value of dByte is divided by two. Dividing by two is the
same as shifting right by one bit, so this process puts the
next highest bit into the BIT0 position.
Coding to shift bits in is similar. In the DS1620, the
temperature returned as a nine-bit, two’s-compliment
(if negative) value, with the MSB is used as the sign (0 for
positive, 1 for negative).
■ FIGURE 3. DS1620 Spider.
DIRS = %00000110\
tempC = 0
Clock = IsHigh
FOR shift = 1 TO 9
tempC = tempC / 2
Clock = IsLow
BIT8 = DQ
Clock = IsHigh
tempHi = -sign
As you can see, things are reversed. The first thing we
March 2006 15