Author Topic: Unable to get LCD to display color  (Read 959 times)

MidknighTrain

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
    • View Profile
Unable to get LCD to display color
« on: September 16, 2016, 08:50:42 PM »
Hi all,

I'm having some trouble interfacing with this LCD that I'm working with. The model for the LCD is NHD-5.0-800480TF-ATXL#-CTP, and it uses the controller board NHD‐5.0‐800480TF‐34 with built-in SSD1963 controller chip. The LCD has a total of 40 pins that connects to the controller board through a ribbon cable, and the controller board give users access to 34 pins to connect to the MCU, also using a ribbon cable (plus some adapters to connect to the breadboard that I have the launchpad plugged into). Here are some extra datasheets for reference. They are in the order of LCD, controller board, and then controller chip SSD1963.

http://www.newhavendisplay.com/specs/NHD-5.0-800480TF-ATXL-CTP.pdf
http://www.newhavendisplay.com/specs/NHD-5.0-800480TF-34%20Controller%20Board.pdf
http://www.newhavendisplay.com/appnotes/datasheets/LCDs/SSD1963.pdf


I found the code for the Arduino Mega on the company's website, and thus I transfer that over into C for the Tiva C laucnhpad. Here is the link to the Arduino code, followed by the app notes for the SSD1963, with the difference that this one came from the actual company that made the chip itself (the code examples from the app notes seems to match the ones on the display company's website):

http://www.newhavendisplay.com/app_notes/Arduino_nhd-5_0-800480TF.txt
http://www.solomon-systech.com/files/ck/files/SSD1961_2_3_Application_note_v1.7.pdf


And now here is my code:

//*****************************************************************************
//
// Main routine.
//
//*****************************************************************************
int main(void)
{
   //
    // Run from the PLL at 120 MHz.
    //
   uint32_t g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
         SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

    //
    // Initialize peripherals.
    //
   initLCD(g_ui32SysClock);

   //
   // Setup LCD for display.
   //
   lcdSetup(g_ui32SysClock);

    //
    // Main loop.
    //
    while (1)
    {
       lcdDemo(g_ui32SysClock);

       MAP_SysCtlDelay(g_ui32SysClock / 3); // 1 s delay
    }
}

//*****************************************************************************
//
// Initialize LCD.
//
//*****************************************************************************
void initLCD(uint32_t g_ui32SysClock)
{
   //
   // Enable the peripherals to be used.
   //
   MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
   MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);
   MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
   MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);

   //
   // Waits for peripherals to be ready.
   //
   while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOH) &&
         !MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOM) &&
         !MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOQ) &&
         !MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOL));

   //
   // Configure pin PQ3 as output.
   //
   MAP_GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_3);

   //
   // Configure pin PH0-PH3 as output.
   //
   MAP_GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
         GPIO_PIN_2 | GPIO_PIN_3);

   //
   // Configure pin PM0-PM7 as output.
   //
   MAP_GPIOPinTypeGPIOOutput(GPIO_PORTM_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
         GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
         GPIO_PIN_7);

   //
   // Configure pin PL0 as output.
   //
   MAP_GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_0);
}

