18f4331 LCD Woes


Today 18:02
Forum: Proton Plus Compiler v3
Starter: towlerg
Views: 0
Replies: 0
Today 00:44
Forum: Proton Plus Compiler v3
Starter: davroski
Views: 0
Replies: 4
+ Reply to Thread
Results 1 to 6 of 6

Thread: 18f4331 LCD Woes16 days old

  1. #1
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,936
    Thumbs Up
    Received: 34
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default 18f4331 LCD Woes

    Morning All,
    It's been a while! I'm stuck on the simplest of things. I'm trying to print to a 4x20 LCD using a PIC-DIP40 board. Code below. I know the LCD is ok, because I have swapped out the 18F4331 for a 18F4580, 18f46K80 & 18F4520 and all 3 work fine. For some reason, I get a blank screen with the 18F4331. Has anybody managed to use an LCD with this PIC?

    Any tips most welcome!

    Device = 18F4331
    Config_Start
    OSC = IRC ;Internal oscillator block, CLKO function on RA6 and port function on RA7
    FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    IESO = OFF ;Internal External Switchover mode disabled
    PWRTEN = OFF ;PWRT disabled
    BOREN = On ;Brown-out Reset enabled
    BORV = 20 ;Reserved
    WDTEN = OFF ;WDT disabled (control is placed on the SWDTEN bit)
    WDPS = 32768 ;1:32768
    WINEN = OFF ;WDT window disabled
    PWMPIN = OFF ;PWM outputs disabled upon Reset (default)
    LPOL = High ;PWM0, 2, 4 and 6 are active-high
    HPOL = High ;PWM1, 3, 5 and 7 are active-high
    T1OSCMX = OFF ;Standard (legacy) Timer1 oscillator operation
    FLTAMX = RC1 ;FLTA input is multiplexed with RC1
    SSPMX = RC7 ;SCK/SCL clocks and SDA/SDI data are multiplexed with RC5 and RC4, respectively. SDO output is multiplexed with RC7.
    PWM4MX = RB5 ;PWM4 output is multiplexed with RB5
    EXCLKMX = RC3 ;TMR0/T5CKI external clock input is multiplexed with RC3
    MCLRE = On ;Enabled
    STVREN = On ;Stack full/underflow will cause Reset
    LVP = OFF ;Low-voltage ICSP disabled
    Debug = OFF ;Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
    Cp0 = OFF ;Block 0 (000200-000FFFh) not code-protected
    CP1 = OFF ;Block 1 (001000-001FFF) not code-protected
    CPB = OFF ;Boot Block (000000-0001FFh) not code-protected
    CPD = OFF ;Data EEPROM not code-protected
    WRT0 = OFF ;Block 0 (000200-000FFFh) not write-protected
    WRT1 = OFF ;Block 1 (001000-001FFF) not write-protected
    WRTC = OFF ;Configuration registers (300000-3000FFh) not write-protected
    WRTB = OFF ;Boot Block (000000-0001FFh) not write-protected
    WRTD = OFF ;Data EEPROM not write-protected
    EBTR0 = OFF ;Block 0 (000200-000FFFh) not protected from table reads executed in other blocks
    EBTR1 = OFF ;Block 1 (001000-001FFF) not protected from table reads executed in other blocks
    EBTRB = OFF ;Boot Block (000000-0001FFh) not protected from table reads executed in other blocks
    Config_End
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    Declare Xtal 8
    'Configure Internal Oscillator
    OSCCON.4 = 1
    OSCCON.5 = 1
    OSCCON.6 = 1

    'Set Port Directions
    TRISD = 0x00 ' all outputs
    TRISE = 0x00 ' all outputs

    'Disable Analogue function on all pins
    ANSEL0 = 0x00
    ANSEL1 = 0x00

    'Set up LCD
    Declare Float_Display_Type = Fast
    Declare LCD_Interface = 4
    Declare LCD_Lines = 4
    Declare LCD_Type ALPHA
    Declare LCD_DTPin = LATD.0
    Declare LCD_RSPin = LATE.0
    Declare LCD_RWPin = LATE.1
    Declare LCD_ENPin = LATE.2

    DelayMS 100
    Cls

    Main:
    Print At 1,1, " Line 1"
    Print At 1,1, " Line 2"
    Print At 1,1, " Line 3"
    Print At 1,1, " Line 4"
    DelayMS 1000
    Cls
    GoTo Main

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Prolific Poster rcurl's Avatar
    Join Date
    Mar 2002
    Posts
    1,819
    Thumbs Up
    Received: 36
    Given: 53
    Total Downloaded
    2.15 GB

    0 Not allowed!

    Default Re: 18f4331 LCD Woes

    Hi John-
    I'll bet one of the peripherals that share some of the LCD pins is unintentionally on.

    Even though the SSP is supposed to default to being off, you might declare SSPCON = 0 just to make sure.
    Beyond that i think I'd try to blink an LED on each of the pins going to the LCD to find out which one(s) is in trouble.

    -Rick

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,076
    Thumbs Up
    Received: 190
    Given: 169
    Total Downloaded
    4.66 GB

    0 Not allowed!

    Default Re: 18f4331 LCD Woes

    Very sage advise, particularly the blinky on each pin (especially as Alpha displays usually only use output pins)
    George.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,278
    Thumbs Up
    Received: 380
    Given: 137
    Total Downloaded
    1.59 GB

    1 Not allowed!

    Default Proton PIC18F4331 display on a 4x20 Alphanumeric LCD

    I've just ran a test with a 18F4331 in the simulator and the code below works:

    Code:
    '
    '   /\\\\\\\\\
    '  /\\\///////\\\
    '  \/\\\     \/\\\                                                 /\\\          /\\\
    '   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
    '    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
    '     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
    '      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
    '       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
    '        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
    '                                  Let's find out together what makes a PIC Tick!
    '
    ' Display on a 4x20 alphanumeric LCD
    ' Written for the Proton BASIC Compiler
    '
        Device = 18F4331
        Declare Xtal = 8
    '
    ' Setup the Alphanumeric LCD
    '
        Declare LCD_DTPin = LATD.0
        Declare LCD_RSPin = LATE.0
        Declare LCD_ENPin = LATE.2
        Declare LCD_Interface = 4
        Declare LCD_Lines = 4
        Declare LCD_Type = Alpha   
    
    '----------------------------------------------------------------------------------------
    ' Set the internal oscillator to 8MHz
    '
    Proc OSC_8()
        OSCCON = $70
        DelayMS 100             ' Wait for stabilisation
    EndProc
    
    '----------------------------------------------------------------------------------------
    ' The main program starts here
    '
    Main:
        OSC_8()         ' Set the internal oscillator to 8MHz
       
        Cls
        Print At 1, 1, "This is Line 1"
        Print At 2, 1, "This is Line 2"
        Print At 3, 1, "This is Line 3"
        Print At 4, 1, "This is Line 4"
        Stop
    
    '----------------------------------------------------------------------------------------
    ' Setup the fuses for an internal oscillator
    '
    Config_Start
        OSC = IRCIO         ' Internal RC, RA6 & RA7 are I/O
        FCMEN = Off         ' Fail-Safe Clock Monitor Disabled
        IESO = Off          ' Internal/External Switch-Over Disabled
        PWRTEN = On         ' Power-up Timer Enabled
        BOREN = On          ' Brown-out Reset Enabled
        BORV = 20           ' Brown-out Voltage 2.0V
        WDTEN = Off         ' Watchdog Timer Disabled
        WINEN = Off         ' Watchdog Timer Enable Window Disabled
        WDPS = 128          ' Watchdog Postscaler 1:128
        T1OSCMX = On        ' Timer1 Oscillator MUX Inactive
        HPOL = High         ' High-Side Transistors Polarity Active high
        LPOL = Low          ' Low-Side Transistors Polarity Active low
        PWMPIN = Off        ' PWM output pins Reset state control Disabled
        MCLRE = On          ' MCLR Enable Enabled
        EXCLKMX = RC3       ' External clock MUX bit Multiplexed with RC3
        PWM4MX = RB5        ' PWM4 MUX bitMultiplexed with RB5
        SSPMX = RD1         ' SDO output is multiplexed with RD1
        FLTAMX = RC1        ' FLTA MUX bit Multiplexed with RC1
        STVREN = Off        ' Stack Overflow Reset Disabled
        LVP = On            ' Low Voltage Programming Enabled
        Debug = Off         ' Background Debugger Enable Disabled
        Cp0 = Off           ' Code Protection Block 0 Disabled
        CP1 = Off           ' Code Protection Block 1 Disabled
        CPB = Off           ' Boot Block Code Protection Disabled
        CPD = Off           ' Data EEPROM Code Protection Disabled
        WRT0 = Off          ' Write Protection Block 0 Disabled
        WRT1 = Off          ' Write Protection Block 1 Disabled
        WRTB = Off          ' Boot Block Write Protection Disabled
        WRTC = Off          ' Configuration Register Write Protection Disabled
        WRTD = Off          ' Data EEPROM Write Protection Disabled
        EBTR0 = Off         ' Table Read Protection Block 0 Disabled
        EBTR1 = Off         ' Table Read Protection Block 1 Disabled
        EBTRB = Off         ' Boot Block Table Read Protection Disabled
    Config_End 
    Here's a screenshot of the simulator running the above code. I noticed you are using the LCD_RWpin Declare in your code. This is purely for graphic LCDs, and alphanumeric Hitachi LCDs need the RW line pulled to ground.

    18F4331.jpg
    Last edited by top204; 2nd August 2019 at 17:21.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,936
    Thumbs Up
    Received: 34
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: 18f4331 LCD Woes

    Thank you for all the replies.
    Bit embarrassed about this one. The problem turned out to be hardware. I am using a PIC DIP40 board from ebay, the board is great, only flaw is the ICSP connector is very close to the socketed LCD, so when I plugged in the pickit2, it pulled the lcd out of the socket slightly. Bent the ICSP pins down and all is good!

    I usually do pull the R/W to 0V Les, but this is a pre-made dev board. DO the LCD print command pull R/W low, or should I be adding that line of code manually?

    BR
    John
    Last edited by pic-ignorant; 5th August 2019 at 08:39.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,278
    Thumbs Up
    Received: 380
    Given: 137
    Total Downloaded
    1.59 GB

    0 Not allowed!

    Default Re: 18f4331 LCD Woes

    The compiler's alphanumeric LED Print routines do nothing with the R/W line, so the pin it is connected too must be pulled to ground with a Low command at the setup of the main program.

    If you take a look in the Asm file prduced (Press F2), you'll see that the pins and ports used in Declares are brought out, so if the Declare LCD_RWPin is used, you can use the Port.Pin declare names in the BASIC code:

    Low __LCD_RWPort.__LCD_RWPin

    I brought these out so I could do some tests and help when writing libraries, but they are a nice feature to use so I'll add them to the manual ASAP. The preceding double underscores in the names is to make them different to standard BASIC constant and variable names.
    Last edited by top204; 5th August 2019 at 12:18.

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. LCD toruble at 40 Mhz HSPLL 18f4331
    By Hornett in forum Absolute Beginners Section
    Replies: 2
    Last Post: 18th December 2016, 10:24
  2. Help setting up 18f4331 to run at 40 Mhz
    By Hornett in forum Absolute Beginners Section
    Replies: 5
    Last Post: 16th December 2016, 07:22
  3. 18f4331 QEI function for two encoders
    By Hornett in forum Absolute Beginners Section
    Replies: 0
    Last Post: 28th November 2016, 06:04
  4. Write problem with 18f4331 using MC loader
    By Hornett in forum Absolute Beginners Section
    Replies: 2
    Last Post: 20th October 2016, 16:03
  5. 18F4331 Bootloader
    By pic-ignorant in forum The Lounge
    Replies: 13
    Last Post: 21st September 2013, 23:53

Members who have read this thread : 107

Actions :  (Set Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts