LCD on Any Pin

How do I scatter the pins of the LCD data bus across multiple ports with PicBasic Pro?

First, let me show you what a sample program might look like:

;----[ Change these to match your LCD ]--------------------------------------- 
LCD_DB4    VAR PORTA.0 
LCD_DB5    VAR PORTB.3 
LCD_DB6    VAR PORTB.7 
LCD_DB7    VAR PORTC.1 
LCD_RS     VAR PORTD.4 
LCD_E      VAR PORTA.1 
LCD_Lines  CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines) 
LCD_DATAUS CON 50 ' Data delay time in us 
LCD_COMMANDUS CON 2000 ' Command delay time in us 
INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****

;----[ Your Main program starts here ]---------------------------------------- 
LoopCount VAR WORD
PAUSE 500 : LCDOUT $FE,1 : PAUSE 250 ; Initialize LCD (You may not need this, 
                                     ; but some displays are picky) 

Main: 
    LCDOUT $FE,1 ; clear screen 
    LCDOUT $FE,$87,"Hello,",$FE,$C8,"From DT!"

    FOR LoopCount = 0 TO 65535 
        LCDOUT $FE,$80, IDEC LoopCount 
        LCDOUT $FE,$C0, IHEX4 LoopCount 
    NEXT LoopCount
GOTO Main

Pretty simple eh?
Just assign the Pins, Include the file, and away you go, using LCDOUT just like you always have.

Ok, so now for the other Simple part that can go tragically wrong if you're not careful.
Yes, ... that's right, ... I'm modifying the Library again.

Or, more accurately, ... "You" are modifying the Library.\\ And before "You" change anything,
"MAKE SURE" you have a backup of the file.
Don't blame me if it gets messed up and you don't have anything to restore it with. And, I will apologize to MeLabs Support ahead of time for the extra support calls this will generate.
Back it up! and they won't have a problem.

In your PBP folder (the one with PBPW.EXE in it), open the Library file for the type PIC you are using.
For 16F's open PBPPIC14.lib with Notepad.
For 18F's open PBPPIC18.lib
Search for this string ";* LCDOUT ". That's "semicolon star space LCDOUT space"
You should see a section that looks like this ...

;****************************************************************
;* LCDOUT     : Send char to LCD                                *
;*                                                              *
;* Input      : W = char                                        *
;* Output     : None                                            *
;*                                                              *
;* Notes      :                                                 *
;****************************************************************

    ifdef LCDOUTJ_USED
  LIST
LCDOUTJ    movf    FSR, W    ; Jumpman entry
  NOLIST
LCDOUT_USED = 1
    endif

    ifdef LCDOUT_USED
;****************************************************************
NEW Code goes here...
;****************************************************************
  LIST
LCDOUT  movwf   R3 + 1          ; Save char

That one is from PBPPIC14.lib, for PBPPIC18.lib the only difference is it will show FSR0L, instead of FSR.

Insert this code into the spot marked ''' NEW Code goes here...

It's very important that you get the EXACT line. Be careful.

;****************************************************************
;*               Added for HighJack                             *
;****************************************************************
HIGHJACK_USED = 1                                              ;*
LCDOUT_HIGHJACKED = 1                                          ;*
    ifdef HJ_LCDOUT                                            ;*
  LIST                                                         ;*
LCDOUT                                                         ;*
        L?GOTO  HJ_LCDOUT                                      ;*
  NOLIST                                                       ;*
    else                                                       ;*
;****************************************************************

Now, scroll down past the LCDOUT code, and you should see this ...

NOLIST
DUNN_USED = 1
PAUSEUS_USED = 1
    endif
;****************************************************************
 Second piece of NEW Code goes here ...
;****************************************************************
;* LOOK2      : Get data from any register                      *
;*                                                              *
;* Input      : R0 address / constant                           *
;*            : W data type                                     *
;* Output     : R0 result                                       *
;*                                                              *
;* Notes      :                                                 *
;****************************************************************

Insert this code into the spot marked Second piece of NEW Code goes here ...

;****************************************************************
;*               Modified for HighJack                          *
;****************************************************************
    endif

If you got it right, you can now use your HD44780 LCD on any pins you wish. If you got it wrong, restore the file you backed up (You did back it up, right?). Then try again. It work's. Really! Trust me!

GoodNote: This modification will NOT interfere with your normal PBP LCDOUT routines.
In order to invoke the Custom LCD port routines, the main file must have the statement ...

INCLUDE "LCD_AnyPin.pbp"

If that statement is NOT included in your program, the LCDOUT commands will work the same way they always have.

There are 2 files required to implement this approach ...

LCD_AnyPin.pbp
VirtualPort.bas -- (Included from the LCD_AnyPin.pbp file)
Both files are included in the Zip file below. Extract them to your PBP folder.

LCD_AnyPin.zip

Page last modified on March 03, 2018, at 04:10 AM