• AVR Freaks

Hot!LCD interfacing with PIC18f2550

Page: 12 > Showing page 1 of 2
Author
Ugochi
Starting Member
  • Total Posts : 70
  • Reward points : 0
  • Joined: 2019/02/17 03:49:57
  • Location: 0
  • Status: offline
2019/05/21 03:15:54 (permalink)
0

LCD interfacing with PIC18f2550

I want to interface pic18f2550 with an LCD, but discovered it's not the same with the 16f series. I finally got one but it's using MCC to generate some files and pic18f2550 is not supported by MCC. Pls any ideas on how I can do that without having to use MCC generated files.
post edited by Ugochi - 2019/05/23 09:07:24
#1

32 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 9200
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 03:51:53 (permalink)
    0
    What you meant "it's not the same with the 16f series"?  Write your own functions, LCD is a simple device.
    #2
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 04:16:13 (permalink)
    0
    You don't mention if you're working in assembler, or in C.
    There's little difference between PIC18F and PIC16F when you're working in C. there are  afew differences if you're working in assembler, but not too difficult to adapt.
     

    Nearly there...
    #3
    Ugochi
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2019/02/17 03:49:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 05:01:31 (permalink)
    0
    @qhb
    I'm working on C, Using MPLAB XC8 compiler.
    #4
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 05:17:29 (permalink)
    0
    So there shouldn't be much to change at all.
    Of course it will require some minor tweaking, but you'd need that even when changing to a different PIC16F part too.
    What exactly are you finding "not the same" ?
     

    Nearly there...
    #5
    Ugochi
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2019/02/17 03:49:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 06:59:25 (permalink)
    0
    In pic16f series, the RW pin is always grounded. Tried the same method with 18f2550, the simulation with proteus worked but upon implementation, nothing shows up.
    #6
    pcbbc
    Super Member
    • Total Posts : 992
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: LCD interfacing with PIC18f2550 2019/05/21 07:26:54 (permalink)
    +1 (1)
    Usually the problem with LCDs is insufficient delays when starting up, or between commands.
    Insert longer delays.  Reduce delays until you find where the problem is (or check the LCD busy flag).
    #7
    1and0
    Access is Denied
    • Total Posts : 9200
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 07:27:10 (permalink)
    0
    Ugochi
    In pic16f series, the RW pin is always grounded. Tried the same method with 18f2550, the simulation with proteus worked but upon implementation, nothing shows up.

    Having the RW pin grounded will work regardless of PIC devices.  Your problem is most likely LCD initialization or LCD timing.
    #8
    katela
    Super Member
    • Total Posts : 1249
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 08:34:02 (permalink)
    0
    Ugochi
    In pic16f series, the RW pin is always grounded. Tried the same method with 18f2550, the simulation with proteus worked but upon implementation, nothing shows up.

    Grounding the pin has got nothing to do with PIC16F or PIC18F
    RW pin = 0: Write data(from microcontroller to LCD)
    RW pin = 1: Read data: (from LCD to microcontroller)
    As in most of cases when you need to send characters to be displayed to the LCD only and you won't need to read back, to save a pin of a microcontroller this pin can permanently be grounded.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #9
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 13:08:57 (permalink)
    0
    pcbbc
    Usually the problem with LCDs is insufficient delays when starting up, or between commands.
    Insert longer delays.  Reduce delays until you find where the problem is (or check the LCD busy flag).

    Agreed.
    The crucial difference between your PIC16 and PIC18 is that you probably have the PIC18 running much faster.
    Nothing to do with the RW pin.

    Nearly there...
    #10
    dan1138
    Super Member
    • Total Posts : 3092
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 17:45:17 (permalink)
    0
    Ugochi
    In pic16f series, the RW pin is always grounded. Tried the same method with 18f2550, the simulation with proteus worked but upon implementation, nothing shows up.

    How about you posting a photo of the actual hardware as you have built it?
    #11
    Idris
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2019/05/08 13:44:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 21:23:22 (permalink)
    0
    Hello guys, I'm new here too. I worked in both embedded systems. and if you have libraries to work with 16F they can work with 18F too. you need to define some registers like PORT LAT and if you need to activate a digital input remember that is not ANSEL but ADCON1.
     

    #12
    Idris
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2019/05/08 13:44:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/21 21:38:54 (permalink)
    0
    other thing can be the way you configurate those bits man, peace!
    #13
    Ugochi
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2019/02/17 03:49:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/22 05:05:21 (permalink)
    0
    pcbbc
    Usually the problem with LCDs is insufficient delays when starting up, or between commands.Insert longer delays.  Reduce delays until you find where the problem is (or check the LCD busy flag).


    Is there another way of turning OFF the analog function of 18f2550? After going through the data sheet, I only found the one in ADCON1 register (PCFG3:0) which is for ADC conversion. I tried the ANSEL register but it's showing error. Since I only want to interface an LCD as a test, is there need for me to use the ADCON1 register to do that or is there any other way of doing it?
    I'm thinking it's because the analog functions are ON, that's why the LCD is not displaying.
    post edited by Ugochi - 2019/05/22 05:06:44
    #14
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/22 05:11:35 (permalink)
    0
    Ugochi
    Is there another way of turning OFF the analog function of 18f2550? After going through the data sheet, I only found the one in ADCON1 register (PCFG3:0) which is for ADC conversion. I tried the ANSEL register but it's showing error.

    You seem to be making assumptions rather than reading the datasheet.
    The PIC18F2550 does not have ANSEL registers, so of course the compiler complains if you try to access them.
    ANSEL registers appeared in later PIC parts, the 18F2550 is a very old part that still does it the old way.
     

    Since I only want to interface an LCD as a test, is there need for me to use the ADCON1 register to do that or is there any other way of doing it?

    There's only one way to do it, which is how the datasheet tells you.
     

    I'm thinking it's because the analog functions are ON, that's why the LCD is not displaying.

    I'm thinking you're wrong. If you are addressing the LAT register correctly (not using PORT registers) for all your output signals, then the analog setting doesn't matter anyway.
    Are you going to keep bearing around the bush, or let us actually see what code you have come up with?
     
     

    Nearly there...
    #15
    Ugochi
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2019/02/17 03:49:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/22 10:47:52 (permalink)
    0
    Configuration files and LCD definitions

    // CONFIG1L
    #pragma config PLLDIV = 1
    #pragma config CPUDIV = OSC1_PLL2
    #pragma config USBDIV = 1

    // CONFIG1H
    #pragma config FOSC = HS
    #pragma config FCMEN = OFF
    #pragma config IESO = OFF

    // CONFIG2L
    #pragma config PWRT = OFF
    #pragma config BOR = ON
    #pragma config BORV = 3
    #pragma config VREGEN = OFF

    // CONFIG2H
    #pragma config WDT = OFF
    #pragma config WDTPS = 32768

    // CONFIG3H
    #pragma config CCP2MX = ON
    #pragma config PBADEN = ON
    #pragma config LPT1OSC = OFF
    #pragma config MCLRE = ON

    // CONFIG4L
    #pragma config STVREN = ON
    #pragma config LVP = OFF
    #pragma config XINST = OFF

    // CONFIG5L
    #pragma config CP0 = OFF
    #pragma config CP1 = OFF
    #pragma config CP2 = OFF
    #pragma config CP3 = OFF

    // CONFIG5H
    #pragma config CPB = OFF
    #pragma config CPD = OFF

    // CONFIG6L
    #pragma config WRT0 = OFF
    #pragma config WRT1 = OFF
    #pragma config WRT2 = OFF
    #pragma config WRT3 = OFF

    // CONFIG6H
    #pragma config WRTC = OFF
    #pragma config WRTB = OFF
    #pragma config WRTD = OFF

    // CONFIG7L
    #pragma config EBTR0 = OFF
    #pragma config EBTR1 = OFF
    #pragma config EBTR2 = OFF
    #pragma config EBTR3 = OFF

    // CONFIG7H
    #pragma config EBTRB = OFF

    #include <xc.h>
    #define _XTAL_FREQ 8000000
    post edited by Ugochi - 2019/05/22 10:52:56
    #16
    pcbbc
    Super Member
    • Total Posts : 992
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: LCD interfacing with PIC18f2550 2019/05/22 10:58:32 (permalink)
    0
    qhb
    Are you going to keep bearing around the bush, or let us actually see what code you have come up with?  

    That I’ll be a NO then.
    #17
    Ugochi
    Starting Member
    • Total Posts : 70
    • Reward points : 0
    • Joined: 2019/02/17 03:49:57
    • Location: 0
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/22 11:07:06 (permalink)
    0
    LCD definitions

    #define RS PORTBbits.RB2
    #define EN PORTBbits.RB3
    #define D4 PORTBbits.RB4
    #define D5 PORTBbits.RB5
    #define D6 PORTBbits.RB6
    #define D7 PORTBbits.RB7
    void Lcd_Port(char a)
    {
    if(a & 1)
    D4 = 1;
    else
    D4 = 0;
    if(a & 2)
    D5 = 1;
    else
    D5 = 0;
    if(a & 4)
    D6 = 1;
    else
    D6 = 0;
    if(a & 8)
    D7 = 1;
    else
    D7 = 0;
    }
    void Lcd_Cmd(char a)
    {
    RS = 0; // => RS = 0
    Lcd_Port(a);
    EN = 1; // => E = 1
    __delay_ms(8);//4ms
    EN = 0; // => E = 0
    }
    void Lcd_Clear()
    {
    Lcd_Cmd(0);
    Lcd_Cmd(1);
    }
    void Lcd_Set_Cursor(char a, char b)
    {
    char temp,z,y;
    if(a == 1)
    {
    temp = 0x80 + b - 1;
    z = temp>>4;
    y = temp & 0x0F;
    Lcd_Cmd(z);
    Lcd_Cmd(y);
    }
    else if(a == 2)
    {
    temp = 0xC0 + b - 1;
    z = temp>>4;
    y = temp & 0x0F;
    Lcd_Cmd(z);
    Lcd_Cmd(y);
    }
    }
    void Lcd_Init()
    {
    Lcd_Port(0x00);
    __delay_ms(20);//20ms
    Lcd_Cmd(0x03);
    __delay_ms(5);//5ms
    Lcd_Cmd(0x03);
    __delay_ms(11);//11ms
    Lcd_Cmd(0x03);
    Lcd_Cmd(0x02);
    Lcd_Cmd(0x02);
    Lcd_Cmd(0x08);
    Lcd_Cmd(0x00);
    Lcd_Cmd(0x0C);
    Lcd_Cmd(0x00);
    Lcd_Cmd(0x06);
    }
    post edited by Ugochi - 2019/05/22 11:16:05
    #18
    pcbbc
    Super Member
    • Total Posts : 992
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: LCD interfacing with PIC18f2550 2019/05/22 11:44:24 (permalink)
    +2 (2)
    You’re not using LAT registers, if your device has them. If it doesn’t, mitigate against RMW effects using a shadow register.
    Make your delays longer.
    Put a longer delay at the start of your main routine before you initialise the LCD to ensure the LCD is ready before you try to initialise it.
    #19
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: LCD interfacing with PIC18f2550 2019/05/22 13:12:32 (permalink)
    +1 (1)
    Finally we get to see some code.
    Change all your bit definitions to:
    #define RS LATBbits.LATB2
    #define EN LATBbits.LATB3
    #define D4 LATBbits.LATB4
    #define D5 LATBbits.LATB5
    #define D6 LATBbits.LATB6
    #define D7 LATBbits.LATB7

    and if it still doesn't work, try doubling all your delays in the Lcd_Init() function.
     

    Nearly there...
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5