//*****************************************************************************
//
// Setup/initialize LCD.
//
//*****************************************************************************
void lcdSetup(uint32_t g_ui32SysClock)
{
   //
   // Drive DISP & RD HIGH.
   // Drive WR & REST LOW.
   //
   MAP_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
         GPIO_PIN_3, 0x0A);
   MAP_SysCtlDelay(g_ui32SysClock / 3 / (25/3)); // 120 ms delay

   //
   // Drive REST HIGH.
   //
   MAP_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_2, 0x04);
   MAP_SysCtlDelay(g_ui32SysClock / 3 / (25/3)); // 120 ms delay

   //
   // Perform software reset.
   //
   lcdWriteCommand(0x01);
   MAP_SysCtlDelay(g_ui32SysClock / 3 / (25/3)); // 120 ms delay

   //
   // Set multiplier and divider for PLL.
   //
   lcdWriteCommand(0xE2);
   lcdWriteData(0x1D);
   lcdWriteData(0x02);
   lcdWriteData(0x04);

   //
   // Enable and lock PLL.
   //
   lcdWriteDataToReg(0xE0, 0x01);
   MAP_SysCtlDelay(g_ui32SysClock / 3 / 1000); // 1 ms delay
   lcdWriteDataToReg(0xE0, 0x03);

   //
   // Perform software reset.
   //
   lcdWriteCommand(0x01);
   MAP_SysCtlDelay(g_ui32SysClock / 3 / (25/3)); // 120 ms delay

   //
   // Set LCD mode.
   //
   lcdWriteCommand(0xB0);
   lcdWriteData(0x08);      // 18-bit, FRC enable, dithering disable
   lcdWriteData(0x80);      // TFT mode
   lcdWriteData(0x03);      // Horizontal size = 800 - 1; high byte
   lcdWriteData(0x1F);      // Horizontal size = 800 - 1; low byte
   lcdWriteData(0x01);      // Horizontal size = 480 - 1; high byte
   lcdWriteData(0xDF);      // Horizontal size = 480 - 1; low byte
   lcdWriteData(0x00);      // Even/odd line RGB sequence = RGB

   //
   // Set pixel data format to 8-bit.
   //
   lcdWriteDataToReg(0xF0, 0x00);

   //
   // Set address mode. Image is flipped vertically on display. RGB order from
   // is buffer to display is flipped to BGR.
   //
   lcdWriteDataToReg(0x36, 0x09);

   //
   // Set pixel clock frequency.
   //
   lcdWriteCommand(0xE6);
   lcdWriteData(0x0F);
   lcdWriteData(0xFF);
   lcdWriteData(0xFF);

   //
   // Set horizontal period.
   //
   lcdWriteCommand(0xB4);
   lcdWriteData(0x04);      // HSYCN total = 1056; high byte
   lcdWriteData(0x20);      // HSYCN total = 1056; low byte
   lcdWriteData(0x00);      // HSYNC start position = 88; high byte
   lcdWriteData(0x58);      // HSYNC start position = 88; low byte
   lcdWriteData(0x80);      // HSYNC pulse width = 128 = 127pixels + 1
   lcdWriteData(0x00);      // HSYNC pulse start position; high byte
   lcdWriteData(0x00);      // HSYNC pulse start position; low byte
   lcdWriteData(0x00);      // HSYNC pulse subpixel start position

   //
   // Set vertical period.
   //
   lcdWriteCommand(0xB6);
   lcdWriteData(0x02);      // VSYCN total = 525; high byte
   lcdWriteData(0x0D);      // VSYCN total = 525; low byte
   lcdWriteData(0x00);      // VSYNC start position = 32; high byte
   lcdWriteData(0x20);      // VSYNC start position = 32; low byte
   lcdWriteData(0x01);      // VSYNC pulse width = 1 = 0lines + 1
   lcdWriteData(0x00);      // VSYNC pulse start position; high byte
   lcdWriteData(0x00);      // VSYNC pulse start position; low byte

   //
   // Go into normal mode. Whole display area is used.
   //
   lcdWriteCommand(0x13);

   //
   // Exit idle mode. Full color depth is used for display.
   //
   lcdWriteCommand(0x38);

   //
   // Show image.
   //
   lcdWriteCommand(0x29);
   MAP_SysCtlDelay(g_ui32SysClock / 3 / 100); // 10 ms delay
}

//*****************************************************************************
//
// Test function.
//
//*****************************************************************************
void lcdDemo(uint32_t g_ui32SysClock)
{
   uint16_t i = 0;
   uint16_t j = 0;

   //
   // Set start and end position for column/page address. (full screen)
   //
   lcdWindowSet(0, 799, 0, 479);

   //
   // Start transaction from MCU to display.
   //
   lcdWriteCommand(0x2C);

   //
   // Fill screen with blue pixels.
   //
   for (; i < 480; ++i)
   {
      for (; j < 800; ++j)
      {
         lcdWriteData(0xFF);
         lcdWriteData(0x00);
         lcdWriteData(0x00);
      }
   }
   //
   // Set start and end position for column/page address. (full screen)
   //
   lcdWindowSet(0, 799, 0, 479);

   //
   // Start transaction from MCU to display.
   //
   lcdWriteCommand(0x2C);

   //
   // Fill screen with green pixels.
   //
   for (; i < 480; ++i)
   {
      for (; j < 800; ++j)
      {
         lcdWriteData(0x00);
         lcdWriteData(0xFF);
         lcdWriteData(0x00);
      }
   }

   //
   // Set start and end position for column/page address. (full screen)
   //
   lcdWindowSet(0, 799, 0, 479);

   //
   // Start transaction from MCU to display.
   //
   lcdWriteCommand(0x2C);

   //
   // Fill screen with red pixels.
   //
   for (; i < 480; ++i)
   {
      for (; j < 800; ++j)
      {
         lcdWriteData(0x00);
         lcdWriteData(0x00);
         lcdWriteData(0xFF);
      }
   }
}

