Shop OBEX P1 Docs P2 Docs Learn Events
Displaying Variable Data on a Parallel LCD — Parallax Forums

Displaying Variable Data on a Parallel LCD

mascagnicmascagnic Posts: 2
edited 2008-12-07 19:38 in BASIC Stamp
I am doing a project for a digital electronics class at UW Platteville. I need help to figure out how to get data from a SHT15 to display on a parallel 2x16 Hitachi LCD. The code for the sht is barrowed from EME system web page at http://www.emesystems.com/OL2sht1x.htm. I've tried to use the various code examples from parallax and i can't seem to·get them to work to gether. The code is as follows:
'=============================================================
' {$STAMP BS2}
' {$PBASIC 2.5}
'
'
'
'
'
'
'=====[noparse][[/noparse]I/O Configerations]====================================
'
LCD I/O Configerations
E········· PIN 1
RW········ PIN 2
RS········ CON 3
LCDBus···· VAR OUTB
LcdBusOut· VAR OUTB ' 4-bit LCD data bus
LcdBusIn·· VAR INB
'
SHT I/O Configerations
sck······· PIN· 14
dta······· PIN· 15
dtain····· VAR· IN15
'=====[noparse][[/noparse]Constants]=============================================
'
LCD Constants
LcdClrs· CON· $01
LcdHome· CON· $02
LcdCrsrL CON· $10
LcdCrsrR CON· $14
LcdDispL CON· $18
LcdDispR CON· $1C
LcdDDRAM CON· $80
LcdCGRAM CON· $40
LcdLine1 CON· $80
LcdLine2 CON· $C0
'
SHT Constants
shtTR··· CON· 3
shtRH··· CON· 5
shtSW··· CON· 6
shtSR··· CON· 7
shtS0··· CON· 30
'=====[noparse][[/noparse]variables]=============================================
'
LCD Variables
char··· VAR· Word
idx···· VAR· Byte
tempOut VAR· Byte
rhOut·· VAR· Byte
temp··· VAR· Word

'
SHT Variables
cmd···· VAR· Byte
result· VAR· Word
r0····· VAR· result.BYTE0
r1····· VAR· result.BYTE1
degC··· VAR· Word
RH····· VAR· Word
RHtc··· VAR· Word
'=====[noparse][[/noparse]EEPROM]================================================
MSG1 DATA "Temperature: "
MSG2 DATA "RHumidity: "
'=====[noparse][[/noparse]Initialization]=======================================
'
LCD Initialization
DIRL = %11111110······· 'Set up pins for Display
PAUSE 100
Lcd_Setup:
· LcdBusOut = %0011···· ' 8-bit mode
··· PULSOUT E, 3
··· PAUSE 5
··· PULSOUT E, 3
··· PULSOUT E, 3
· LcdBusOut = %0010···· ' 4-bit mode
··· PULSOUT E, 1
· char = %00101000····· ' multi-line mode
··· GOSUB LCD_Cmd
· char = %00001100····· ' disp on, no crsr or blink
··· GOSUB LCD_Cmd
· char = %00000110····· ' inc crsr, no disp shift
··· GOSUB LCD_Cmd
Display:

