manuals.online logo
Brands
  1. Home
  2. •
  3. Brands
  4. •
  5. Parallax
  6. •
  7. Microcontroller
  8. •
  9. Parallax BS2p Plus Pack AppKit User manual

Parallax BS2p Plus Pack AppKit User manual

Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 1
599 Menlo Drive, Suite 100
Rocklin, California 95765, USA
Office: (916) 624-8333
Fax: (916) 624-8003
General: [email protected]
Technical: [email protected]
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 2
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...... PP_LCDDEMO1.BSP
' Purpose... Basic LCD Demo -Single Line Mode
' Author.... Parallax, Inc.
' E-mail.... [email protected]
' Started...
' Updated... 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 ' display control command
On CON 1
Off CON 0
' -----[ Variables ]------------------------------------------------------------
'
cmd VAR Byte ' command sent to LCD
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 3
display VAR cmd.Bit2 ' display on/off bit
cursor VAR cmd.Bit1 ' cursor on/off bit
blinking VAR cmd.Bit0 ' blinking on/off bit
char VAR cmd ' character sent to LCD
idx VAR Byte ' 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 ' move the cursor home
cmd = DispCtrl
display = On
cursor = On
LCDCMD LCDpin,cmd
PAUSE 500
Move_Cursor:
FOR idx = 1 TO 15 ' move the cursor across display
LCDCMD LCDpin,CrsrRt
PAUSE 150
NEXT
FOR idx = 14 TO 0 ' go backward by moving cursor
cmd = DDRam + idx ' to a specific address
LCDCMD LCDpin,cmd
PAUSE 150
NEXT
PAUSE 1000
Block_Cursor:
cmd = DispCtrl
display = On
blinking = On ' enable block cursor
LCDCMD LCDpin,cmd
PAUSE 2000
blinking = Off ' turn it off
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 4
LCDCMD LCDpin,cmd
Flash_Display:
cmd = DispCtrl
display = On
FOR idx = 1 TO 10 ' flash display by
display = ~display ' toggling display bit
LCDCMD LCDpin,cmd
PAUSE 250
NEXT
PAUSE 1000
Shift_Display:
FOR idx = 1 TO 16 ' shift display to right
LCDCMD LCDpin,DispRt
PAUSE 100
NEXT
PAUSE 1000
FOR idx = 1 TO 16 ' shift display back
LCDCMD LCDpin,DispLf
PAUSE 100
NEXT
PAUSE 1000
GOTO Main ' do it all over
END
' -----[ Subroutines ]----------------------------------------------------------
'
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 5
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...... PP_LCDDEMO2.BSP
' Purpose... Basic LCD Demo -Multi-line mode with custom characters
' Author.... Parallax, Inc.
' E-mail.... [email protected]
' Started...
' Updated... 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 6
cmd VAR Byte ' commnand sent to LCD
char VAR Byte ' character sent to LCD
newChr VAR Byte ' new character for animation
addr VAR Byte ' address in EE and display
cNum VAR Byte ' character number
' -----[ EEPROM Data ]----------------------------------------------------------
'
' custom character definitions
Mouth0 DATA $0E,$1F,$1F,$1F,$1F,$1F,$0E,$00
Mouth1 DATA $0E,$1F,$1F,$18,$1F,$1F,$0E,$00
Mouth2 DATA $0E,$1F,$1C,$18,$1C,$1F,$0E,$00
Smile DATA $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: ' download custom chars to LCD
LCDCMD LCDpin,CGRam ' prepare to write CG data
FOR addr = Mouth0 TO (Smile + 7) ' build 4 custom chars
READ addr,char ' get byte from EEPROM
LCDOUT LCDpin,NoCmd,[char] ' put into LCD CGRAM
NEXT
' -----[ 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 ' cover 16 characters
READ (Msg + addr),newChr ' get new char from message
cmd = Line2 + addr ' set new DDRAM address
FOR cNum = 0 TO 4 ' 5 characters in cycle
LOOKUP cNum,[2,1,0,1,newChr],char
LCDOUT LCDpin,cmd,[char] ' write animation character
PAUSE 100 ' delay between animation chars
NEXT
NEXT
PAUSE 3000
GOTO Main ' do it all over
END
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 7
' -----[ Subroutines ]----------------------------------------------------------
'
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 8
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...... PP_LCDCFONT.BSP
' Purpose... Advanced LCD Demo -custom numeric font(s)
' Author.... Parallax, Inc.
' E-mail.... [email protected]
' Started...
' Updated... 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 CON 8 ' lines per character
Space CON 10
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 9
' -----[ 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 ' initialize cust chars
LOOKUP cNum,[Dig_0,Dig_0,Dig_Spc],addr
GOSUB Update_CC
NEXT
' -----[ Main Code ]------------------------------------------------------------
'
Main:
LCDOUT LCDpin,ClrLCD,["CUSTOM DIGITS"] ' setup display
LCDOUT LCDpin,(Line2 + 12),[2,1,".",0]
Show_Counter:
FOR counter = 0 TO 999 ' count in tenths 0 -99.9
FOR cNum = 0 TO 2
addr = counter DIG cNum ' get a digit
IF (cNum < 2) OR (addr > 0) THEN DigitOK
addr = Space ' leading space if < 10
DigitOK:
addr = addr * CLines ' calculate map for this digit
GOSUB Update_CC ' download to LCD
NEXT
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 10
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 11
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...... PP_LCDODO.BSP
' Purpose... Advanced LCD Demo -rewriting CGRAM on the fly
' Author.... Parallax, Inc.
' E-mail.... [email protected]
' Started...
' Updated... 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 12
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 CON 8 ' lines per character
OdoChar CON 0 ' 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 VAR Word
hundreds VAR Byte ' hundredths value of counter
temp VAR Word ' temp value for RJ display
width VAR Nib ' width of rt justified
pos VAR Byte ' LCD display position
digits VAR Nib ' 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 13
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
cNum = OdoChar
addr = 0
GOSUB Update_CC ' 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 ' display odometer version
width = 3
pos = Line2 + 1
GOSUB RJ_Print
addr = hundreds
GOSUB Update_CC ' update rolling character
pos = Line2 + 10 ' display digital version
GOSUB RJ_Print
LCDOUT LCDpin,NoCmd,[".",DEC2 hundreds]
PAUSE 100
NEXT
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 MapStart + (addr + idx // 100),char
LCDOUT LCDpin,NoCmd,[char] ' write to LCD CGRAM
NEXT
RETURN
RJ_Print: ' right justified printing
digits = width
LOOKDOWN temp,<[0,10,100,1000,65535],digits
LCDOUT LCDpin,pos,[REP " "\(width-digits),DEC temp]
RETURN
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 14
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 15
PP_LCD5x10.BSP
•Connect LCD to the BS2p Demo Board X5
•Install jumper X6
•Adjust contrast pot for best display
•Assemble pushbutton circuit on breadboard
'-----[ Title ]----------------------------------------------------------------
'
' BS2p Plus Pack
'
' File...... PP_LCD5x10.BSP
' Purpose... Basic LCD Demo -- Using 5x10 font and descended characters
' Author.... Parallax, Inc.
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 26 SEP 2001
' {$STAMP BS2p}
' -----[ Program Description ]--------------------------------------------------
'
' This program demostrates a method of intializing a 2x16 LCD so that it behaves
' like a single-line LCD that will display the 5x10 character set. The LCD
' character map includes properly descended characters, but they are not mapped
' in the normal ASCII set. A simple conversion routine can be used to replace
' "squishy" descended characters with proper ones.
'
' Stamp pin 15 is pulled up to Vdd (+5) through 10K. This pin is connected to
' Vss (ground) through a N.O. pushbutton switch. The pin will read 1 when the
' switch is open, 0 when pressed.
'
' To run this program on the BS2p Demo Board, assemble the the switch circuit on
' the breadboard, connect the LCD to X5 and install Jumper X6. Adjust contrast
' pot for best display.
'
' Refer to the Hitachi HD44780 documentation for details on LCD control.
' -----[ Revision History ]-----------------------------------------------------
'
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 16
' -----[ I/O Definitions ]------------------------------------------------------
'
LCDpin CON 0 ' LCD is connected to OutL
AskBtn VAR In15 ' Ask button input pin
' -----[ 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
NumAns CON 6 ' 6 possible answers
_g CON $E7 ' DDROM addresses of descenders
_j CON $EA
_p CON $F0
_q CON $F1
_y CON $F9
Pressed CON 0 ' button input is active low
' -----[ Variables ]------------------------------------------------------------
'
char VAR Byte ' character sent to LCD
addr VAR Byte ' message address
answer VAR Nib ' answer pointer
clock VAR Nib ' animation clock
pntr VAR Nib ' pointer to animation character
' -----[ EEPROM Data ]----------------------------------------------------------
'
Prompt DATA "Ask a question",0 ' messages for LCD
Ans0 DATA "Definitely YES",0
Ans1 DATA "Possible...",0
Ans2 DATA "Definitely NO",0
Ans3 DATA "Not likely...",0
Ans4 DATA "Answer uncertain",0
Ans5 DATA "Please ask again",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,%00100100 : PAUSE 0 ' 5x10 font
LCDCMD LCDpin,%00001100 : PAUSE 0 ' no crsr, no blink
LCDCMD LCDpin,%00000110 ' inc crsr, no disp shift
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 17
' -----[ Main Code ]------------------------------------------------------------
'
Main:
LCDCMD LCDpin,ClrLCD ' clear the LCD
addr = Prompt
GOSUB Show_Msg ' print prompt
Rollem:
GOSUB Shuffle ' shuffle until button pressed
PAUSE 5
IF (AskBtn = Pressed) THEN Show_Answer
GOTO Rollem
Show_Answer:
' get address of answer message
LOOKUP answer,[Ans0,Ans1,Ans2,Ans3,Ans4,Ans5],addr
LCDCMD LCDpin,ClrLCD
GOSUB Show_Msg
PAUSE 2000 ' give time to read answer
GOTO Main ' do it all over
END
' -----[ Subroutines ]----------------------------------------------------------
'
Show_Msg:
READ addr,char ' read a character
IF (char = 0) THEN Msg_Done ' if 0, message is complete
GOSUB Translate ' fix letters with descenders
LCDOUT LCDpin,NoCmd,[char]
addr = addr + 1 ' point to next character
GOTO Show_Msg
Msg_Done:
RETURN
' convert to descender font
' - does not change other characters
Translate:
LOOKDOWN char,["g","j","q","p","y"],char ' translate decended characters
LOOKUP char,[_g,_j,_q,_p,_y],char
RETURN
Shuffle:
answer = answer + 1 // NumAns ' update answer pointer
clock = clock + 1 // 15 ' update pointer clock
IF (clock > 0) THEN Shuffle_Done ' time to update animation?
LOOKUP pntr,["-+|*"],char ' load animation character
LCDOUT LCDpin,DDRam + 15,[char] ' write it at column 15
pntr = pntr + 1 // 4 ' update animation char
Shuffle_Done:
RETURN
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 18
PP_PCF8574.BSP
•Assemble PCF8583574 circuit on breadboard
-- use on-board 4.7K resistors (R1 and R2) for pull-ups
' -----[ Title ]----------------------------------------------------------------
'
' BS2p Plus Pack
'
' File...... PP_PCF8574.BSP
' Purpose... Reads remote input and updates 2 remote outputs on PCF8574
' Author.... Parallax
' E-mail.... stamptech@parallaxinc.com
' Started...
' Updated... 26 SEP 2001
' {$STAMP BS2p}
' -----[ Program Description ]--------------------------------------------------
'
' This program reads bit 7 from the PCF8574. If that bit is high (button is
' pressed), a counter is incremented and displayed via LEDs on PCF8574 bits
' 0 and 1.
'
' Note: Most (not all) I2C devices have multiple internal addresses, so the
' I2CIN and I2COUT commands support this with an address parameter (this byte
' comes after the Slave Address byte). With the PCF8574, replace the address
' byte with a value that reflects the desired state of the I/O pins, where
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 19
' 1 is an input. For example:
'
' %11100000 = Bits 0 -4 are outputs, bits 5 -7 are inputs
'
' For the PCF8574 the syntax becomes:
'
' I2CIN pin, ddr_value, [in_byte]
' I2COUT pin, ddr_value, [out_byte]
'
' Special Note: When reading inputs while using the PCF8574 in mixed I/O mode,
' you must refresh the output bits during the read. This is easily accomplished
' by ORing the state of the output pins with the DDR value.
'
' I2CIN pin, (ddr_value | out_bits), [out_byte]
'
' This program uses the bits in mixed mode and will use the syntax described
' immediately above.
'
' I/O Notes:
'
' The input bit is pulled up to Vdd (+5) through 10K. This input is connected
' to Vss (ground) through a N.O. pushbutton switch. The input will read 1 when
' the switch is open, 0 when pressed.
'
' PCF8574 can sink current, but provide almost no source current. Outputs for
' this program are setup as active-low. The tilde (~) in front of the variable
' cntr inverts the bits since we're using active low outputs.
' -----[ Revision History ]-----------------------------------------------------
'
' -----[ I/O Definitions ]------------------------------------------------------
'
I2Cpin CON 8 ' SDA on 8; SCL on 9
' -----[ Constants ]------------------------------------------------------------
'
DevType CON %0100 << 4 ' Device type
DevAddr CON %000 << 1 ' address = %000 -> %111
Wr8574 CON DevType | DevAddr ' write to PCF8574
Rd8574 CON Wr8574 | 1 ' read from PCF8574
MixDDR CON %11111100 ' 1 = input, 0 = output
' -----[ Variables ]------------------------------------------------------------
'
ioByte VAR Byte ' i/o byte for PCF8574
btn VAR ioByte.Bit7 ' button input (0 = pressed)
cntr VAR Nib ' counter
' -----[ EEPROM Data ]----------------------------------------------------------
'
' -----[ Initialization ]-------------------------------------------------------
'
Initialize:
DEBUG CLS
Parallax, Inc. • BS2p “Plus Pack” (#45184) • 10/2001 Page 20
PAUSE 100
DEBUG "PCF8574 Demo", CR
DEBUG "Press button to update counter"
' -----[ Main Code ]------------------------------------------------------------
'
Main:
I2CIN I2Cpin, Rd8574, (MixDDR | ~cntr), [ioByte]
IF (btn) THEN Main ' wait for press
cntr = cntr + 1 // 4 ' update counter
DEBUG Home, 10, 10, 10, BIN2 cntr ' display on screen
I2COUT I2Cpin, Wr8574, MixDDR, [~cntr] ' send new value
PAUSE 200
GOTO Main
' -----[ Subroutines ]----------------------------------------------------------
'

This manual suits for next models

1

Other Parallax Microcontroller manuals

Parallax 28034 User manual

Parallax

Parallax 28034 User manual

Parallax 28016 User manual

Parallax

Parallax 28016 User manual

Parallax BASIC Stamp 2e Owner's manual

Parallax

Parallax BASIC Stamp 2e Owner's manual

Parallax 27113 User manual

Parallax

Parallax 27113 User manual

Parallax Javelin Stamp User manual

Parallax

Parallax Javelin Stamp User manual

Parallax 27150 User manual

Parallax

Parallax 27150 User manual

Parallax eb500-SER C User manual

Parallax

Parallax eb500-SER C User manual

Parallax BASIC Stamp II User manual

Parallax

Parallax BASIC Stamp II User manual

Parallax WIZnet W5200 User manual

Parallax

Parallax WIZnet W5200 User manual

Popular Microcontroller manuals by other brands

NXP Semiconductors M53015EVB quick start guide

NXP Semiconductors

NXP Semiconductors M53015EVB quick start guide

Renesas Starter Kit+ quick start

Renesas

Renesas Starter Kit+ quick start

Cytron Technologies SK40C user manual

Cytron Technologies

Cytron Technologies SK40C user manual

Nuvoton I94100 Series user manual

Nuvoton

Nuvoton I94100 Series user manual

Siemens C541U user manual

Siemens

Siemens C541U user manual

Intel Edison Kit for Arduino Hardware guide

Intel

Intel Edison Kit for Arduino Hardware guide

NEC 78K0S/KA1+ user manual

NEC

NEC 78K0S/KA1+ user manual

NEC V850/SB1TM user manual

NEC

NEC V850/SB1TM user manual

ST STEVAL-IDB007V1M SPBTLE-1S user manual

ST

ST STEVAL-IDB007V1M SPBTLE-1S user manual

Silicon Laboratories C8051F326/7 user guide

Silicon Laboratories

Silicon Laboratories C8051F326/7 user guide

Nuvoton NuTiny-SDK-NUC123 user manual

Nuvoton

Nuvoton NuTiny-SDK-NUC123 user manual

NXP Semiconductors LPC11E Series user manual

NXP Semiconductors

NXP Semiconductors LPC11E Series user manual

Panasonic MN103SFX1K manual

Panasonic

Panasonic MN103SFX1K manual

Espressif Systems ESP32-C6 Series Hardware Design Guidelines

Espressif Systems

Espressif Systems ESP32-C6 Series Hardware Design Guidelines

Altera APEX Getting started guide

Altera

Altera APEX Getting started guide

Ehong EH-MC10-MESH-EVK user guide

Ehong

Ehong EH-MC10-MESH-EVK user guide

Silicon Laboratories C8051F970 user guide

Silicon Laboratories

Silicon Laboratories C8051F970 user guide

Conrad C-Control Pro Mega Series manual

Conrad

Conrad C-Control Pro Mega Series manual

manuals.online logo
manuals.online logoBrands
  • About & Mission
  • Contact us
  • Privacy Policy
  • Terms and Conditions

Copyright 2025 Manuals.Online. All Rights Reserved.