//*****************************************************************************
//
// Send a command to LCD.
//
//*****************************************************************************
void lcdWriteCommand(unsigned char command)
{
   uint8_t all_pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
         GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;

   //
   // Drive RS LOW to send command.
   //
   MAP_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_3, 0x00);

   //
   // Send 8-bit all together.
   //
   MAP_GPIOPinWrite(GPIO_PORTM_BASE, all_pin, command);

   //
   // Toggle WR. (Active LOW)
   //
   MAP_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0, 0x00);
   MAP_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0, 0x01);
}

//*****************************************************************************
//
// Send data to LCD.
//
//*****************************************************************************
void lcdWriteData(unsigned char data)
{
   uint8_t all_pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
         GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;

   //
   // Drive RS HIGH to send data.
   //
   MAP_GPIOPinWrite(GPIO_PORTQ_BASE, GPIO_PIN_3, 0x08);

   //
   // Send 8-bit all together.
   //
   MAP_GPIOPinWrite(GPIO_PORTM_BASE, all_pin, data);

   //
   // Toggle WR. (Active LOW)
   //
   MAP_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0, 0x00);
   MAP_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0, 0x01);
}

//*****************************************************************************
//
// Write/overwrite value in specified register.
//
//*****************************************************************************
void lcdWriteDataToReg(unsigned char reg, unsigned char val)
{
   lcdWriteCommand(reg);
   lcdWriteData(val);
}


Here are some tests that I've did so far:

- Connected a logic analyzer to an oscilloscope, hooked the probes to the data pins PM0-PM7, hooked the channel 1 probe to the WR signal, and stepped through each line in the code to make sure that all values that are sent are being sent as specified.

- Wrote color data to frame buffer, then reading it back out. All data are the same coming out as how they came in, proving that the MCU is communicating correctly with the SSD1963.


Possible causes:

- The LCD or the circuitry on ribbon cable flap connecting to the controller board is faulty/short-circuited.

- I missed something when I transferred the code from Arduino to C.

- I'm not setting the Horizontal Period, Vertical Period, and/or the PLL multiplier and divider correctly (though I've looked through the datasheet for the values on this and I'm quite certain that they are set to the correct values, though I could be wrong, as I'm not 100% sure).


I've been stuck on this for the past couple of weeks, and I'm in desperate needs to get this done in time for my school project. Does anyone have any sort of idea (or have even worked with a NewHaven Display before) on what I might have done wrong, or what other tests I could do?

Thanks a bunch.

 

Blank Display on NHD‐C0220BiZ‐FS(RGB)‐FBW‐3VM

Started by SteveCBoard Character LCDs

Replies: 3
Views: 4565
Last post May 13, 2014, 12:04:36 AM
by SteveC
NHD‐C12864A1Z‐FSW‐FBW‐HTT display clears after draw

Started by EdAverillBoard Graphic LCDs

Replies: 6
Views: 5700
Last post November 07, 2014, 08:25:20 AM
by Michael_L
NHD‐4.3‐480272EF‐ATXL#‐CTP | FAN5333 | BBB | Nothing on the Display

Started by Alias_AliasBoard TFTs

Replies: 2
Views: 3406
Last post November 20, 2017, 08:40:38 PM
by tolikkk
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 8817
Last post July 10, 2014, 08:46:06 AM
by Michael_L
NHD-0420DZW-AG5 - Display "sometimes" shows only 2 lines

Started by stylonurusBoard OLEDs

Replies: 5
Views: 5574
Last post June 18, 2014, 10:09:49 AM
by Michael_L