599 Menlo Drive, Suite 100
Rocklin, California 95765, USA
Office: (916) 624-8333
Fax: (916) 624-8003
General: info@parallaxinc.com
Technical: stamptech@parallaxinc.com
Web Site: www.parallaxinc.com
Educational: www.stampsinclass.com
BS2p “Plus Pack” AppKit (#45184)
Introduction
The BS2p “Plus Pack” is a selection of components and ready-to-run source code to assist experimenters
with mastering some of the exciting new features of the BS2p; specifically the use of parallel LCDs,
Philips I2C™ components and Dallas Semiconductor 1-Wire® components.
Please note that this AppKit is designed for intermediate to advanced users. The schematics and source
code have been carefully checked and are commented, but the expectation is that the user will consult
the appropriate product data sheets (not duplicated here) for detailed explanation of each component’s
operation.
Each of the enclosed experiments was built, tested and run on the BS2p Demo Board (#45183). Should
you desire more space for connecting components, please consider the NX-1000 lab board (#28135).
Packing List
Verify that your BS2p “Plus Pack” package is complete in accordance with the list below. The contents of
the package include:
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Packing List (this page)
Documentation/Source Code Diskette
Parallel LCD module; 2 lines x 16 characters (HD44780-compatible)
PCF8574 Remote 8-Bit I/O Expander
PCF8583 Clock/Calendar with 240 x 8-Bit RAM
PCF8591 8-Bit A/D and D/A Converter
24LC32 32K Serial EEPROM
(2) DS1822 Econo-MicoLAN Digital Thermometer
DS2405 Addressable Switch
DS2890 1-Wire Digital Potentiometer
(4) Jumper wires packs
220 ohm resistor
(2) 1K resistor
10K resistor
100K potentiometer
0.01 uF capacitor
(2) low-current LED
Normally-open pushbutton switch
32.678 kHz crystal
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 1
PP_LCDDEMO1.BSP
•
•
•
'
'
'
'
'
'
'
'
'
'
Connect LCD to the BS2p Demo Board X5
Install jumper X6
Adjust contrast pot for best display
-----[ Title ]---------------------------------------------------------------BS2p Plus Pack
File......
Purpose...
Author....
E-mail....
Started...
Updated...
PP_LCDDEMO1.BSP
Basic LCD Demo - Single Line Mode
Parallax, Inc.
stamptech@parallaxinc.com
26 SEP 2001
' {$STAMP BS2p}
'
'
'
'
'
'
'
'
-----[ Program Description ]-------------------------------------------------This program demonstrates LCD basics using the BS2p.
To run this program on the BS2p Demo Board, connect the LCD and install
Jumper X6. Adjust contrast pot for best display.
Refer to the Hitachi HD44780 documentation for details on LCD control.
' -----[ Revision History ]----------------------------------------------------'
' -----[ I/O Definitions ]-----------------------------------------------------'
LCDpin CON
0
' connect LCD to OutL
' -----[ Constants ]-----------------------------------------------------------'
NoCmd
CON
$00
' No command in LCDOUT
ClrLCD
CON
$01
' clear the LCD
CrsrHm
CON
$02
' move cursor to home position
CrsrLf
CON
$10
' move cursor left
CrsrRt
CON
$14
' move cursor right
DispLf
CON
$18
' shift displayed chars left
DispRt
CON
$1C
' shift displayed chars right
DDRam
CON
$80
' Display Data RAM control
DispCtrl
CON
%00001000
On
Off
CON
CON
1
0
' display control command
' -----[ Variables ]-----------------------------------------------------------'
cmd
VAR
Byte
' command sent to LCD
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 2
display
cursor
blinking
VAR
VAR
VAR
cmd.Bit2
cmd.Bit1
cmd.Bit0
' display on/off bit
' cursor on/off bit
' blinking on/off bit
char
idx
VAR
VAR
cmd
Byte
' character sent to LCD
' loop counter
' -----[ EEPROM Data ]---------------------------------------------------------'
' -----[ Initialization ]------------------------------------------------------'
Initialize:
PAUSE 500
' let the LCD settle
LCDCMD LCDpin,%00110000 : PAUSE 5
' 8-bit mode
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00100000 : PAUSE 0
' 4-bit mode
LCDCMD LCDpin,%00001100 : PAUSE 0
' no crsr, no blink
LCDCMD LCDpin,%00000110
' inc crsr, no disp shift
' -----[ Main Code ]-----------------------------------------------------------'
Main:
LCDCMD LCDpin,ClrLCD
' clear display
PAUSE 500
Splash_Screen
LCDOUT LCDpin,NoCmd,["THE BASIC STAMP!"]
PAUSE 2000
Cursor_On:
LCDCMD LCDpin,CrsrHm
cmd = DispCtrl
display = On
cursor = On
LCDCMD LCDpin,cmd
PAUSE 500
Move_Cursor:
FOR idx = 1 TO 15
LCDCMD LCDpin,CrsrRt
PAUSE 150
NEXT
FOR idx = 14 TO 0
cmd = DDRam + idx
LCDCMD LCDpin,cmd
PAUSE 150
NEXT
' move the cursor home
' move the cursor across display
' go backward by moving cursor
' to a specific address
PAUSE 1000
Block_Cursor:
cmd = DispCtrl
display = On
blinking = On
LCDCMD LCDpin,cmd
PAUSE 2000
blinking = Off
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
' enable block cursor
' turn it off
Page 3
LCDCMD LCDpin,cmd
Flash_Display:
cmd = DispCtrl
display = On
FOR idx = 1 TO 10
display = ~display
LCDCMD LCDpin,cmd
PAUSE 250
NEXT
' flash display by
' toggling display bit
PAUSE 1000
Shift_Display:
FOR idx = 1 TO 16
LCDCMD LCDpin,DispRt
PAUSE 100
NEXT
' shift display to right
PAUSE 1000
FOR idx = 1 TO 16
LCDCMD LCDpin,DispLf
PAUSE 100
NEXT
PAUSE 1000
GOTO Main
END
' shift display back
' do it all over
' -----[ Subroutines ]---------------------------------------------------------'
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 4
PP_LCDDEMO2.BSP
•
•
•
'
'
'
'
'
'
'
'
'
'
Connect LCD to the BS2p Demo Board X5
Install jumper X6
Adjust contrast pot for best display
-----[ Title ]---------------------------------------------------------------BS2p Plus Pack
File......
Purpose...
Author....
E-mail....
Started...
Updated...
PP_LCDDEMO2.BSP
Basic LCD Demo - Multi-line mode with custom characters
Parallax, Inc.
stamptech@parallaxinc.com
26 SEP 2001
' {$STAMP BS2p}
'
'
'
'
'
'
'
'
'
'
-----[ Program Description ]-------------------------------------------------This program demonstrates the use of the multi-line initialization and
the use of custom characters. When using the standard 5x7 font, the LCD
will hold up to eight customer characters.
To run this program on the BS2p Demo Board, connect the LCD and install
Jumper X6. Adjust contrast pot for best display.
Refer to the Hitachi HD44780 documentation for details on LCD control.
' -----[ Revision History ]----------------------------------------------------'
' -----[ I/O Definitions ]-----------------------------------------------------'
LCDpin
CON
0
' connect LCD to OutL
' -----[ Constants ]-----------------------------------------------------------'
NoCmd
CON
$00
' No command in LCDOUT
ClrLCD
CON
$01
' clear the LCD
CrsrHm
CON
$02
' move cursor to home position
CrsrLf
CON
$10
' move cursor left
CrsrRt
CON
$14
' move cursor right
DispLf
CON
$18
' shift displayed chars left
DispRt
CON
$1C
' shift displayed chars right
DDRam
CON
$80
' Display Data RAM control
CGRam
CON
$40
' Custom character RAM
Line1
CON
$80
' DDRAM address of line 1
Line2
CON
$C0
' DDRAM address of line 2
' -----[ Variables ]-----------------------------------------------------------'
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 5
cmd
char
newChr
addr
cNum
VAR
VAR
VAR
VAR
VAR
Byte
Byte
Byte
Byte
Byte
'
'
'
'
'
commnand sent to LCD
character sent to LCD
new character for animation
address in EE and display
character number
' -----[ EEPROM Data ]---------------------------------------------------------'
' custom character definitions
Mouth0
Mouth1
Mouth2
Smile
DATA
DATA
DATA
DATA
$0E,$1F,$1F,$1F,$1F,$1F,$0E,$00
$0E,$1F,$1F,$18,$1F,$1F,$0E,$00
$0E,$1F,$1C,$18,$1C,$1F,$0E,$00
$00,$0A,$0A,$00,$11,$0E,$06,$00
Msg
DATA
" IS VERY COOL! ",3
' revealed message
' -----[ Initialization ]------------------------------------------------------'
Initialize:
PAUSE 500
' let the LCD settle
LCDCMD LCDpin,%00110000 : PAUSE 5
' 8-bit mode
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00100000 : PAUSE 0
' 4-bit mode
LCDCMD LCDpin,%00101000 : PAUSE 0
' 2-line mode
LCDCMD LCDpin,%00001100 : PAUSE 0
' no crsr, no blink
LCDCMD LCDpin,%00000110
' inc crsr, no disp shift
DLChars:
LCDCMD LCDpin,CGRam
FOR addr = Mouth0 TO (Smile + 7)
READ addr,char
LCDOUT LCDpin,NoCmd,[char]
NEXT
'
'
'
'
'
download custom chars to LCD
prepare to write CG data
build 4 custom chars
get byte from EEPROM
put into LCD CGRAM
' -----[ Main Code ]-----------------------------------------------------------'
Main:
LCDCMD LCDpin,ClrLCD
PAUSE 1000
LCDOUT LCDpin,NoCmd,["THE BASIC STAMP"]
PAUSE 2000
' Animation by character replacement
FOR addr = 0 TO 15
READ (Msg + addr),newChr
cmd = Line2 + addr
FOR cNum = 0 TO 4
LOOKUP cNum,[2,1,0,1,newChr],char
LCDOUT LCDpin,cmd,[char]
PAUSE 100
NEXT
NEXT
PAUSE 3000
GOTO Main
END
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
'
'
'
'
cover 16 characters
get new char from message
set new DDRAM address
5 characters in cycle
' write animation character
' delay between animation chars
' do it all over
Page 6
' -----[ Subroutines ]---------------------------------------------------------'
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 7
PP_LCDFONT.BSP
•
•
•
'
'
'
'
'
'
'
'
'
'
Connect LCD to the BS2p Demo Board X5
Install jumper X6
Adjust contrast pot for best display
-----[ Title ]---------------------------------------------------------------BS2p Plus Pack
File......
Purpose...
Author....
E-mail....
Started...
Updated...
PP_LCDCFONT.BSP
Advanced LCD Demo - custom numeric font(s)
Parallax, Inc.
stamptech@parallaxinc.com
26 SEP 2001
' {$STAMP BS2p}
'
'
'
'
'
'
'
'
'
'
'
'
'
-----[ Program Description ]-------------------------------------------------This program demonstrates character definition replacement in order to create
a custom font for numbers. This program creates three custom characters that
are used to display the tens, ones and tenths value of a counter.
The program analyzes the counter and updates the screen by downloading the
appropriate character map for each digit.
To run this program on the BS2p Demo Board, connect the LCD and install
Jumper X6. Adjust contrast pot for best display.
Refer to the Hitachi HD44780 documentation for details on LCD control.
' -----[ Revision History ]----------------------------------------------------'
' -----[ I/O Definitions ]-----------------------------------------------------'
LCDpin
CON
0
' connect LCD to OutL
' -----[ Constants ]-----------------------------------------------------------'
NoCmd
CON
$00
' No command in LCDOUT
ClrLCD
CON
$01
' clear the LCD
CrsrHm
CON
$02
' move cursor to home position
CrsrLf
CON
$10
' move cursor left
CrsrRt
CON
$14
' move cursor right
DispLf
CON
$18
' shift displayed chars left
DispRt
CON
$1C
' shift displayed chars right
DDRam
CON
$80
' Display Data RAM control
CGRam
CON
$40
' Custom character RAM
Line1
CON
$80
' DDRAM address of line 1
Line2
CON
$C0
' DDRAM address of line 2
CLines
Space
CON
CON
8
10
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
' lines per character
Page 8
' -----[ Variables ]-----------------------------------------------------------'
char
VAR
Byte
' character sent to LCD
addr
VAR
Byte
' EE starting address of map
cNum
VAR
Nib
' character number
idx
VAR
Nib
' loop counter
counter
VAR
Word
' -----[ EEPROM Data ]---------------------------------------------------------'
' character definitions - digits 0 - 9 and space
'
Dig_0
DATA
$1F,$11,$11,$19,$19,$19,$1F,$00
Dig_1
DATA
$04,$04,$04,$0C,$0C,$0C,$0C,$00
Dig_2
DATA
$1F,$01,$01,$1F,$18,$18,$1F,$00
Dig_3
DATA
$1E,$02,$02,$1F,$03,$03,$1F,$00
Dig_4
DATA
$18,$18,$18,$19,$1F,$01,$01,$00
Dig_5
DATA
$1F,$18,$18,$1F,$01,$01,$1F,$00
Dig_6
DATA
$18,$10,$10,$1F,$19,$19,$1F,$00
Dig_7
DATA
$1F,$11,$01,$03,$03,$03,$03,$00
Dig_8
DATA
$0E,$0A,$0A,$1F,$13,$13,$1F,$00
Dig_9
DATA
$1F,$11,$11,$1F,$03,$03,$03,$00
Dig_Spc
DATA
$00,$00,$00,$00,$00,$00,$00,$00
' -----[ Initialization ]------------------------------------------------------'
Initialize:
PAUSE 500
' let the LCD settle
LCDCMD LCDpin,%00110000 : PAUSE 5
' 8-bit mode
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00100000 : PAUSE 0
' 4-bit mode
LCDCMD LCDpin,%00101000 : PAUSE 0
' 2-line mode
LCDCMD LCDpin,%00001100 : PAUSE 0
' no crsr, no blink
LCDCMD LCDpin,%00000110
' inc crsr, no disp shift
FOR cNum = 0 TO 2
LOOKUP cNum,[Dig_0,Dig_0,Dig_Spc],addr
GOSUB Update_CC
NEXT
' initialize cust chars
' -----[ Main Code ]-----------------------------------------------------------'
Main:
LCDOUT LCDpin,ClrLCD,["CUSTOM DIGITS"]
' setup display
LCDOUT LCDpin,(Line2 + 12),[2,1,".",0]
Show_Counter:
FOR counter = 0 TO 999
FOR cNum = 0 TO 2
addr = counter DIG cNum
IF (cNum < 2) OR (addr > 0) THEN DigitOK
addr = Space
DigitOK:
addr = addr * CLines
GOSUB Update_CC
NEXT
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
' count in tenths 0 - 99.9
' get a digit
' leading space if < 10
' calculate map for this digit
' download to LCD
Page 9
PAUSE 100
NEXT
GOTO Main
END
' -----[ Subroutines ]---------------------------------------------------------'
Update_CC:
' update custom character
LCDCMD LCDpin,(CGRam + (cNum * CLines))
' point to character map
FOR idx = 0 TO (CLines - 1)
READ (addr + idx),char
' get data for character line
LCDOUT LCDpin,NoCmd,[char]
' write to LCD CGRAM
NEXT
RETURN
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 10
PP_LCDODO.BSP
•
•
•
'
'
'
'
'
'
'
'
'
'
Connect LCD to the BS2p Demo Board X5
Install jumper X6
Adjust contrast pot for best display
-----[ Title ]---------------------------------------------------------------BS2p Plus Pack
File......
Purpose...
Author....
E-mail....
Started...
Updated...
PP_LCDODO.BSP
Advanced LCD Demo - rewriting CGRAM on the fly
Parallax, Inc.
stamptech@parallaxinc.com
26 SEP 2001
' {$STAMP BS2p}
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
'
-----[ Program Description ]-------------------------------------------------This program demonstrates LCD character animation by writing to the
character map (in CGRAM) for a character that is already displayed. The
refresh cycle of the LCD will cause the character to change when its
map is changed. This technique (originally by Scott Edwards) allows
the programmer to create advanced animations by storing character (cell)
definitions in the Stamp's EEPROM.
This program displays a rolling odometer type reading (last digit
"rolls"). Character definitions are copied from the standard set
(using "LCD Character Creator" software from Parallax).
Each character definition is separated by 2 blank lines in order to create
10 lines per "rolling" character. This makes the math for calculating
the starting line of the roller very easy.
To run this program on the BS2p Demo Board, connect the LCD and install
Jumper X6. Adjust contrast pot for best display.
Refer to the Hitachi HD44780 documentation for details on LCD control.
' -----[ Revision History ]----------------------------------------------------'
' -----[ I/O Definitions ]-----------------------------------------------------'
LCDpin
CON
0
' connect LCD to OutL
' -----[ Constants ]-----------------------------------------------------------'
NoCmd
CON
$00
' No command in LCDOUT
ClrLCD
CON
$01
' clear the LCD
CrsrHm
CON
$02
' move cursor to home position
CrsrLf
CON
$10
' move cursor left
CrsrRt
CON
$14
' move cursor right
DispLf
CON
$18
' shift displayed chars left
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 11
DispRt
DDRam
CGRam
Line1
Line2
CON
CON
CON
CON
CON
$1C
$80
$40
$80
$C0
'
'
'
'
'
shift displayed chars right
Display Data RAM control
Custom character RAM
DDRAM address of line 1
DDRAM address of line 2
CLines
OdoChar
CON
CON
8
0
' lines per character
' animated odometer character
' -----[ Variables ]-----------------------------------------------------------'
cmd
VAR
Byte
' commnand sent to LCD
char
VAR
Byte
' character sent to LCD
addr
VAR
Byte
' EE starting address of map
cNum
VAR
Nib
' character number
idx
VAR
Nib
' loop counter
counter
hundreds
VAR
VAR
Word
Byte
' hundredths value of counter
temp
width
pos
digits
VAR
VAR
VAR
VAR
Word
Nib
Byte
Nib
'
'
'
'
temp value for RJ display
width of rt justified
LCD display position
digits to display
' -----[ EEPROM Data ]---------------------------------------------------------'
' rolling odometer character definitions
'
Char0
DATA
$0E,$11,$13,$15,$19,$11,$0E,$00,$00,$00
Char1
DATA
$04,$0C,$04,$04,$04,$04,$0E,$00,$00,$00
Char2
DATA
$0E,$11,$01,$02,$04,$08,$1F,$00,$00,$00
Char3
DATA
$1F,$02,$04,$02,$01,$11,$0E,$00,$00,$00
Char4
DATA
$02,$06,$0A,$12,$1F,$02,$02,$00,$00,$00
Char5
DATA
$1F,$10,$1E,$01,$01,$11,$0E,$00,$00,$00
Char6
DATA
$06,$08,$10,$1E,$11,$11,$0E,$00,$00,$00
Char7
DATA
$1F,$01,$02,$04,$08,$08,$08,$00,$00,$00
Char8
DATA
$0E,$11,$11,$0E,$11,$11,$0E,$00,$00,$00
Char9
DATA
$0E,$11,$11,$0F,$01,$02,$0C,$00,$00,$00
' inverted character definitions (white on black)
'
Char0i
DATA
$11,$0E,$0C,$0A,$06,$0E,$11,$1F,$1F,$1F
Char1i
DATA
$1B,$13,$1B,$1B,$1B,$1B,$11,$1F,$1F,$1F
Char2i
DATA
$11,$0E,$1E,$1D,$1B,$17,$00,$1F,$1F,$1F
Char3i
DATA
$00,$1D,$1B,$1D,$1E,$0E,$11,$1F,$1F,$1F
Char4i
DATA
$1D,$19,$15,$0D,$00,$1D,$1D,$1F,$1F,$1F
Char5i
DATA
$00,$0F,$01,$1E,$1E,$0E,$11,$1F,$1F,$1F
Char6i
DATA
$19,$17,$0F,$01,$0E,$0E,$11,$1F,$1F,$1F
Char7i
DATA
$00,$1E,$1D,$1B,$17,$17,$17,$1F,$1F,$1F
Char8i
DATA
$11,$0E,$0E,$11,$0E,$0E,$11,$1F,$1F,$1F
Char9i
DATA
$11,$0E,$0E,$10,$1E,$1D,$13,$1F,$1F,$1F
MapStart
CON
Char0i
' -----[ Initialization ]------------------------------------------------------'
Initialize:
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 12
PAUSE 500
LCDCMD LCDpin,%00110000
LCDCMD LCDpin,%00110000
LCDCMD LCDpin,%00110000
LCDCMD LCDpin,%00100000
LCDCMD LCDpin,%00101000
LCDCMD LCDpin,%00001100
LCDCMD LCDpin,%00000110
:
:
:
:
:
:
PAUSE
PAUSE
PAUSE
PAUSE
PAUSE
PAUSE
5
0
0
0
0
0
cNum = OdoChar
addr = 0
GOSUB Update_CC
' let the LCD settle
' 8-bit mode
'
'
'
'
4-bit mode
2-line mode
no crsr, no blink
inc crsr, no disp shift
' put "0" into custom character
' -----[ Main Code ]-----------------------------------------------------------'
Main:
LCDOUT LCDpin,ClrLCD,["ROLLER
COUNTER"]
LCDOUT LCDpin,Line2, ["
0",OdoChar,"
0.00"]
PAUSE 1000
Show_Counters:
FOR counter = 0 TO 999
FOR hundreds = 0 TO 99
temp = counter
width = 3
pos = Line2 + 1
GOSUB RJ_Print
addr = hundreds
GOSUB Update_CC
pos = Line2 + 10
GOSUB RJ_Print
LCDOUT LCDpin,NoCmd,[".",DEC2 hundreds]
PAUSE 100
NEXT
NEXT
' display odometer version
' update rolling character
' display digital version
GOTO Main
END
' -----[ Subroutines ]---------------------------------------------------------'
Update_CC:
' update custom character
LCDCMD LCDpin,(CGRam + (cNum * CLines))
' point to character map
FOR idx = 0 TO (CLines - 1)
READ MapStart + (addr + idx // 100),char
LCDOUT LCDpin,NoCmd,[char]
' write to LCD CGRAM
NEXT
RETURN
RJ_Print:
' right justified printing
digits = width
LOOKDOWN temp, F conversion
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 43
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 44
PP_DS1822-2.BSP
•
•
•
•
'
'
'
'
'
'
'
'
'
'
Connect LCD to the BS2p Demo Board X5
Install jumper X6
Adjust contrast pot for best display
Assemble DS1822 ciruit on breadboard
-- use on-board 4.7K resistor (R1) for 1-Wire pull-up
-----[ Title ]---------------------------------------------------------------BS2p Plus Pack
File......
Purpose...
Author....
E-mail....
Started...
Updated...
PP_DS1822-2.BSP
Reads and displays information from two Dallas DS1822
Parallax
stamptech@parallaxinc.com
26 SEP 2001
' {$STAMP BS2p}
'
'
'
'
'
'
-----[ Program Description ]-------------------------------------------------This program demonstrates individual device addressing with the Dallas
1-Wire bus. Before running the program, the individual device addresses
must be determined and stored in the EEPROM.
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 45
'
'
'
'
'
'
'
Use the program PP_OWID.BSP to determine the data table for your
DS1822 sensors.
To run this program on the BS2p Demo Board, connect the LCD and
install Jumper X6. Adjust contrast pot for best display.
Refer to the Hitachi HD44780 documentation for details on LCD control.
' -----[ Revision History ]----------------------------------------------------'
' -----[ I/O Definitions ]-----------------------------------------------------'
OWpin
CON
15
TempType
VAR
In14
' 1 = Fahrenheit
LCDpin
CON
0
' connect LCD to OutL
' -----[ Constants ]-----------------------------------------------------------'
NoCmd
CON
$00
' No command in LCDOUT
ClrLCD
CON
$01
' clear the LCD
CrsrHm
CON
$02
' move cursor to home position
CrsrLf
CON
$10
' move cursor left
CrsrRt
CON
$14
' move cursor right
DispLf
CON
$18
' shift displayed chars left
DispRt
CON
$1C
' shift displayed chars right
DDRam
CON
$80
' Display Data RAM control
CGRam
CON
$40
' Custom character RAM
Line1
CON
$80
' DDRAM address of line 1
Line2
CON
$C0
' DDRAM address of line 2
DegSym
CON
223
' degrees symbol
' 1-Wire Support
'
OW_FERst
CON
OW_BERst
CON
OW_BitMode
CON
OW_HighSpd
CON
%0001
%0010
%0100
%1000
' Front-End Reset
' Back-End Reset
ReadROM
MatchROM
SkipROM
SearchROM
CON
CON
CON
CON
$33
$55
$CC
$F0
'
'
'
'
' DS1822 control
'
CnvrtTemp
CON
RdScratch
CON
$44
$BE
' do temperature conversion
' read scratchpad
TC
TF
NumSensors
0
1
2
' read in Celcius
' read in Fahrenheit
' inside and outside
CON
CON
CON
read ID, serial num, CRC
look for specific device
skip ROM (one device)
search
' -----[ Variables ]-----------------------------------------------------------'
sensor
VAR
Nib
' sensor number to process
idx
VAR
Nib
' loop counter
eeAddr
VAR
Byte
' ee address of ROM match
romData
VAR
Byte(8)
' ROM data to DS1822
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 46
tempIn
sign
tInLow
tInHigh
tSign
VAR
VAR
VAR
VAR
VAR
Word
tempIn.Bit11
tempIn.LowByte
tempIn.HighByte
Bit
' raw temperature
' 1 = negative temperature
tempC
tempF
char
rjNum
rjSign
pos
digits
width
VAR
VAR
VAR
VAR
VAR
VAR
VAR
VAR
Word
Word
Byte
tempIn
Bit
Byte
Nib
Nib
'
'
'
'
'
'
'
'
Celsius
Fahrenheit
character for LCD
right justified number
sign for rj number
position to print
digits in rjNum
width of display
' -----[ EEPROM Data ]---------------------------------------------------------'
' ROM codes for connected sensors
' -- these values MUST be edited for your sensors
T_ID0
T_ID1
DATA
DATA
$22,$30,$34,$01,$00,$00,$00,$6C
$22,$85,$42,$01,$00,$00,$00,$71
' labels for temperature sensors
T_Label0
T_Label1
DATA
DATA
"INSIDE ",0
"OUTSIDE ",0
' -----[ Initialization ]------------------------------------------------------'
Initialize:
PAUSE 500
' let the LCD settle
LCDCMD LCDpin,%00110000 : PAUSE 5
' 8-bit mode
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00110000 : PAUSE 0
LCDCMD LCDpin,%00100000 : PAUSE 0
' 4-bit mode
LCDCMD LCDpin,%00101000 : PAUSE 0
' 2-line mode
LCDCMD LCDpin,%00001100 : PAUSE 0
' no crsr, no blink
LCDCMD LCDpin,%00000110
' inc crsr, no disp shift
' -----[ Main Code ]-----------------------------------------------------------'
Main:
LCDOUT LCDpin,ClrLCD,["
DS1822"]
' splash screen
LCDOUT LCDpin,Line2, [" Thermometer"]
PAUSE 2000
LCDCMD LCDpin,ClrLCD
Show_Sensors:
LOOKUP sensor,[T_ID0,T_ID1],eeAddr
GOSUB Get_Temp
LOOKUP sensor,[T_Label0,T_Label1],eeAddr
LCDCMD LCDpin, Line1
GOSUB Print_Label
' point to ROM code
' get temperature
' display sensor label
width = 4
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001
Page 47
pos = Line2 + 10
rjNum = tempC
IF (TempType = TC) THEN
rjNum = tempF
Print_Temp
Print_Temp:
GOSUB RJ_Print
LCDOUT LCDpin,NoCmd,[DegSym,TempType * ("F" - "C") + "C"]
Next_Sensor:
sensor = sensor + 1 // NumSensors
PAUSE 5000
GOTO Show_Sensors
END
' -----[ Subroutines ]---------------------------------------------------------'
Get_Temp:
FOR idx = 0 TO 7
' load ROM pattern
READ (eeAddr+idx),romData(idx)
NEXT
OWOUT
PAUSE
OWOUT
OWIN
OWpin,OW_FERst,[MatchROM,STR romData\8,CnvrtTemp]
500
OWpin,OW_FERst,[MatchROM,STR romData\8,RdScratch]
OWpin,OW_BERst,[tInLow,tInHigh]
tSign = sign
tempC = tempIn
tempC = tempC >> 4
IF (tSign = 0) THEN NoNeg1
tempC = tempC | $FF00
' save sign bit
' round to whole degrees
' extend sign bits for negs
NoNeg1:
tempF = tempC */ $01CD
IF (tSign = 0) THEN NoNeg2
tempF = tempF | $FF00
' multiply by 1.8
' if neg, extend sign bits
NoNeg2:
tempF = tempF + 32
RETURN
' finish C -> F conversion
Print_Label:
READ eeAddr,char
IF (char = 0) THEN Print_Done
LCDOUT LCDpin,NoCmd,[char]
eeAddr = eeAddr + 1
GOTO Print_Label
Print_Done:
RETURN
'
'
'
'
get a character
if 0, exit
send to LCD
move to next char address
RJ_Print:
rjSign = rjNum.Bit15
' save sign
rjNum = ABS(rjNum)
' convert to positive
digits = width
LOOKDOWN rjNum,