STM32F429 Discovery LTDC (LCD TFT Display Control)

NAME SURNAME:
NUMBER:
CEN 425 Embedded Systems
STM32F429 Discovery LTDC (LCD TFT Display Control)
The LCD-TFT (Liquid Crystal Display - Thin Film Transistor) display controller provides a parallel digital RGB
(Red, Green, Blue) and signals for horizontal, vertical synchronisation, Pixel Clock and Data Enable as output to
interface directly to a variety of LCD and TFT panels.
void LCD_Init (void)
Initializes the LCD.
Parameters: None.
Return values: None.
void LCD_LayerInit (void)
Initializes the LCD layers.
Parameters: None.
Return values: None.
void LTDC_Cmd (FunctionalState NewState)
Enables or disables the LTDC Controller.
Parameters:
NewState: New state of the LTDC peripheral. This parameter can be: ENABLE or DISABLE.
Return values: None.
void LCD_SetLayer (uint32_t Layerx)
Sets the LCD Layer.
Parameters:
Layerx: Specifies the Layer foreground or background.
Return values: None.
void LCD_Clear (uint16_t Color)
Clears the hole LCD.
Parameters:
Color: The color of the background.
Return values: None.
void LCD_SetFont (sFONT* fonts)
Sets the Text Font.
Parameters:
fonts: Specifies the font to be used.
Return values: None.
Variables




