Shop OBEX P1 Docs P2 Docs Learn Events
Jon, where... — Parallax Forums

Jon, where...

studentstudent Posts: 12
edited 2004-12-01 03:08 in BASIC Stamp
I am getting closer; LCD now reads "Present Temp =" Where do I insert the ShowTemp_LCD to display the temp? I've tried a lot of combinations, but...(guess I don't know what to do).

' {$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:
·' char = CrsrHm································ ' What do I do???
· 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

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:
· char = CrsrHm
· GOSUB LCDcommand
·char = %00001110
· GOSUB LCDcommand
·' RETURN

'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

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-30 18:48
    Since you're using somewhat dated code, I've gone ahead and fixed up the whole program using newer code fragments I have from recent projects. Note that my connections are different from yours -- my LCD connections match that of the BS2p and BS2pe so that the project with work with them as well (it does, I tested it). This should give you something to chew on for a while; but please make sure you understand it completely before attempting to modify it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • studentstudent Posts: 12
    edited 2004-12-01 03:08
    THANK-YOU very much! I was able to adapt the program to my application, and it works beautifully.
Sign In or Register to comment.