Code for NHD-2.8-240320AF-CSXP-FCTP with STM32CubeIDE
I'm using NHD-2.8-240320AF-CSXP-FCTP. I want to make a GUI on that. Is there any example code available?
-
please follow this link for example code on the NHD-2.8-240320AF-CSXP-FCTP
this is for the display driver (https://support.newhavendisplay.com/hc/en-us/articles/4413936008727--2-4-TFT-ST7789-Controller)
this is for the touch panel controller (https://github.com/NewhavenDisplay/FT5X26-Focaltech-Drivers)please feel free to reach out with further questions.
Thank you!
0 -
Thank you,
I'm using NHD-2.8-240320AF-CSXP-FCTP display. But https://support.newhavendisplay.com/hc/en-us/articles/4413936008727--2-4-TFT-ST7789-Controller this support my Display?
Touch screen controller - XPT2046
Is there any example for this one?
0 -
Hello,
-
Compatibility of the ST7789 Controller Code:
- The code provided for the ST7789 controller will work with any display that uses the ST7789 controller, including the NHD-2.8-240320AF-CSXP-FCTP. As mentioned, minor changes may be needed to match the specific GPIO pin connections of your hardware setup. The ST7789 controller is standardized, so as long as the initialization sequence, data commands, and power sequencing are correctly implemented, the code should be compatible across displays using the same controller.
-
Touch Screen Controller - XPT2046:
- The XPT2046 is indeed a third-party touch screen controller that is not supplied by Newhaven Displays. The XPT2046 is a commonly used resistive touch controller, and it can be interfaced with various microcontrollers using SPI.
- The repository you referenced (https://github.com/taburyak/STM32-touchscreen-XPT2046-HAL-SPI) provides example code for interfacing the XPT2046 with STM32 microcontrollers using HAL (Hardware Abstraction Layer) and SPI, which should be useful if you're working with STM32-based systems.
Please let us know if you have any other questions.
0 -
-
Hi,
I write a code for LCD display. Now I want to display the RED color background on LCD panel. Can you help me how to write a code.
/*
* tft.c
*
* Created on: Sep 9, 2024
* Author: admin
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "tft.h"
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
uint32_t temp;
//extern Window *WindowPages;
//extern privlock prvlock;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void TFT_delay(unsigned int x) {
unsignedinti,j;
for(i=0;i<x;i++){
for(j=0;j<10;j++){
asm("NOP");
}
}
}
/**
* @brief Reset the touch controller as per the datasheet
*
* @retval None
*/
void LCD_TouchReset(void)
{
/* set the TOUCH_RESET pin */
HAL_GPIO_WritePin(TOUCH_RESET_GPIO_Port, TOUCH_RESET_Pin,GPIO_PIN_RESET);
HAL_Delay(10);
HAL_GPIO_WritePin(TOUCH_RESET_GPIO_Port, TOUCH_RESET_Pin,GPIO_PIN_SET);
HAL_Delay(10);
}
/**
* Fun name: TFT_28_7789_writeCommand
* @brief : initialization of LCD command
* @param : none
* @retval : none
*/
void TFT_28_7789_writeCommand(unsigned long command)
{
/* USER CODE END PD */
/* chip select */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_7,GPIO_PIN_RESET);// MC_LCD_CS
/* reset pin */
HAL_GPIO_WritePin( GPIOG, GPIO_PIN_1,GPIO_PIN_RESET);//MC_LCD_D_C
/* set read pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_4,GPIO_PIN_SET);//MC_LCD_RD
/* reset write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_RESET);//MC_LCD_WR
/* First Four bits */
temp = GPIOD->ODR;
temp = 0x3FFC & temp;
/* PD14 */
if(command&0x01)
{
temp = 0x4000 | temp;
}
/* PD15 */
if(command&0x02)
{
temp = 0x8000 | temp;
}
/* PD0 */
if(command&0x04)
{
temp = 0x0001 | temp;
}
/* PD0 */
if(command&0x08)
{
temp = 0x0002 | temp;
}
/* Set data to PD data register */
GPIOD->ODR = temp;
/* Second Four bits */
temp = GPIOE->ODR;
temp = 0xF87F & temp;
/* PD0 */
if(command&0xF0)
{
command=(command&0xF0)<<3;
temp = command | temp;
}
/* Set data to PE data register */
GPIOE->ODR = temp;
TFT_delay(10);
/* set write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_SET);//MC_LCD_WR
HAL_Delay(1);
}
/**
* Fun name: TFT_28_7789_writeData
* @brief : initialization of LCD data
* @param : none
* @retval : none
*/
void TFT_28_7789_writeData(unsigned long data)
{
/* First Four bits */
temp = GPIOD->ODR;
temp = 0x3FFC & temp;
/* PD14 */
if(data&0x01)
{
temp = 0x4000 | temp;
}
/* PD15 */
if(data&0x02)
{
temp = 0x8000 | temp;
}
/* PD0 */
if(data&0x04)
{
temp = 0x0001 | temp;
}
/* PD0 */
if(data&0x08)
{
temp = 0x0002 | temp;
}
/* Set data to PD data register */
GPIOD->ODR = temp;
/* Second Four bits */
temp = GPIOE->ODR;
temp = 0xF87F & temp;
/* PD0 */
if(data&0xF0)
{
data=(data&0xF0)<<3;
temp = data | temp;
}
/* Set data to PE data register */
GPIOE->ODR = temp;
/* reset pin */
HAL_GPIO_WritePin( GPIOG, GPIO_PIN_1,GPIO_PIN_SET);//DC PIN
/* reset write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_RESET);
TFT_delay(1);
/* set write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_SET);
}
/**
* Fun name: writeColor
* @brief : initialization of LCD Color
* @param : none
* @retval : none
*/
void writeColor(unsigned long color)
{
unsignedlongdata;
/* set D_C pin */
HAL_GPIO_WritePin( GPIOG, GPIO_PIN_1,GPIO_PIN_SET);
/* reset write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_RESET);
data=color>>8;
/* First Four bits */
temp = GPIOD->ODR;
temp = 0x3FFC & temp;
/* PD14 */
if(data&0x01)
{
temp = 0x4000 | temp;
}
/* PD15 */
if(data&0x02)
{
temp = 0x8000 | temp;
}
/* PD0 */
if(data&0x04)
{
temp = 0x0001 | temp;
}
/* PD0 */
if(data&0x08)
{
temp = 0x0002 | temp;
}
/* Set data to PD data register */
GPIOD->ODR = temp;
/* Second Four bits */
temp = GPIOE->ODR;
temp = 0xF87F & temp;
/* PD0 */
if(data&0xF0)
{
data=(data&0xF0)<<3;
temp = data | temp;
}
/* Set data to PE data register */
GPIOE->ODR = temp;
/* set write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_SET);
data=(color&0xFF);
/* First Four bits */
temp = GPIOD->ODR;
temp = 0x3FFC & temp;
/* PD14 */
if(data&0x01)
{
temp = 0x4000 | temp;
}
/* PD15 */
if(data&0x02)
{
temp = 0x8000 | temp;
}
/* PD0 */
if(data&0x04)
{
temp = 0x0001 | temp;
}
/* PD0 */
if(data&0x08)
{
temp = 0x0002 | temp;
}
/* Set data to PD data register */
GPIOD->ODR = temp;
/* Second Four bits */
temp = GPIOE->ODR;
temp = 0xF87F & temp;
/* PD0 */
if(data&0xF0)
{
data=(data&0xF0)<<3;
temp = data | temp;
}
/* Set data to PE data register */
GPIOE->ODR = temp;
/* reset write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_RESET);
TFT_delay(1);
/* set write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_SET);
}
/**
* @brief The application entry point.
* @retval int
*/
void TFT_28_7789_LCD_Init()
{
/* reset chip select */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_7,GPIO_PIN_RESET);
/* set Read pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_4,GPIO_PIN_SET);
/* reset write pin */
HAL_GPIO_WritePin( GPIOD, GPIO_PIN_5,GPIO_PIN_RESET);
HAL_GPIO_WritePin( GPIOG, GPIO_PIN_4,GPIO_PIN_RESET);
TFT_delay(100);
HAL_GPIO_WritePin( GPIOG, GPIO_PIN_4,GPIO_PIN_SET);
TFT_delay(100);
/* exit from sleep mode */
TFT_28_7789_writeCommand(0x0011);
TFT_delay(100);
TFT_28_7789_writeCommand(0x0036);
TFT_28_7789_writeData(0x0080);//MADCTL: memory data access control
TFT_28_7789_writeCommand(0x003A);
TFT_28_7789_writeData(0x0055);//COLMOD: Interface Pixel format
TFT_28_7789_writeCommand(0x0021);//INVON: Display Inversion ON (setting for IPS)
TFT_28_7789_writeCommand(0x00B2);
TFT_28_7789_writeData(0x000C);
TFT_28_7789_writeData(0x0C);
TFT_28_7789_writeData(0x00);
TFT_28_7789_writeData(0x33);
TFT_28_7789_writeData(0x33);//PORCTRK: Porch setting
TFT_28_7789_writeCommand(0x00B7);
TFT_28_7789_writeData(0x0035);//GCTRL: Gate Control
TFT_28_7789_writeCommand(0x00BB);
TFT_28_7789_writeData(0x002B);//VCOMS: VCOM setting
TFT_28_7789_writeCommand(0x00C0);
TFT_28_7789_writeData(0x002C);//LCMCTRL: LCM Control
TFT_28_7789_writeCommand(0x00C2);
TFT_28_7789_writeData(0x0001);
TFT_28_7789_writeData(0xFF);//VDVVRHEN: VDV and VRH Command Enable
TFT_28_7789_writeCommand(0x00C3);
TFT_28_7789_writeData(0x0011);//VRHS: VRH Set
TFT_28_7789_writeCommand(0x00C4);
TFT_28_7789_writeData(0x0020);//VDVS: VDV Set
TFT_28_7789_writeCommand(0x00C6);
TFT_28_7789_writeData(0x000F);//FRCTRL2: Frame Rate control in normal mode
TFT_28_7789_writeCommand(0x00D0);
TFT_28_7789_writeData(0x00A4);
TFT_28_7789_writeData(0xA1);//PWCTRL1: Power Control 1
TFT_28_7789_writeCommand(0x00E0);
TFT_28_7789_writeData(0x00D0);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x0005);
TFT_28_7789_writeData(0x000E);
TFT_28_7789_writeData(0x0015);
TFT_28_7789_writeData(0x000D);
TFT_28_7789_writeData(0x0037);
TFT_28_7789_writeData(0x0043);
TFT_28_7789_writeData(0x0047);
TFT_28_7789_writeData(0x0009);
TFT_28_7789_writeData(0x0015);
TFT_28_7789_writeData(0x0012);
TFT_28_7789_writeData(0x0016);
TFT_28_7789_writeData(0x0019);//PVGAMCTRL: Positive Voltage Gamma control
TFT_28_7789_writeCommand(0x00E1);
TFT_28_7789_writeData(0x00D0);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x0005);
TFT_28_7789_writeData(0x000D);
TFT_28_7789_writeData(0x000C);
TFT_28_7789_writeData(0x0006);
TFT_28_7789_writeData(0x002D);
TFT_28_7789_writeData(0x0044);
TFT_28_7789_writeData(0x0040);
TFT_28_7789_writeData(0x000E);
TFT_28_7789_writeData(0x001C);
TFT_28_7789_writeData(0x0018);
TFT_28_7789_writeData(0x0016);
TFT_28_7789_writeData(0x0019);//NVGAMCTRL: Negative Voltage Gamma control
TFT_28_7789_writeCommand(0x002A);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x00EF);//X address set
TFT_28_7789_writeCommand(0x002B);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x0000);
TFT_28_7789_writeData(0x0001);
TFT_28_7789_writeData(0x003F);//Y address set
HAL_Delay(1);
TFT_28_7789_writeCommand(0x29);
TFT_28_7789_writeCommand(0x2C);
}
0 -
Hi, To display a red color for background you can use the following code
#include "tft.h" // Assuming this file includes all necessary headers for your TFT display
// RGB565 format for red color
#define RED 0xF800
// Function to fill the LCD with a single color
void LCD_FillScreen(uint16_t color)
{
uint16_t x, y;
for (y = 0; y < LCD_HEIGHT; y++) // Loop through the height of the screen
{
for (x = 0; x < LCD_WIDTH; x++) // Loop through the width of the screen
{
LCD_DrawPixel(x, y, color); // Draw a pixel with the specified color
}
}
}
// Example function to initialize the LCD and fill it with red color
void DisplayRedBackground(void)
{
LCD_Init(); // Initialize the LCD (if not already initialized)
LCD_FillScreen(RED); // Fill the screen with the red color
}and then the main loop in tft.c
int main(void)
{
HAL_Init(); // Initialize HAL
SystemClock_Config(); // Configure system clock
MX_GPIO_Init(); // Initialize GPIO
MX_FSMC_Init(); // Initialize FSMC if using parallel communication
MX_FMPI2C1_Init(); // Initialize I2C if needed
// Display red background on the LCD
DisplayRedBackground();
while(1)
{
// Main loop code
}
}0
Please sign in to leave a comment.
Comments
5 comments