LCD help with EEPROM
eecs189
Posts: 10
Hey,
This is my code for ultrasound range finder. We designed both the transmitter and receiver circuit of the ultrasound range finder. When we turn on all the circuits, we would like the LCD to display, "Transmitter on" and then "Press the button." Once the user presses the button, then we want the LCD to display time and distance. Here's my code that I have so far. It's not working. I'm wondering if my syntax is incorrect. If there's more efficient way of displaying data LCD using other commands such as SERIN, please let me know. I'm still getting my feet wet with Basic Stamp 2.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Constants ]
' Ports used
RS CON 4 ' Register Select (1 = char)
E CON 5 ' LCD Enable pin (1 = enabled)
' LCD control characters
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
'
[noparse][[/noparse] Initialization ]
'
Init: DIRL = %00111111 ' set pins 0-5 as outputs
OUTS = $0000 ' clear the pins
' Initialize the LCD (Hitachi HD44780 controller)
'
LCDinit: PAUSE 500 ' Wait for LCD init
' =================================
' STANDARD HITACHI 44780 4-BIT INIT
' =================================
char=%00000011 ' Set 8-bit mode (1)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (2)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (3)
GOSUB LCDcmd
char=%00000010 ' Set 4-bit mode
GOSUB LCDcmd
char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
GOSUB LCDcmd ' 10xx = 5x8 matric
char=%00000000 ' Display control mode
GOSUB LCDcmd
char=%00001000 ' Set display OFF, cursor OFF, blink OFF
GOSUB LCDcmd
char=%00000000 ' Display control mode
GOSUB LCDcmd
char=%00001111 ' Set display ON, cursor ON, blink ON
GOSUB LCDcmd ' 11CB -> C=1 cursor on, B=1 blink on
char=%00000000 ' Entry control mode
GOSUB LCDcmd
char=%00000110 ' Set cursor right, no display shift
GOSUB LCDcmd ' 01IS -> I=1 cursor right, S=1 shift display
char = ClrLCD ' Clear LCD
GOSUB LCDcmd
'
[noparse][[/noparse] Variables ]
time VAR Word
dist VAR Word
char VAR Byte ' character sent to LCD
index VAR Byte ' loop counter
value VAR Word ' value to print
width VAR Nib ' width of print field
pad VAR Nib ' spaces for rj printing
idx VAR Byte ' loop counter
'
[noparse][[/noparse] EEPROM Data ]
Msg DATA "Transmitter on" ' preload message
Msg1 DATA "Press the button"
Msg2 DATA "Dist is: "
'
[noparse][[/noparse] Main Code ]
Start:
FOR index = 0 TO 8
READ Msg + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
NEXT
width = 4
GOSUB LCD_Put_RJ_Value
PAUSE 1000 ' wait 2 seconds
char = DDRam ' clear the LCD
GOSUB LCDcmd
PAUSE 500
FOR index = 0 TO 8
READ Msg1 + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
GOSUB UserWait
NEXT
width = 4
GOSUB LCD_Put_RJ_Value
PAUSE 1000 ' wait 2 seconds
char = DDRam ' clear the LCD
GOSUB LCDcmd
PAUSE 500
PULSOUT 10, 100
OUTPUT 10 'mini delay
RCTIME 12, 1, time
dist = 343 * time
FOR index = 0 TO 8
READ Msg2 + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
NEXT
width = 4
value = dist
GOSUB LCD_Put_RJ_Value
PAUSE 1000 ' wait 2 seconds
char = DDRam ' clear the LCD
GOSUB LCDcmd
PAUSE 500
'HIGH 14
'PAUSE 100
GOTO Start 'Do it all over again
'
[noparse][[/noparse] Subroutines ]
' Send command to the LCD
'
LCDcmd: LOW RS ' enter command mode
' Write one ASCII char to LCD at current location
'
LCDwr:
OUTA = char.HIGHNIB ' output high nibble
PULSOUT E, 1 ' strobe the Enable line
OUTA = char.LOWNIB ' output low nibble
PULSOUT E, 1 ' strobe the Enable line
HIGH RS ' return to character mode
RETURN
LCD_Put_RJ_Value:
FOR idx = (width - pad - 1) TO 0
char = value DIG idx + "0"
GOSUB LCDwr
NEXT
RETURN
UserWait:
INPUT 0
RCTIME 0, 1, value
IF value = 0 THEN UserWait
RETURN
This is my code for ultrasound range finder. We designed both the transmitter and receiver circuit of the ultrasound range finder. When we turn on all the circuits, we would like the LCD to display, "Transmitter on" and then "Press the button." Once the user presses the button, then we want the LCD to display time and distance. Here's my code that I have so far. It's not working. I'm wondering if my syntax is incorrect. If there's more efficient way of displaying data LCD using other commands such as SERIN, please let me know. I'm still getting my feet wet with Basic Stamp 2.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Constants ]
' Ports used
RS CON 4 ' Register Select (1 = char)
E CON 5 ' LCD Enable pin (1 = enabled)
' LCD control characters
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
'
[noparse][[/noparse] Initialization ]
'
Init: DIRL = %00111111 ' set pins 0-5 as outputs
OUTS = $0000 ' clear the pins
' Initialize the LCD (Hitachi HD44780 controller)
'
LCDinit: PAUSE 500 ' Wait for LCD init
' =================================
' STANDARD HITACHI 44780 4-BIT INIT
' =================================
char=%00000011 ' Set 8-bit mode (1)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (2)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (3)
GOSUB LCDcmd
char=%00000010 ' Set 4-bit mode
GOSUB LCDcmd
char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
GOSUB LCDcmd ' 10xx = 5x8 matric
char=%00000000 ' Display control mode
GOSUB LCDcmd
char=%00001000 ' Set display OFF, cursor OFF, blink OFF
GOSUB LCDcmd
char=%00000000 ' Display control mode
GOSUB LCDcmd
char=%00001111 ' Set display ON, cursor ON, blink ON
GOSUB LCDcmd ' 11CB -> C=1 cursor on, B=1 blink on
char=%00000000 ' Entry control mode
GOSUB LCDcmd
char=%00000110 ' Set cursor right, no display shift
GOSUB LCDcmd ' 01IS -> I=1 cursor right, S=1 shift display
char = ClrLCD ' Clear LCD
GOSUB LCDcmd
'
[noparse][[/noparse] Variables ]
time VAR Word
dist VAR Word
char VAR Byte ' character sent to LCD
index VAR Byte ' loop counter
value VAR Word ' value to print
width VAR Nib ' width of print field
pad VAR Nib ' spaces for rj printing
idx VAR Byte ' loop counter
'
[noparse][[/noparse] EEPROM Data ]
Msg DATA "Transmitter on" ' preload message
Msg1 DATA "Press the button"
Msg2 DATA "Dist is: "
'
[noparse][[/noparse] Main Code ]
Start:
FOR index = 0 TO 8
READ Msg + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
NEXT
width = 4
GOSUB LCD_Put_RJ_Value
PAUSE 1000 ' wait 2 seconds
char = DDRam ' clear the LCD
GOSUB LCDcmd
PAUSE 500
FOR index = 0 TO 8
READ Msg1 + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
GOSUB UserWait
NEXT
width = 4
GOSUB LCD_Put_RJ_Value
PAUSE 1000 ' wait 2 seconds
char = DDRam ' clear the LCD
GOSUB LCDcmd
PAUSE 500
PULSOUT 10, 100
OUTPUT 10 'mini delay
RCTIME 12, 1, time
dist = 343 * time
FOR index = 0 TO 8
READ Msg2 + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
NEXT
width = 4
value = dist
GOSUB LCD_Put_RJ_Value
PAUSE 1000 ' wait 2 seconds
char = DDRam ' clear the LCD
GOSUB LCDcmd
PAUSE 500
'HIGH 14
'PAUSE 100
GOTO Start 'Do it all over again
'
[noparse][[/noparse] Subroutines ]
' Send command to the LCD
'
LCDcmd: LOW RS ' enter command mode
' Write one ASCII char to LCD at current location
'
LCDwr:
OUTA = char.HIGHNIB ' output high nibble
PULSOUT E, 1 ' strobe the Enable line
OUTA = char.LOWNIB ' output low nibble
PULSOUT E, 1 ' strobe the Enable line
HIGH RS ' return to character mode
RETURN
LCD_Put_RJ_Value:
FOR idx = (width - pad - 1) TO 0
char = value DIG idx + "0"
GOSUB LCDwr
NEXT
RETURN
UserWait:
INPUT 0
RCTIME 0, 1, value
IF value = 0 THEN UserWait
RETURN