0
\$\begingroup\$

I'm trying to get this 320 x 480 LCD going through SPI (4 wire 8bit) for a while now but no luck. It seems like the resolution is not defined as should during init but I can't see how.

Here what I see after running code that should paint the entire LCD blue: enter image description here

Here is the test function:

LCDWriteCommand(0x2A);
LCDWriteData(0x00);
LCDWriteData(0x00);
LCDWriteData(0x01);
LCDWriteData(0x3F);
LCDWriteCommand(0x2B);
LCDWriteData(0x00);
LCDWriteData(0x00);
LCDWriteData(0x01);
LCDWriteData(0xDF);
LCDWriteCommand(0x2C);

for(uint16_t i = 0; i < 320; i++) // Y
{
    for(uint16_t j = 0; j < 480; j++)
    {
        LCDWriteData(BLUE>>8);
        LCDWriteData((uint8_t)BLUE);
    }
}

The addresses for the memory are from 0 to 319 & 0 to 479 so it should be fine for this LCD as far as I can see.

Here is the init code itself:

    LCDWriteCommand(0xF0); // PASSWD1 - OK
    LCDWriteData(0x5A);
    LCDWriteData(0x5A);

    LCDWriteCommand(0xF1); // PASSWD2 - OK
    LCDWriteData(0x5A);
    LCDWriteData(0x5A);

    LCDWriteCommand(0xF2); // DISCTL (Display Control)
    LCDWriteData(0x3B);    // 480 scan lines
    LCDWriteData(0x33);
    LCDWriteData(0x03);
    LCDWriteData(0x0C);
    LCDWriteData(0x08);
    LCDWriteData(0x08);
    LCDWriteData(0x08);
    LCDWriteData(0x00);
    LCDWriteData(0x08);
    LCDWriteData(0x08);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x33);
    LCDWriteData(0x0C);
    LCDWriteData(0x08);
    LCDWriteData(0x0C);
    LCDWriteData(0x08);

    LCDWriteCommand(0xF4);
    LCDWriteData(0x07);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x04);
    LCDWriteData(0x70);
    LCDWriteData(0x03);
    LCDWriteData(0x04);
    LCDWriteData(0x70);
    LCDWriteData(0x03);

    LCDWriteCommand(0xF5);
    LCDWriteData(0x00);
    LCDWriteData(0x46);//Set VCOMH
    LCDWriteData(0x70);//Set VCOM Amplitude
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x02);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x46);
    LCDWriteData(0x70);

    LCDWriteCommand(0xF6);
    LCDWriteData(0x03);
    LCDWriteData(0x00);
    LCDWriteData(0x08);
    LCDWriteData(0x03);
    LCDWriteData(0x03);
    LCDWriteData(0x00);
    LCDWriteData(0x03);
    LCDWriteData(0x00);

    LCDWriteCommand(0xF7);
    LCDWriteData(0x48);
    LCDWriteData(0x80);//RGB_MCU(DM)
    LCDWriteData(0x10);
    LCDWriteData(0x02);
    LCDWriteData(0x00);

    LCDWriteCommand(0xF8);
    LCDWriteData(0x11);
    LCDWriteData(0x00);

    LCDWriteCommand(0xF9); //Gamma Selection
    LCDWriteData(0x14);

    LCDWriteCommand(0xFA); //Positive Gamma Control
    LCDWriteData(0x33);
    LCDWriteData(0x07);
    LCDWriteData(0x04);
    LCDWriteData(0x1A);
    LCDWriteData(0x18);
    LCDWriteData(0x1C);
    LCDWriteData(0x24);
    LCDWriteData(0x1D);
    LCDWriteData(0x26);
    LCDWriteData(0x28);
    LCDWriteData(0x2F);
    LCDWriteData(0x2E);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);

    LCDWriteCommand(0xFB); //Positive Gamma Control
    LCDWriteData(0x33);
    LCDWriteData(0x03);
    LCDWriteData(0x00);
    LCDWriteData(0x2E);
    LCDWriteData(0x2F);
    LCDWriteData(0x28);
    LCDWriteData(0x26);
    LCDWriteData(0x1D);
    LCDWriteData(0x24);
    LCDWriteData(0x1C);
    LCDWriteData(0x18);
    LCDWriteData(0x1A);
    LCDWriteData(0x04);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);

    LCDWriteCommand(0xF9); //Gamma Selection
    LCDWriteData(0x12);

    LCDWriteCommand(0xFA); //Positive Gamma Control
    LCDWriteData(0x36);
    LCDWriteData(0x07);
    LCDWriteData(0x04);
    LCDWriteData(0x1C);
    LCDWriteData(0x1C);
    LCDWriteData(0x23);
    LCDWriteData(0x28);
    LCDWriteData(0x1C);
    LCDWriteData(0x25);
    LCDWriteData(0x26);
    LCDWriteData(0x2E);
    LCDWriteData(0x2B);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);

    LCDWriteCommand(0xFB); //Positive Gamma Control
    LCDWriteData(0x33);
    LCDWriteData(0x06);
    LCDWriteData(0x00);
    LCDWriteData(0x2B);
    LCDWriteData(0x2E);
    LCDWriteData(0x26);
    LCDWriteData(0x25);
    LCDWriteData(0x1C);
    LCDWriteData(0x28);
    LCDWriteData(0x23);
    LCDWriteData(0x1C);
    LCDWriteData(0x1C);
    LCDWriteData(0x04);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);

    LCDWriteCommand(0xF9); //Gamma Selection
    LCDWriteData(0x11);

    LCDWriteCommand(0xFA); //Positive Gamma Control
    LCDWriteData(0x33);
    LCDWriteData(0x07);
    LCDWriteData(0x04);
    LCDWriteData(0x30);
    LCDWriteData(0x32);
    LCDWriteData(0x34);
    LCDWriteData(0x35);
    LCDWriteData(0x11);
    LCDWriteData(0x1D);
    LCDWriteData(0x20);
    LCDWriteData(0x28);
    LCDWriteData(0x20);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);

    LCDWriteCommand(0xFB); //Positive Gamma Control
    LCDWriteData(0x33);
    LCDWriteData(0x03);
    LCDWriteData(0x00);
    LCDWriteData(0x20);
    LCDWriteData(0x28);
    LCDWriteData(0x20);
    LCDWriteData(0x1D);
    LCDWriteData(0x11);
    LCDWriteData(0x35);
    LCDWriteData(0x34);
    LCDWriteData(0x32);
    LCDWriteData(0x30);
    LCDWriteData(0x04);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x00);

    LCDWriteCommand(0x44);
    LCDWriteData(0x00);
    LCDWriteData(0x01);

    LCDWriteCommand(0x2A);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x01);
    LCDWriteData(0x3F);

    LCDWriteCommand(0x2B);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x01);
    LCDWriteData(0xDF);

    LCDWriteCommand(0x36); //Memory Data Access Control
    LCDWriteData(0x00);

    LCDWriteCommand(0x3A); //SET 65K Color
    LCDWriteData(0x55);

    LCDWriteCommand(0x11);
    _delay_ms(120);

    LCDWriteCommand(0x29);//Display on
    LCDWriteCommand(0x2C);//Write GRAM

    _delay_ms(10);
    LCDWriteCommand(0x36); //Set_address_mode
    LCDWriteData(0x60); //???????????????????

