' ========================================================================= ' ' File....... LCD_AppMod_Demo.BS1 ' Purpose.... Demonstrates the LCD Terminal AppMod ' Author..... Parallax, Inc. (Copyright 2003-04, All Rights Reserved) ' E-mail..... support@parallax.com ' Started.... ' Updated.... 13 JAN 2004 ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This program demonstrates the use of the Parallax LCD Terminal AppMod ' with a BS1 microcontroller. Note that due to code space limitations and ' GOSUB stack restrictions, this version is dramatically simpler than its ' BS2 and Javelin counterparts. ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL E = 1 ' LCD Enable (1 = enabled) SYMBOL RW = 2 ' Read/Write\ SYMBOL RS = 3 ' Reg Select (1 = char) ' -----[ Constants ]------------------------------------------------------- SYMBOL LcdCls = $01 ' clear the LCD SYMBOL LcdHome = $02 ' move cursor home SYMBOL LcdCrsrL = $10 ' move cursor left SYMBOL LcdCrsrR = $14 ' move cursor right SYMBOL LcdDispL = $18 ' shift chars left SYMBOL LcdDispR = $1C ' shift chars right SYMBOL LcdDDRam = $80 ' Display Data RAM control SYMBOL LcdCGRam = $40 ' Character Generator RAM SYMBOL LcdLine1 = $80 ' DDRAM address of line 1 SYMBOL LcdLine2 = $C0 ' DDRAM address of line 2 ' -----[ Variables ]------------------------------------------------------- SYMBOL buttons = B0 SYMBOL btnA = BIT0 ' left-most button SYMBOL btnB = BIT1 SYMBOL btnC = BIT2 SYMBOL btnD = BIT3 ' right-most SYMBOL addr = B1 ' address pointer SYMBOL char = B2 ' character sent to LCD SYMBOL idx = B3 ' loop counter SYMBOL scan = B4 ' button scan counter ' -----[ EEPROM Data ]----------------------------------------------------- Messages: EEPROM ("PARALLAX", 0) EEPROM ("Buttons:", 0) ' -----[ Initialization ]-------------------------------------------------- Setup: NAP 5 ' let LCD self-initialize DIRS = %11111110 ' LCD pins are outputs LCD_Init: PINS = %00110000 ' 8-bit mode PULSOUT E, 1 PAUSE 5 PULSOUT E, 1 PULSOUT E, 1 PINS = %00100000 ' 4-bit mode PULSOUT E, 1 char = %00101000 ' 2-line mode GOSUB LCD_Command char = %00001100 ' on, no crsr, no blink GOSUB LCD_Command char = %00000110 ' inc crsr, no disp shift GOSUB LCD_Command ' -----[ Program Code ]---------------------------------------------------- Main: char = LcdCls ' clear the LCD GOSUB LCD_Command PAUSE 500 Write_Parallax: ' put "Parallax" on line 1 FOR idx = $00 TO $07 READ idx, char GOSUB LCD_Write_Char NEXT PAUSE 1500 Show_Buttons: char = LcdCls GOSUB LCD_Command FOR idx = $09 TO $10 ' put "Buttons:" on line 1 READ idx, char GOSUB LCD_Write_Char NEXT FOR idx = 1 TO 100 GOSUB LCD_Get_Buttons ' read/debounce buttons char = LcdLine2 + 2 ' show on 2nd line GOSUB LCD_Command char = 20 * btnA + "-" ' display buttons GOSUB LCD_Write_Char char = 21 * btnB + "-" GOSUB LCD_Write_Char char = 22 * btnC + "-" GOSUB LCD_Write_Char char = 23 * btnD + "-" GOSUB LCD_Write_Char NEXT GOTO Main ' run demo again END ' -----[ Subroutines ]----------------------------------------------------- ' Send command to LCD ' -- put command byte in 'char' ' -- falls through to LCD_Write_Char LCD_Command: LOW RS ' enter command mode ' Write character to current cursor position ' -- but byte to write in 'char' LCD_Write_Char: PINS = PINS & %00001001 ' clear bus; save RS, P0 PINS = char & $F0 | PINS ' -> high nib PULSOUT E, 1 ' strobe the E PINS = PINS & %00001001 PINS = char * 16 | PINS ' -> low nib PULSOUT E, 1 HIGH RS ' return to character mode RETURN ' Read and debounce the LCD AppMod buttons LCD_Get_Buttons: DIRS = DIRS & $0F ' make LCD bus inputs buttons = %11110000 ' assume all pressed FOR scan = 1 TO 10 buttons = buttons & PINS ' make sure button held PAUSE 5 ' debounce 10 x 5 ms NEXT buttons = buttons / 16 ' correct bit alignment DIRS = DIRS | $F0 ' return data lines to outputs RETURN