'===== PICnLCD.BAS =================================================== BX-24 == ' ' This module contains routines for the PIC-n'-LCD 4x20 serial LCD module. ' It assumes the LCD input is connected to BX-24 pin-1 ' ' 1999/11/02 Created by Nick Taylor ntaylor@iname.com ' 1999/11/04 Added LCDPutByte() & LCDPutStr() ' ' Requires: ' SerialPort_24.bas ' Support_24.bas ' ' The PICnLCD module by Dale Wheat is available from: ' Peter Anderson at: http://www.phanderson.com ' B.G. Micro at: http://www.bgmicro.com '------------------------------------------------------------------------------ ' PICnLCD commands: ' &h01 - Cursor Address - Next byte is the location on the LCD panel: ' &h00 - 00 - beginning of line 1 ' &h40 - 64 - beginning of line 2 ' &h14 - 20 - beginning of line 3 ' &h54 - 84 - beginning of line 4 ' &h02 - Home Cursor - Moves cursor to location 00, does not affect display. ' &h03 - Cursor Left - Moves cursor one position left. Nondestructive. ' &h04 - Cursor Right - Moves cursor one position right. Nondestructive. ' &h05 - Save Cursor Position - Saves the current cursor position. ' &h06 - Restore Cursor Position - Restores cursor to previously stored address. ' &h07 - Bell - Sounds tone for about 0.1 seconds. ' &h08 - Backspace - Destructive backspace. ' &h09 - Horizontal Tab - Advances cursor four places to the right. ' &h0A - Line Feed - Moves cursor to the same position on the next line. ' &h0B - Vertical Tab - The display scrolls up one line. Cursor doesn't move. ' &h0C - Form Feed - Clears display and homes cursor. ' &h0D - Carriage Return - Moves cursor to beginning of current line. ' &h0D - Shift Left - Entire display shifts one place left. ' &h0F - Shift Right - Entire display shifts one place right. ' &h11 - Send LCD Instruction - Next byte is sent to the instruction register. ' &h12 - Send LCD Data - Next byte is displayed. ' &h13 - Set Number of Lines - Next bytes sets number of lines (4 is default). ' &h15 - General Purpose Output - Next byte is GP0 thru GP4. ' &h16 - Print Signed Decimal Number - Displays next byte as signed decimal. ' &h17 - Print Unsigned Decimal Number - Displays next byte as unsigned decimal. ' &h19 - Set Cursor Display Options - Next byte defines cursor style. ' &h00 - no cursor ' &h01 - blinking block ' &h02 - underline ' &h03 - blinking block and underline '============================================================================== ' Cursor type commands for use by LCDCursorType(type) public const None as BYTE = &h00 public const BlinkBlock as BYTE = &h01 public const Underline as BYTE = &h02 public const BlockUnderline as BYTE = &h03 '------------------------------------------------------------------------------ public sub LCDInit() ' Open pin-1 for 9600 baud. CALL OpenSerialPort_1(9600) ' Turn LEDs off. CALL LCDPutByte(&h15) CALL LCDPutByte(&h00) ' Clear the screen. CALL LCDPutByte(&h0C) ' Set the cursor to disabled. CALL LCDPutByte(&h19) CALL LCDPutByte(&h00) ' Move the cursor to row 2, col 3. CALL LCDPutByte(&h01) CALL LCDPutByte(&h43) END sub '------------------------------------------------------------------------------ public sub LCDCursorType( _ ByVal Type as BYTE) ' Sets the cursor type. CALL LCDPutByte(&h19) CALL LCDPutByte(Type) END sub '------------------------------------------------------------------------------ public sub LCDClearScreen() ' Clears the screen and homes the cursor. CALL LCDPutByte(&h0C) END sub '------------------------------------------------------------------------------ public sub LCDHomeCursor() ' Moves cursor to row 1, col 1. CALL LCDPutByte(&h02) END sub '------------------------------------------------------------------------------ public sub LCDPutCursor( _ ByVal Line as BYTE, _ ByVal Column as BYTE) ' Moves the cursor to the commanded line (1-4) and row (1-20). IF ((Column < 1) OR (Column > 20)) THEN CALL LCDFail(1) END IF CALL LCDPutByte(&h01) SELECT CASE Line CASE 1 CALL LCDPutByte(Column - 1) CASE 2 CALL LCDPutByte(64 + Column - 1) CASE 3 CALL LCDPutByte(20 + Column - 1) CASE 4 CALL LCDPutByte(84 + Column - 1) CASE ELSE CALL LCDFail(2) END SELECT END sub '------------------------------------------------------------------------------ public sub LCDBackspace() ' Does a single destructive backspace. CALL LCDPutByte(&h08) END sub '------------------------------------------------------------------------------ public sub LCDPutByte( _ ByVal n as BYTE) CALL PutByte_1(n) END sub '------------------------------------------------------------------------------ public sub LCDPutStr( _ ByRef txt as STRING) CALL PutStr_1(txt) END sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private sub LCDFail( _ ByVal flashes as BYTE) ' Flashes the on chip LEDs to indicate a failure. Two green flashes indicate ' the PICnLCD followed by one red flash for a column error or two flashes for ' a row error. CALL PutPin(GreenLED, 1) ' Green LED off. CALL PutPin(RedLED, 1) ' Red LED off. DO CALL FlashLED(GreenLED, 2) CALL FlashLED(RedLED, flashes) LOOP END sub '==============================================================================