'
SHT Initialization
OUTS = 0
DIRS = %1111111111111101
GOSUB shtrst
'=====[noparse][[/noparse]Program]====================================================
'
SHT Main Program
DO
· getTemperature:
··· cmd = shtTR
··· GOSUB shtget16
··· degC = result + 5/10-400
· getHumidity:
··· cmd = shtRH
··· GOSUB shtget16
··· RH = (26542-(54722**result + result))**result-40
··· RHtc = 655+(result*5)+(result**15917)
··· RHtc = (RHtc**(degC+2480))-(RHtc**2730)+RH
··· PAUSE 1000
LOOP
'
LCD Main Program
Main:
· char = LcdClrs ' clear the LCD
· GOSUB LCD_Cmd
· PAUSE 250
·· idx = MSG1
· char = tempOut
· FOR idx = 0 TO 15 ' get message from EEPROM
··· READ (Msg1 + idx), char ' read a character
··· GOSUB LCD_Out ' write it
· NEXT
· PAUSE 1000 ' wait 2 seconds
Animation:
·'idx = MSG2
·char = rhOut
FOR idx = 0 TO 15 ' cover 16 characters
· READ (Msg2 + idx), char ' get new char from Msg2
'FOR idx2 = 0 TO 4 ' 5 characters in cycle
'char = LcdLine2 + idx1 ' set new DDRAM address
'GOSUB LCD_Cmd ' move cursor position
'LOOKUP idx2, [noparse][[/noparse]0, 1, 2, 1, newChar], char ' get animation "frame"
GOSUB LCD_Out ' write "frame"
'PAUSE 100 ' animation delay
NEXT
'NEXT
PAUSE 2000
GOTO Main
'=====[noparse][[/noparse]Sub-Routines=================================================
'
LCD Sub-Routines
LCD_Cmd:
· LOW RS ' enter command mode
LCD_Out:
· LcdBusOut = char.HIGHNIB ' output high nibble
··· PULSOUT E, 3 ' strobe the Enable line
· LcdBusOut = char.LOWNIB ' output low nibble
··· PULSOUT E, 3
··· HIGH RS ' return to character mode
··· RETURN
'
SHT Sub-Routines
shtRst:
· SHIFTOUT dta, sck, LSBFIRST, [noparse][[/noparse]$ffff/16]
· RETURN
shtget16:
· GOSUB shtcmd
· GOSUB shtwait
· SHIFTIN dta, sck, MSBPRE, [noparse][[/noparse]r1]
· LOW dta
· PULSOUT sck, 10
· INPUT dta
· SHIFTIN dta, sck, MSBPRE, [noparse][[/noparse]r0]
· INPUT dta
· PULSOUT sck, 10
· RETURN
shtcmd:
· shtStart:
··· INPUT dta
··· HIGH sck
··· LOW dta
··· LOW sck
··· HIGH sck
··· INPUT dta
··· LOW sck
· shtcmd1:
··· SHIFTOUT dta, sck, MSBFIRST, [noparse][[/noparse]cmd]
··· INPUT dta
··· PULSOUT sck, 10
··· RETURN
shtWait:
· result = 4096
· DO
··· result = result -1
· LOOP WHILE dta & result.BIT11
· RETURN

The main problem is getting any thing useful to display. I can get both the sht and the LCD to work seperately. but that is where it stops working. It is also possiable the the DIRS and DIRL pin assignments are conflicting and creating a problem also. Any help would be greatly appreciated. Thanks for any help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-07 16:14
    I didn't look at your program in detail, but you're correct that the direction register settings you're using conflict. DIRL is just the lower 8 bits of DIRS. When you later set DIRS to %1111111111111101, you're setting DIRL to %11111101 which makes the E pin an input (not what you want).

    I'd leave the LCD initialization the same, but change the SHT initialization by removing the assignments to OUTS and DIRS and just saying "LOW clk". The dta pin changes back and forth between input and output mode, so it doesn't matter what state it's in initially.
  • mascagnicmascagnic Posts: 2
    edited 2008-12-07 19:10
    Thank you for responding Mike. I did that and it didn't seem to make a differance.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-07 19:38
    You have to back up a step or two. You haven't integrated the two pieces of the program (LCD and SHT) at all. I had just glanced at how you used the I/O registers and hadn't noticed the details of the program.

    Start with the LCD program. You have to learn how it works from the documentation well enough so you can display the values that you need. You'll need to display the numeric value of a variable called "degC" and the numeric value of a variable called "RHtc" and display them in the proper positions of the display, never mind now where they come from. They can be set to constants in your program's initialization. If you don't know how to display a numeric value, have a look at the DIG operator in the Basic Stamp Manual, then come back with any specific questions.

    Nuts and Volts Column #31 (www.parallax.com/Resources/NutsVoltsColumns/tabid/272/Default.aspx) discusses the use of a parallel LCD that's 16 x 1, but the same applies to a 16 x 2 display.
Sign In or Register to comment.