I know this is very long, however perhaps someone has some experience and will be able to help out quickly. Thanks!

\$\endgroup\$
  • 1
    \$\begingroup\$ Seeing the blue being rather squarish - have you tried initializing the LCD dimensions in the other order, say instead of setting it to X×Y resolution, try Y×X. In other words, it just seems to me as if the coordinates were swapped. \$\endgroup\$ – Richard the Spacecat May 16 '18 at 23:27
  • 1
    \$\begingroup\$ @RichardtheSpacecat Seems like that did the trick. I simply changed the memory end addresses for commands 0x2A & 0x2B. So the whole screen shows but the colors are messed up. Not sure if codes are wrong or some gamma correction issue? \$\endgroup\$ – user34920 May 17 '18 at 16:21
  • \$\begingroup\$ Messed up in what way? If the datasheet isn't too helpful, try setting the whole screen to all red, all green, and all blue. See whether you get what you expect. If not, it should at least point you in the right direction \$\endgroup\$ – Richard the Spacecat May 17 '18 at 16:33
  • 1
    \$\begingroup\$ Which color format are you using? RGB-565 is afaik fdairlycommon on LCDs with 16bit colour, but other schemes do exist. \$\endgroup\$ – Richard the Spacecat May 17 '18 at 16:38
  • \$\begingroup\$ The color format was correct, however the loops scanning the screen were not. Now it's all good. Thanks! \$\endgroup\$ – user34920 May 18 '18 at 17:09
0
\$\begingroup\$

The end addresses for the LCD memory should be swapped (2nd parameter of 0x2A & 0x2B commands). A working test function that draws colored lines on the screen looks like so:

void LCDTestColor()
{
    LCDWriteCommand(0x2A);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x01);
    LCDWriteData(0xDF);
    LCDWriteCommand(0x2B);
    LCDWriteData(0x00);
    LCDWriteData(0x00);
    LCDWriteData(0x01);
    LCDWriteData(0x3F);
    LCDWriteCommand(0x2C);

    for(uint16_t i = 0; i < 480; i++) // Y
    {
        for(uint16_t j = 0; j < 320; j++)
        {
            if (i < 120)
            {
                LCDWriteData(RED>>8);
                LCDWriteData((uint8_t)RED);
            }
            else if (i < 240)
            {
                LCDWriteData(BLUE>>8);
                LCDWriteData((uint8_t)BLUE);
            }
            else if (i < 360)
            {
                LCDWriteData(GREEN>>8);
                LCDWriteData((uint8_t)GREEN);
            }
            else
            {
                LCDWriteData(YELLOW>>8);
                LCDWriteData((uint8_t)YELLOW);
            }
        }
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.