' ========================================================================= ' ' File....... SW21-EX11-LCD_Demo.BSP ' Purpose.... Essential LCD control ' Author..... (C) 2000 - 2005, Parallax, Inc. ' E-mail..... support@parallax.com ' Started.... ' Updated.... 16 AUG 2006 ' ' {$STAMP BS2p} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This program demonstrates essential character LCD control. ' ' The connections for this program conform to the BS2p-family LCDCMD, ' LCDIN, and LCDOUT instructions. Use this program for the BS2p, BS2pe, ' or BS2px. There is a separate program for the BS2, BS2e, and BS2sx. ' -----[ I/O Definitions ]------------------------------------------------- E PIN 1 ' Enable pin ' -----[ Constants ]------------------------------------------------------- LcdCls CON $01 ' clear the LCD LcdHome CON $02 ' move cursor home LcdCrsrL CON $10 ' move cursor left LcdCrsrR CON $14 ' move cursor right LcdDispL CON $18 ' shift chars left LcdDispR CON $1C ' shift chars right LcdDDRam CON $80 ' Display Data RAM control LcdCGRam CON $40 ' Character Generator RAM LcdLine1 CON $80 ' DDRAM address of line 1 LcdLine2 CON $C0 ' DDRAM address of line 2 #DEFINE _NotLcdReady = ($STAMP < BS2P) ' -----[ Variables ]------------------------------------------------------- char VAR Byte ' character sent to LCD idx VAR Byte ' loop counter ' -----[ EEPROM Data ]----------------------------------------------------- Msg DATA "The BASIC STAMP!", 0 ' store message ' -----[ Initialization ]-------------------------------------------------- Check_Stamp: #IF _NotLcdReady #THEN #ERROR "Please use BS2 version: SW21-EX11-LCD_Demo.BS2" #ENDIF PAUSE 100 ' let the LCD settle Lcd_Setup: LCDCMD E, %00110000 : PAUSE 5 ' 8-bit mode LCDCMD E, %00110000 : PAUSE 0 LCDCMD E, %00110000 : PAUSE 0 LCDCMD E, %00100000 : PAUSE 0 ' 4-bit mode LCDCMD E, %00001100 : PAUSE 0 ' on, no crsr, no blink LCDCMD E, %00000110 ' inc crsr, no disp shift ' -----[ Program Code ]---------------------------------------------------- Main: LCDCMD E, LcdCls ' clear the LCD PAUSE 500 idx = Msg ' get EE address of message Write_Message: DO READ idx, char ' get character from EE IF (char = 0) THEN EXIT ' if 0, message is complete LCDOUT E, 0, [char] ' write the character idx = idx + 1 ' point to next character LOOP PAUSE 2000 ' wait 2 seconds Cursor_Demo: LCDCMD E, LcdHome ' move the cursor home PAUSE 1 LCDCMD E, %00001110 ' turn the cursor on PAUSE 500 FOR idx = 1 TO 15 ' move cursor l-to-r LCDCMD E, LcdCrsrR PAUSE 150 NEXT FOR idx = 14 TO 0 ' move cursor r-to-l by char = LcdDDRam + idx ' moving to a specific LCDCMD E, char ' column PAUSE 150 NEXT LCDCMD E, %00001101 ' cursor off, blink on PAUSE 2000 LCDCMD E, %00001100 ' blink off Flash_Demo: FOR idx = 1 TO 10 ' flash display char = char ^ %00000100 ' toggle display bit LCDCMD E, char PAUSE 250 NEXT PAUSE 1000 Shift_Demo: FOR idx = 1 TO 16 ' shift display LCDCMD E, LcdDispR PAUSE 100 NEXT PAUSE 1000 FOR idx = 1 TO 16 ' shift display back LCDCMD E, LcdDispL PAUSE 100 NEXT PAUSE 1000 GOTO Main ' do it all over ' -----[ Subroutines ]-----------------------------------------------------