Shop OBEX P1 Docs P2 Docs Learn Events
no luck — Parallax Forums

no luck

studentstudent Posts: 12
edited 2004-11-30 06:15 in BASIC Stamp
I've tried a lot of things here, but still cannot get anything to display on LCD. Temp does show with DEBUG. Downloaded a known good LCD program, and that works, so circuit is O.K. The last code I tried is below. I appreciate any help.

' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ==============================================================================

'
' Program Description
'
' This program measures temperature using the Dallas Semiconductor DS1620
' temperature sensor and displays the results in fahrenheit.

'
' I/O Definitions
'
DQ············· CON···· 0·················· ' DS1620.1 (data I/O)
Clock·········· CON···· 1··················· ' DS1620.2
Reset·········· CON···· 2···················· ' DS1620.3
E·············· CON···· 8··················· ' LCD Enable pin· (1 = enabled)
RS············· CON···· 3······················ ' Register Select (1 = char)
'
' Constants
'
ClrLCD········· CON· $01···················· ' clear the LCD
CrsrHm········· CON· $02····················· ' move cursor to home position
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
RdTmp·········· CON···· $AA···················· ' read temperature
WrHi··········· CON···· $01····················· ' write TH (high temp)
WrLo··········· CON···· $02······················ ' write TL (low temp)
RdHi··········· CON···· $A1······················· ' read TH
RdLo··········· CON···· $A2······················ ' read TL
StartC········· CON···· $EE····················· ' start conversion
StopC·········· CON···· $22···················· ' stop conversion
WrCfg·········· CON···· $0C··················· ' write config register
RdCfg·········· CON···· $AC·················· ' read config register
'
' Variables
'
tempIn········· VAR···· Word··················· ' raw temperature
sign··········· VAR···· tempIn.BIT8············ ' 1 = negative temperature
tSign·········· VAR···· Bit
tempC·········· VAR···· Word··················· ' Celsius
tempF·········· VAR···· Word··················· ' Fahrenheit
LCDbus········· VAR···· OUTB··········· ' 4-bit LCD data
char··········· VAR···· Byte··········· ' character sent to LCD
index·········· VAR···· Byte············ ' space for index
'
' DATA statements
Msg· DATA "Present Temp = ", 0

'
' Initialization
'
Initialize:
·DIRL= %11111001·········· ' setup pins
· GOSUB LCDinit···················· ' initialize LCD for 4-bit mode
· HIGH Reset··································· ' alert the DS1620
· SHIFTOUT DQ, Clock, LSBFIRST, [noparse][[/noparse]WrCfg, %10]···· ' use with CPU; free-run
· LOW Reset
· PAUSE 10
· HIGH Reset
· SHIFTOUT DQ, Clock, LSBFIRST, [noparse][[/noparse]StartC]······· ' start conversions
· LOW Reset


'
' Program Code
'
Main:
·· char = ClrLCD
· GOSUB Get_Temperature························ ' read the DS1620
· DEBUG HOME
· DEBUG "---DS1620---·· ", CR
· DEBUG "Present Temperature =", CR
· DEBUG· SDEC··· tempC, " C··· ", CR
· DEBUG· SDEC··· tempF, " F··· ", CR
·· GOSUB· LCDcommand
··· PAUSE 500
··· index = Msg
· Read_Char:
· READ index, char
· IF char = 0 THEN MsgDone
· GOSUB LCDwrite
· index = index + 1
· GOTO Read_Char



·· PAUSE 1000
····································· ' pause between readings

'
' Subroutines
'
Get_Temperature:
· HIGH Reset··································· ' alert the DS1620
· SHIFTOUT DQ, Clock, LSBFIRST, [noparse][[/noparse]RdTmp]········· ' give command to read temp
· SHIFTIN DQ, Clock, LSBPRE, [noparse][[/noparse]tempIn\9]·········· ' read it in
· LOW Reset······································· ' release the DS1620
· tSign = sign································· ' save sign bit
· tempIn = tempIn / 2·························· ' round to whole degrees
· IF (tSign = 0) THEN No_Neg1
· tempIn = tempIn | $FF00························ ' extend sign bits for negative
No_Neg1:
· tempC = tempIn······························· ' save Celsius value
· tempIn = tempIn */ $01CC······················ ' multiply by 1.8
· IF (tSign = 0) THEN No_Neg2···················· ' if negative, extend sign bits
· tempIn = tempIn | $FF00
No_Neg2:
· tempIn = tempIn + 32························· ' finish C -> F conversion
· tempF = tempIn······························· ' save Fahrenheit value
· RETURN
·· LCDinit:
· PAUSE 500················· ' let the LCD settle
· LCDbus = %0011·············· ' 8-bit mode
· PULSOUT E,1
· PAUSE 5
· PULSOUT E,1
· PULSOUT E,1
· LCDbus = %0010·············· ' 4-bit mode
· PULSOUT E,1
· char = %00101000····················· ' multi-line mode
· GOSUB LCDcommand
· char = %00001100··········· ' disp on, crsr off, blink off
· GOSUB LCDcommand
· char = %00000110··········· ' inc crsr, no disp shift
· GOSUB LCDcommand
· RETURN
· LCDcommand:
·· LOW RS················· ' enter command mode
·· RETURN
LCDwrite:
· LCDbus = char.HIGHNIB·········· ' output high nibble
· PULSOUT E,1············· ' strobe the Enable line
· LCDbus = char.LOWNIB··········· ' output low nibble
· PULSOUT E,1
· HIGH RS················· ' return to character mode
· RETURN
· MsgDone:
·· PAUSE 500
· char = CrsrHm
· GOSUB LCDcommand
· char = %00001110
· GOSUB LCDcommand
· PAUSE· 500

·'ShowTemp_LCD:
· IF (tempF.BIT15 = 1) THEN········· ' check sign bit
··· char = "-"························ ' - for negative temp
· ELSE
··· char = " "························ ' blank for positive temp
· ENDIF
·' GOSUB LCDwrite······················ ' write sign character
· tempF = ABS tempIn··············· ' convert tempF to absolute value
· FOR index = 2 TO 0···················· ' loop through three digits
·· index = tempF DIG index + "0"······ ' get digit from temp, convert to decimal
··· GOSUB LCDwrite···················· ' write digit
· NEXT
· RETURN

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-30 06:06
    student -

    One of your problems lies here in the LCDcommand routine, where you are prematurely issuing a RETURN statement:

    LCDcommand:
    LOW RS ' enter command mode
    RETURN '<<-- REMOVE this line

    You may also want to download and incorporate Jon Willams excellent document "The Elements of PBASIC Style" so it will be easier for you and anyone else to read your program and see what it's doing. It's VERY difficult to read at present due to the lack of indenting. That style sheet can be found here:
    http://www.parallax.com/html_pages/downloads/basicstamps/documentation_basic_stamp.asp

    Regards,

    Bruce Bates
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-11-30 06:15
    It looks to me like your routine "LCDcommand" may have gotten trashed. It is only:

    LCDcommand:
    ·· LOW RS················· ' enter command mode
    ·· RETURN

    That does not actually send any command to the LCD. You probably want it to go right on into the LCDwrite routine without the RETURN. I think the first character of your message is being sent to the LCD as a command instead of data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.