• PicŪ Basic


  • Interfacing with a 40 x 4 alpha LCD display

    This item was begun by Rick (RCurl) in the old Forum. It is worth including here in the Wiki. The essential problem is that some 4 line displays need two enable pins - the display functions as if it is 2 separate two line displays with all but the enable pins being shared.

    Tim Box developed a solution to interfacing 4 line LCDs and came up with the routine at the link shown.
    ( Because the mneumonic MOVFW is not recognised by the latest version of the optimiser, John Drew has changed all MOVFW instructions to MOVF to allow the optimiserin PDS to work.) Edit on 29/11/11 to add the macros, omitted in error by JD.

    Print4line code

    Save the code and then include it as shown in the example.

    Code:
    Device 18F4685
    
    Declare Xtal 8
    Declare PLL_Req = On 
    
    All_Digital=true
    'setup alternative system for 4 line LCD
        #disable Print
        #disable Cursor
        #enable DelayUS
     
     
        Dim BPF As Byte System
        Dim BPFH As Byte System
        Dim GEN As Byte System
        Dim PP0 As Byte System
        Dim PP0H As Byte System
        Dim PP3 As Byte System
        Dim PP3H As Byte System
        Dim PP4 As Byte System
        Dim PP5 As Byte System
    
        Dim LCD#ENPINSELECT1 As Bit
        Dim LCD#ENPINSELECT2 As Bit
        
        Symbol LCD#DATAUS = 50
        Symbol LCD#COMMANDUS = 2000
        Symbol LCD_ENPORT2 = PORTE  
        Symbol LCD_ENPIN2= 2        'the additional enable pin is on port E.2
    
        LCD_DTPin = PORTB.4    
        LCD_RSPin = PORTB.3         
        LCD_ENPin = PORTB.2         
        LCD_Interface = 4            '4-bit Interface
        LCD_Lines = 2                 'in this case 2 lots of 2 lines
        LCD_Type = 0  
    
    
        Declare Float_Rounding=On
        Declare Float_Display_Type = fast 
                            
    TRISB=%000000            'set ports for required input or output 
    TRISE=%000000  
    
        LCDCURSOR_12 Macro
        LCD#ENPINSELECT1 = 1
        LCD#ENPINSELECT2 = 0
        Endm
        
        LCDCURSOR_34 Macro
        LCD#ENPINSELECT1 = 0
        LCD#ENPINSELECT2 = 1
        Endm    
    
        LCDCURSOR_1234 Macro
        LCD#ENPINSELECT1 = 1
        LCD#ENPINSELECT2 = 1
        Endm 
        
    Include "Print4line.inc"                 '4 line routines
    
    Test:
        LCDCURSOR_12                      'switch enable for first two lines
        Print At 1,1, "Test line 1" 
        Print at 2,1, "Test line 2"
            
       LCDCURSOR_34                      'switch enable for the second set
       Print At 1,1, "Test line 3"
       Print at 2,1, "Test line 4"
    
    End
    The TRIS registers will need to be set to make the Ports B2-7 and E.2 outputs.
    This article was originally published in forum thread: Interfacing with a 40 x 4 alpha LCD display started by rcurl View original post
  • Recent Activity

    teo-16018

    Microsoft security essentials blues

    Thread Starter: shantanu@india

    Hi, A strange thing happened just now.My Windows 7 Micrsoft Sercurity Essentials suddenly gave a warning that prplus.exe(Compiler) is a potential...

    teo Today, 19:23 Go to last post
    pic-ignorant-1162

    Proton Runtime Error

    Thread Starter: Paulcc

    I have proton running well on my laptop, but after installing it on my desktop, I get the following runtime error: "Runtime Error 217 at 000709FC" I...

    pic-ignorant Yesterday, 22:11 Go to last post
    David Barker-251

    UMC bootloader 18F46K22

    Thread Starter: shunt010

    Hi all. I am trying to build a UMC bootloader file for the 18F46K22, and it doesn't appear to work. It returns (in the error log) Error ...

    David Barker Today, 11:20 Go to last post
    barak-1433

    SPI mssp

    Thread Starter: picprotonguy

    Just ordered Digital to Analog IC MCP4822 with SPI interface and immediately opened proton manual. I'm very disappointed, it looks like Proton...

    barak Today, 16:06 Go to last post