Stamp
information dialog like the one in Figure 4. Click on the
“Program” button to download the script data to the
FlexiPanel module. Note that there are no status or
completion messages provided by the configuration
software. Leave the mouse pointer over the program
dialog until it changes from an hourglass back to an
arrow (standard pointer) before proceeding.
Now we can test it. Start the program called
FlexiPanel IR. The working space will initially be blank.
Click on the “Read” button and, after a brief delay, the title
and controls will appear, as shown in Figure 1. Play with
the controls to see how they work and note that it really
wasn’t very difficult to create a nice, functional display.
Keep in mind that we’re just barely scratching the surface
of the capabilities with the VCP software.
The Host With the Most
Our host will, of course, be the BASIC Stamp
microcontroller — but if you have something else that is
capable of I2C communications, you can use it; you’ll just
need to adapt the code here for your target.
For this project, the BASIC Stamp has three tasks:
As you can see, this is pretty straightforward. We start
by sending the RdTemp instruction then read back the
current temperature. The value returned by the DS1621
will be in units of 0.5 degrees Celsius and will be shifted
left in the tempIn word. Shifting everything to the right by
seven bits takes care of the alignment. Conversion to
Celsius is really just a matter of removing the half-degree
bit, then correcting the upper bits of the tempC value if
the temperature is negative (sign bit will be 1 when
negative).
Converting to Fahrenheit uses an old Scott Edwards
trick from the DS1620, which starts by converting the
temperature to an absolute value. By doing this, we
maintain the proper two’s compliment format for
negative numbers. If you decide to add DEBUG or a
local display, be sure to use the SDEC modifier, in the
event the temperature is negative. (You must live in an
igloo if it is!)
With the current temperature in hand, we can send it
to the FlexiPanel module and receive any controls or
setting changes that may have happened since the last
access.
1. Read the current temperature from DS1621.
2. Exchange data with FlexiPanel module.
3. Process and update control outputs.
Okay, first things first. This is a temperature
controller we’re building, so reading the current
temperature is a priority. The DS1621 was selected so
that we could take advantage of the I2C bus that is
required by the FlexiPanel module.
Get_Temperature:
I2COUT SDA, Wr1621, [RdTemp]
I2CIN SDA, Rd1621, [tempIn.BYTE1, tempIn.BYTE0]
tempIn = tempIn >> 7
‘‘‘ Celsius
tempC = (tempIn / 2) | ($FF00 * sign)
‘‘‘ Fahrenheit
tempF = (tempIn | ($FF00 * sign)) + 110
tempF = tempF * 9 / 10 - 67
RETURN
Figure 4. VCP script loaded and ready for VCP.
F
o
r
E
l
e
c
t
r
o
n
i
c
s
NUTS & VOLTS
E
v
e
r
y
t
h
i
n
g
Process_FlexiPanel:
HIGH Attn
DO : LOOP UNTIL (Ready = IsHigh)
I2COUT SDA, WrFlxPnl, CTmp, [tempF.BYTE0,
tempF.BYTE1]
INPUT SCL
DO : LOOP UNTIL (SCL = IsHigh)
SELECT status
CASE StatOff
I2COUT SDA, WrFlxPnl, Stat, [“OFF “, 0]
CASE StatIdle
I2COUT SDA, WrFlxPnl, Stat, [“Idle “, 0]
CASE StatCool
I2COUT SDA, WrFlxPnl, Stat, [“Cooling”, 0]
CASE StatHeat
I2COUT SDA, WrFlxPnl, Stat, [“Heating”, 0]
CASE StatFan
I2COUT SDA, WrFlxPnl, Stat, [“Fan “, 0]
ENDSELECT
INPUT SCL
DO : LOOP UNTIL (SCL = IsHigh)
I2CIN SDA, RdFlxPnl, StPt, [setPoint]
I2CIN SDA, RdFlxPnl, Mode, [sysMode]
I2CIN SDA, RdFlxPnl, FCtl, [fanCtrl]
INPUT Attn
RETURN
32
Even though the exchange between the BASIC
Stamp and the FlexiPanel module is via I2C, we must
first get the module’s attention before initiating any
communication. This is accomplished by taking the Attn
JULY 2004