sFONT
sFONT
sFONT
sFONT
Font12x12
Font16x24
Font8x12
Font8x8
void LCD_SetTextColor (__IO uint16_t Color)
Sets the Text color.
Parameters:
Color: Specifies the Text color code RGB(5-6-5).
Return values: None.
void LCD_DisplayStringLine (uint16_t Line, uint8_t* ptr)
Displays a maximum of 20 char on the LCD.
Parameters:
Line: The Line where to display the character shape. This parameter can be one of the following values:
Linex: Where x can be 0..9
*ptr: Pointer to string to display on LCD.
Return values: None.
void LCD_DrawFullCircle (uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Displays a full circle.
Parameters:
Xpos: Specifies the X position.
Ypos: Specifies the Y position.
Radius
Return values: None.
void LCD_DrawCircle (uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Displays a circle.
Parameters:
Xpos: Specifies the X position.
Ypos: Specifies the Y position.
Radius
Return values: None.
void LCD_DrawFullRect (uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t
Height)
Displays a full rectangle.
Parameters:
Xpos: Specifies the X position.
Ypos: Specifies the Y position.
Height: Rectangle height.
Width: Rectangle width.
Return values: None.
void LCD_DrawRect (uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Displays a rectangle.
Parameters:
Xpos: Specifies the X position.
Ypos: Specifies the Y position.
Height: Rectangle height.
Width: Rectangle width.
Return values: None.
void LCD_DrawLine
Direction)
(uint16_t
Xpos,
uint16_t
Ypos,
uint16_t
Length,
uint8_t
Displays a line.
Parameters:
Xpos: Specifies the X position.
Ypos: Specifies the Y position.
Length: Line length.
Direction: Line direction. This parameter can be one of the following values: Vertical or Horizontal.
Return values: None.
void LCD_DrawChar (uint16_t
Xpos, uint16_t Ypos, const uint16_t* c)
2
Draws a character on LCD.
Parameters:
Xpos: The Line where to display the character shape.
Ypos: Start column address.
c: Pointer to the character data.
Return values: None.
void LCD_DisplayChar (uint16_t Line,uint16_t Column, uint8_t Ascii)
Displays one character (16dots width, 24dots height).
Parameters:
Line: The Line where to display the character shape . This parameter can be one of the following values:
 Linex: Where x can be 0..9
Column: Start column address.
Ascii: Character ascii code, must be between 0x20 and 0x7E.
Return values: None.
Add your project a new Library file
1.Step: Open Options for Target window. Choose C/C++ and add the followings to the Include Paths:
C:\WorkSpace\STM32F4Libraries\Utilities
C:\WorkSpace\STM32F4Libraries\Utilities\Common
C:\WorkSpace\STM32F4Libraries\Utilities\STM32F429I-Discovery
C:\WorkSpace\STM32F4Libraries\Utilities\Third_Party
2.Step: Right click in the Project window, choose Manage Project Items.
Add lcd to Groups:
Add Files: the followings:
stm32f429i_discovery.c
stm32f429i_discovery.h
stm32f429i_discovery_ioe.c
stm32f429i_discovery_ioe.h
stm32f429i_discovery_lcd.c
stm32f429i_discovery_lcd.h
stm32f429i_discovery_sdram.c
stm32f429i_discovery_sdram.h
Also, don’t forget to add the Manage Run_time Environment window StdPeriph Drivers the followings:
SYSCFG, SPI, RCC, LTDC, I2C, GPIO, Framework, EXTI, DMA, DMA2D.
3
Laboratory Task:

Write the required C program code given as below.

Make the requirred adjustments, and observe the STM32F429ZI Disco Board operation.

Try to write down your own name, surname, your school number to the display by using different colors.

Try to draw a rectangle to the right side of the display.
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_ltdc.h"
#include "misc.h"
#include <stdio.h>
#include "stm32f429i_discovery.h"
#include "stm32f429i_discovery_lcd.h"
#include "stm32f429i_discovery_ioe.h"
#define LCD_COLOR_BROWN
0x69A0
#define LCD_COLOR_ORANGE
0xF941
#define LCD_COLOR_GRAY
0x5ACA
#define LCD_COLOR_GOLD
0xC524
#define LCD_COLOR_SILVER
0xBE16
uint32_t i = 2;
uint32_t n = 0;
uint32_t LED[3] = {GPIO_Pin_13, GPIO_Pin_14, (GPIO_Pin_13 | GPIO_Pin_14)};
void loop(void);
//void delay(uint32_t ms);
void toggleLed(void);
void switchLed(void);
static void Panel_Config(void);
int main() {
GPIO_InitTypeDef GPIO_InitDef;
EXTI_InitTypeDef EXTI_InitDef;
NVIC_InitTypeDef NVIC_InitDef;
RCC_ClocksTypeDef RCC_ClockFreq;
4
//LTDC_InitTypeDef
LTDC_InitDef;
//----------------------------------------------------RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
GPIO_InitDef.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitDef.GPIO_Speed = GPIO_Speed_25MHz;
//Initialize pins
GPIO_Init(GPIOG, &GPIO_InitDef);
//----------------------------------------------------//----------------------------------------------------RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitDef.GPIO_Pin = GPIO_Pin_0;
GPIO_InitDef.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitDef.GPIO_Speed = GPIO_Speed_25MHz;
//Initialize pins
GPIO_Init(GPIOA, &GPIO_InitDef);
//----------------------------------------------------//----------------------------------------------------RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
EXTI_InitDef.EXTI_Line = EXTI_Line0;
EXTI_InitDef.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitDef.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitDef.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitDef);
//----------------------------------------------------//----------------------------------------------------NVIC_InitDef.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitDef.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitDef.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitDef.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitDef);
//----------------------------------------------------//-----------------------------------------------------
5
SysTick_Config(SystemCoreClock / 1000);
NVIC_SetPriority(SysTick_IRQn, 1);
RCC_GetClocksFreq(&RCC_ClockFreq);
LCD_Init();
LCD_LayerInit();
LTDC_Cmd(ENABLE);
LCD_SetLayer(LCD_FOREGROUND_LAYER);
Panel_Config();
while (1){
loop();
};
}
static void Panel_Config(void) {
LCD_Clear(LCD_COLOR_MAGENTA);
}
//----------------------------------------------------void loop() {
__NOP();
}
//----------------------------------------------------/*void delay(uint32_t ms) {
ms *= 3360;
while(ms--) {
__NOP();
}
}*/
//----------------------------------------------------void EXTI0_IRQHandler() {
if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
switchLed();
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
//----------------------------------------------------void SysTick_Handler(void) {
n++;
toggleLed();
}
//----------------------------------------------------void toggleLed(void) {
6
if (n % 250 == 0) {
GPIO_SetBits(GPIOG, LED[i]);
}
}
//----------------------------------------------------void switchLed(void) {
GPIO_ResetBits(GPIOG, LED[i]);
i++;
if (i > 2) {
i = 0;
}
if (i == 0) {
LCD_Clear(LCD_COLOR_WHITE);
LCD_SetFont(&Font16x24);
LCD_SetTextColor(LCD_COLOR_GREEN);
LCD_DisplayStringLine(LCD_LINE_5,(uint8_t*)"
THE GREEN
");
LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)"
LED IS
");
LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)"
ON
");
LCD_SetFont(&Font16x24);
LCD_SetTextColor(0x5678);
LCD_DrawRect(200,
200,
30, 30);
LCD_SetFont(&Font16x24);
LCD_SetTextColor(0xC525);
LCD_DrawFullEllipse(150,
250,
30, 30);
}
else if (i == 1) {
LCD_Clear(LCD_COLOR_WHITE);
LCD_SetFont(&Font16x24);
LCD_SetTextColor(LCD_COLOR_RED);
LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)" THE RED ");
LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)" LED IS
");
LCD_DisplayStringLine(LCD_LINE_8,(uint8_t*)"
");
ON
LCD_SetFont(&Font16x24);
LCD_SetTextColor(LCD_COLOR_GOLD);
LCD_DrawFullCircle(150,
100,
50);
LCD_SetFont(&Font12x12);
LCD_SetTextColor(LCD_COLOR_SILVER);
LCD_DrawFullCircle(250,
200,
10);
}
else {
7
LCD_Clear(LCD_COLOR_WHITE);
LCD_SetFont(&Font8x8);
LCD_SetTextColor(LCD_COLOR_BLACK);
LCD_DisplayStringLine(LCD_LINE_6,(uint8_t*)"
BOTH THE
");
LCD_DisplayStringLine(LCD_LINE_7,(uint8_t*)"
LEDS ARE
");
LCD_DisplayStringLine(LCD_LINE_8,(uint8_t*)"
ON
");
LCD_SetTextColor(LCD_COLOR_CYAN);
LCD_DrawFullCircle(50,
100,
20);
LCD_SetFont(&Font16x24);
LCD_SetTextColor(LCD_COLOR_BLUE);
LCD_DisplayChar(150, 70, 0x45);
LCD_DisplayChar(150, 78, 0x4D);
}
}//-----------------------------------------------------
8