' ========================================================================= ' File: LCDDEMO.BS2 ' ' BASIC LCD demonstration ' Ver 1.1 - Updated to conform to BS2p LCD connections ' ========================================================================= E CON 1 ' LCD Enable pin (1 = enabled) RS CON 3 ' Register Select (1 = char) LCDout VAR OutD ' 4-bit LCD data 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 char VAR Byte ' character sent to LCD index VAR Byte ' loop counter ' ------------------------------------------------------------------------- Msg DATA "THE BASIC STAMP!",0 ' preload EEPROM with message ' ------------------------------------------------------------------------- Initialize: DirL = %11111001 ' setup pins for LCD DirH = %11111111 GOSUB LCDinit ' initialize LCD for 4-bit mode ' ------------------------------------------------------------------------ END Main: char = ClrLCD ' clear the LCD GOSUB LCDcommand PAUSE 500 index = Msg ' get EE address of message ReadChar: READ index, char ' get character from EEPROM IF char = 0 THEN MsgDone ' if 0, message is complete GOSUB LCDwrite ' write the character index = index + 1 ' point to next character GOTO ReadChar ' go get it MsgDone: ' the message is complete PAUSE 2000 ' wait 2 seconds char = CrsrHm ' move the cursor home GOSUB LCDcommand END ' ------------------------------------------------------------------------- LCDinit: PAUSE 500 ' let the LCD settle LCDout = %0011 ' 8-bit mode PULSOUT E,1 PAUSE 5 PULSOUT E,1 PULSOUT E,1 LCDout = %0010 ' 4-bit mode PULSOUT E,1 char = %00101000 ' 4 lines GOSUB LCDcommand char = %00001111 ' disp on, crsr off, blink off GOSUB LCDcommand char = %00000110 ' inc crsr, no disp shift GOSUB LCDcommand char = %00000001 ' cls GOSUB LCDcommand char = "C" GOSUB LCDwrite char = "h" GOSUB LCDwrite char = "r" GOSUB LCDwrite char = "i" GOSUB LCDwrite char = "s" GOSUB LCDwrite RETURN LCDcommand: LOW RS ' enter command mode LCDout = char.HighNib ' output high nibble PULSOUT E,1 ' strobe the Enable line LCDout = char.LowNib ' output low nibble PULSOUT E,1 HIGH RS RETURN ' return to character mode LCDwrite: LCDout = char.HighNib ' output high nibble HIGH E LOW E LCDout = char.LowNib ' output low nibble HIGH E LOW E RETURN