chipKIT® Development Platform

Inspired by Arduino™

LCD 5110 w/ chipkit uno 32. Can't print on LCD

Created Mon, 23 Dec 2013 11:28:59 +0000 by guilherm3c


guilherm3c

Mon, 23 Dec 2013 11:28:59 +0000

Hello, I'm currently trying to get a chipkit uno 32 to work with an LCD 5110 and need an extra help with it. It uses SPI protocol. It works on a frequency up to 4MHz and, to my understanding, chip enable and reset have an active low. The signals seem to be all working as intended but i can't print a thing...

This is my code so far and Help would be MUCH appreciated! (note that some of it was taken from random websites on the internet)

#include <plib.h>
#include <p32xxxx.h>

void init_SPI();
void LED_init();
void Reset();
void LCD_send(unsigned int data, unsigned int dc);
void LCD_init();
void LCD_clr(unsigned int b_w);

main()
{
    OpenTimer2(T2_ON | T2_PS_1_8, 10000-1); // 1ms
    TRISD = 0xFFF1;
    LATD = 0x000A;

    LED_init();
    LCD_init();
    LCD_clr(1);
    /*LCD_send(0x40 + 0x02, 0); //Y address
    LCD_send(0x80 + 0x10, 0); //X address
    LCD_send(0x1f, 1);*/
}

void init_SPI()
{
    OpenSPI2(FRAME_ENABLE_OFF | SPI_MODE8_ON | MASTER_ENABLE_ON , SPI_ENABLE);
    SpiChnSetBrg(2, 9); //4MHz

}

void LED_init()
{
    OC1CON = 0x0006;    // PWM mode on OCx; Fault pin disabled
    OC1RS = 10000;       // duty cycle = 100%
    OC1CONSET = 0x8000; // activa OC1
}

void Reset()
{
    int n, m;

    for (n=0; n<20; n++) // ~ 20ms delay
            for (m=0; m<3800; m++)
            {}//do nothing
    LATDCLR = 0x0008;// RST = 0;
    for (n=0; n<20; n++) // ~ 20ms delay
            for (m=0; m<3800; m++)
            {}//do nothing
    LATDSET = 0x0008;// RST = 1;
}

void LCD_send(unsigned int data, unsigned int dc)
{
   // Set the appropriate status for command=0 or data=1
    if (dc==1)
        LATDSET = 0x0004;
    else if (dc==0)
        LATDCLR = 0x0004;
    putcSPI2(data);
}

void LCD_init()
{
    int n, m;

    for (n=0; n<1000; n++) // ~ 20ms delay
            for (m=0; m<3800; m++)
    LATDCLR = 0x0002; //inicializa LCD
    Reset();

    init_SPI();

    LCD_send(0x20 + 0x01, 0); // Extended instructions enabled
    LCD_send(0x80 + 0x10, 0); // Set contrast 0 - 127
    //LCD_send(0x04 + 0x02, 0); // Temperature control
    //LCD_send(0x10 + 0x03, 0); // Set bias system
    LCD_send(0x20 + 0x00, 0); // Return to basic instruction set, power on, set horizontal addressing
    LCD_send(0x00 + 0x0c, 0); // Display control set to normal mode
}

void LCD_clr(unsigned int b_w)
{
    unsigned int i;
    unsigned int bg;

    if (b_w == 0) // set the background color
    {
        bg = 0x00;
    }
    else if (b_w == 1)
    {
        bg = 0xFF;
    }

    LCD_send(0x40, 0); // set Y address
    LCD_send(0x80, 0); // set X address
    for (i = 0; i < 504; i++)
    {
        LCD_send(bg, 1); // Clear everything
    }
}

dangeljs

Mon, 23 Dec 2013 14:22:42 +0000

I don't see anywhere in your code where you set the chip select pin, for starters.

Is there a reason you are programming in C instead of using MPIDE with the Setup() and Loop() functions? If you are just making sure that the LCD is working, I would suggest using MPIDE and then use Henning Karlsens Library here:

[url]http://henningkarlsen.com/electronics/library.php?id=45[/url]

He has done a lot of great work and has it documented very well. Once you confirm it is working with your Uno, then you can modify your code as needed to adapt to programming in C. Just a suggestion.

Jason


guilherm3c

Mon, 23 Dec 2013 14:36:40 +0000

Thank you for your answer. I will try to do what you told me (though i'm not allowed to use external libraries)

I think I set the chip select here

LATDCLR = 0x0002; //inicializa LCD

, in LCD_init function

another thing, the LCD's PCB is kinda bent, could it mean it's malfunctioning?

note: i'm using MPXLAB IDE already


majenko

Mon, 23 Dec 2013 16:09:18 +0000

Thank you for your answer. I will try to do what you told me (though i'm not allowed to use external libraries) I think I set the chip select here

LATDCLR = 0x0002; //inicializa LCD

, in LCD_init function another thing, the LCD's PCB is kinda bent, could it mean it's malfunctioning? note: i'm using MPXLAB IDE already

Do yourself a favour and set yourself up some symbolic names:

#define CS_PIN 1
#define CS_LATSET LATDSET
#define CS_LATCLR LATDCLR

CS_LATSET = 1<<CS_PIN
... etc ...

And yes, a bent PCB could mean it's faulty. I'd reiterate trying to get it going using MPIDE (not MPLAB-X) and the aforementioned library - just to confirm it's actually working. Then you can work on manual implementation when you know it's actually functioning and wired up right.


guilherm3c

Mon, 23 Dec 2013 16:16:59 +0000

thanks guys, though the programs functioned in similar ways, but aparently not.

Thanks for the PIN tip

edit: sorry to bother you guys again, but how do i add the library? it always says it can't be found


jmlynesjr

Wed, 25 Dec 2013 01:35:57 +0000

The Karlsen library worked fine with my 5110, including multiple sized fonts, bit maps, and graphs. I need to get the code moved to my github area.

However, it didn't work at first, and after a lot of searching, I found mention of an issue with warped PCBs causing bad connections between the display module and the carrier PCB. A little mashing around on the bezel got it to make contact.

Unfortunately I can't find my email exchange with my supplier(Aztec).

James

PS: Look at the topic: Nokia 5110/3310 libraries. Also a post on the warped PCB issue in the Sparkfun Forum,