Author Topic: NHD-7.0-800480EF-ASXN Unable to get LCD to display colors  (Read 109 times)

tom_24

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
NHD-7.0-800480EF-ASXN Unable to get LCD to display colors
« on: April 04, 2018, 03:47:15 AM »
Hi all,
I have the problem that my NHD-7.0-800480EF-ASXN display doesn´t display the colors that I want.
I can display the color white, but every other color will shown in diffrent shades of blue.
I uses the NHD-4.3-480272MF-20 Controller Board with an SSD1963 controller chip.

I hope that somebody can help me. Thanks for your help :)

Regards Tom

The source code that i use:

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f4xx_hal.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
volatile uint16_t LCD_W=800;
volatile uint16_t LCD_H=480;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

void SendData(unsigned long color)
{
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);       //RS,high

  uint16_t k = color>>8;
  uint16_t l = k<<4;
   GPIOE->ODR = l;
 
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);      //WR, Low
   __ASM("nop");
   __ASM("nop");
   __ASM("nop");
   //HAL_Delay(1);
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_SET);        //WR, High
   __ASM("nop");
   __ASM("nop");
   __ASM("nop");

   uint16_t m = color<<4;
   GPIOE->ODR = m;
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);      //WR, Low
   __ASM("nop");
   __ASM("nop");
   __ASM("nop");
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_SET);        //WR, High
   __ASM("nop");
   __ASM("nop");
   __ASM("nop");

}

 void writeCMD(unsigned char a)
{
   int16_t b;
   b = a<<4;
   GPIOE->ODR = b;
   
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_RESET);  //RS,low
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);  //WR,low
   HAL_Delay(1);
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_SET);       //WR,high
   HAL_Delay(1);
}

 void writeData(uint16_t a)
{
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);    //RS,high
   
   int16_t b;
   b = a<<4;
   GPIOE->ODR = b;
   
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);   //WR,low
   HAL_Delay(1);
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_SET);     //WR,high
   HAL_Delay(1);
   
}

void CMDwrite(int8_t REG, int8_t VALUE)
{
  writeCMD(REG);
   //HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);
   writeData(VALUE);
}

void lcd_init(void)
{
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_7, GPIO_PIN_SET);         //Display ON, High

   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_3, GPIO_PIN_RESET);      //CS, Low
   
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_SET);         //RD, High
   
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_1, GPIO_PIN_RESET);      //WR, Low
   
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);      //REST, Low
   HAL_Delay(5);
   
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_SET);         //REST, High
   HAL_Delay(100);
   
   writeCMD(0x01);                                                               //Software reset
  HAL_Delay(10);
  writeCMD(0x01);                                                               //Software reset
  HAL_Delay(10);
  writeCMD(0x01);                                                               //Software reset
   HAL_Delay(10);
   
   CMDwrite(0xe0,0x01);                                                      //Enable PLL
   CMDwrite(0xe0,0x03);                                                      //Lock PLL, Enable PLL
   
   writeCMD(0xb0);                                                               //SET LCD mode
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);    //RS,high
   writeData(0x08);
   writeData(0x80);   
   writeData(0x03);
   writeData(0x1f);   
   writeData(0x01);
   writeData(0xdf);
   writeData(0x00);
   
   CMDwrite(0xf0,0x03);                                                         //SET pixel data interface format=8bit
   CMDwrite(0x36,0x09);
   //CMDwrite(0x3A,0x60);
   
   writeCMD(0xe2);                                                                //SET multiplier and divider of PLL
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);      //RS,high
   writeData(0x22);
   writeData(0x03);
   writeData(0x04);
   
   writeCMD(0xe6);                                                                //SET the pixel clock freq
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);      //RS,high
   writeData(0x02);
   writeData(0xff);
   writeData(0xff);
   
   writeCMD(0xb4);                                                                     
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);      //RS,high
   writeData(0x20);
   writeData(0xaf);
   writeData(0x00);
   writeData(0xa3);
   writeData(0x07);
   writeData(0x00);
   writeData(0x00);
   writeData(0x00);
   
   writeCMD(0xb6);                                                                  
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);      //RS,high
   writeData(0x01);
   writeData(0xef);
   writeData(0x00);
   writeData(0x04);
   writeData(0x01);
   writeData(0x00);
   writeData(0x00);
   
   writeCMD(0x2a);
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);    //RS,high
   writeData(0x00);
   writeData(0x00);
   writeData(0x03);
   writeData(0x1f);
   
   writeCMD(0x2b);
   HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);    //RS,high
   writeData(0x00);
   writeData(0x00);
   writeData(0x01);
   writeData(0xdf);
   
   //writeCMD(0x13);                                                          //enter normal mode
   writeCMD(0x29);                                                             //SET display on
   HAL_Delay(10);

}
void WindowSet(unsigned int s_x,unsigned int e_x,unsigned int s_y,unsigned int e_y)
{
    writeCMD(0x2a);              //SET column address
    writeData((s_x)>>8);         //SET start column address
    writeData(s_x);
    writeData((e_x)>>8);         //SET end column address
    writeData(e_x);
   
    writeCMD(0x2b);      //SET page address
    writeData((s_y)>>8);         //SET start page address
    writeData(s_y);
    writeData((e_y)>>8);         //SET end page address
    writeData(e_y);
}
void LCDclear(unsigned long colour)
{
    uint16_t i,j;
    WindowSet(0,799,0,479);               //set start/end column/page address (full screen)
    writeCMD(0x2C);              //command to begin writing to frame memory#
      HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);    //RS,high
    for(i=0; i<799; i++)
        {
            for(j=0; j<479; j++)
                {
                           SendData(colour);
                }
        }
}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  *
  * @retval None
  */
int main(void)
{
  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();

   lcd_init();
    writeCMD(0x29);

  WindowSet(0,799,0,479);
  LCDclear(0x1234);
  while (1)
  {
        LCDclear(0xFFE0); //gelb
   HAL_Delay(10);
        LCDclear(0xF800);  //rot
   HAL_Delay(10);
        LCDclear(0x001F);
   HAL_Delay(10);

  }
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

    /**Configure the main internal regulator output voltage
    */
  __HAL_RCC_PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Enables the Clock Security System
    */
  HAL_RCC_EnableCSS();

    /**Configure the Systick interrupt time
    */
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick
    */
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
*/
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOE_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
                          |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
                          |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
                          |GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);

  /*Configure GPIO pins : PE4 PE5 PE6 PE7
                           PE8 PE9 PE10 PE11 */
  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
                          |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PD12 PD13 PD14 PD15
                           PD0 PD1 PD2 PD3
                           PD6 PD7 */
  GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
                          |GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
                          |GPIO_PIN_6|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI0_IRQn);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @param  file: The file name as string.
  * @param  line: The line in file as a number.
  * @retval None
  */
void _Error_Handler(char *file, int line)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  while(1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}
« Last Edit: April 04, 2018, 10:20:28 AM by tom_24 »

 

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

Started by SteveCBoard Character LCDs

Replies: 3
Views: 6119
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: 7602
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: 1
Views: 4898
Last post September 25, 2015, 03:09:24 PM
by Paul_B
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 12384
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: 7196
Last post June 18, 2014, 10:09:49 AM
by Michael_L