STM32F429 Discovery FMC驅(qū)動(dòng)原子4.3寸LCD
上一篇寫了GPIO簡(jiǎn)單的流水燈測(cè)試,看著有點(diǎn)單調(diào),習(xí)慣了串口調(diào)試,板子上沒(méi)有串口 那就另想辦法吧,看著LCD突然有了個(gè)想法,為什么不把調(diào)試信息輸出到LCD上,以前在做2416 WINCE開(kāi)發(fā)的時(shí)候就經(jīng)常這樣干非常直觀,那說(shuō)干就干。
STM32F429I-DISO SDK里已經(jīng)把開(kāi)發(fā)包做好,那就直接拿過(guò)來(lái)用吧。
#define MESSAGE1 "STM32F429I-Discoverry" //提示信息
#define MESSAGE1_1 " GPIO TEST "
#define MESSAGE2 " LED3 LED4 "
#define MESSAGE2_1 " ^-^ "
#define MESSAGE5 " LED3 = %d" //LED3狀態(tài) 1亮 0滅
#define MESSAGE6 " LED4 = %d" //LED4狀態(tài)
#define LINENUM 0x15 //行數(shù)
#define FONTSIZE Font12x12 //字體大小
定義完了,那就該具體實(shí)現(xiàn)了,慣例先初始化 LCD初始化實(shí)現(xiàn):
static void Display_Init(void)
{
/* Initialize the LCD */
LCD_Init();
LCD_LayerInit();
/* Eable the LTDC */
LTDC_Cmd(ENABLE);
/* Set LCD Background Layer */
LCD_SetLayer(LCD_BACKGROUND_LAYER);
/* Clear the Background Layer */
LCD_Clear(LCD_COLOR_WHITE);
/* Configure the transparency for background */
LCD_SetTransparency(0);
/* Set LCD Foreground Layer */
LCD_SetLayer(LCD_FOREGROUND_LAYER);
/* Configure the transparency for foreground */
LCD_SetTransparency(200);
/* Clear the Foreground Layer */
LCD_Clear(LCD_COLOR_WHITE);
/* Set the LCD Back Color and Text Color*/
LCD_SetBackColor(LCD_COLOR_BLUE);
LCD_SetTextColor(LCD_COLOR_WHITE);
/* Set the LCD Text size */
LCD_SetFont(&FONTSIZE);
/* Set the LCD Back Color and Text Color*/
LCD_SetBackColor(LCD_COLOR_BLUE);
LCD_SetTextColor(LCD_COLOR_WHITE);
LCD_DisplayStringLine(LINE(LINENUM), (uint8_t*)MESSAGE1);
LCD_DisplayStringLine(LINE(LINENUM + 1), (uint8_t*)MESSAGE1_1);
LCD_DisplayStringLine(LINE(0x17), (uint8_t*)" ");
/* Set the LCD Text size */
LCD_SetFont(&Font16x24);
LCD_DisplayStringLine(LCD_LINE_0, (uint8_t*)MESSAGE2);
LCD_DisplayStringLine(LCD_LINE_1, (uint8_t*)MESSAGE2_1);
/* Set the LCD Back Color and Text Color*/
LCD_SetBackColor(LCD_COLOR_WHITE);
LCD_SetTextColor(LCD_COLOR_BLUE);
}
初始化完成了,那就改實(shí)現(xiàn)顯示函數(shù)了
static void Display(void)
{
uint8_t led3 = 0, led4 = 0;
uint8_t aTextBuffer[50];
led3 = GPIO_ReadOutputDataBit(LED3_GPIO_PORT,LED3_PIN); //讀取LED3對(duì)應(yīng)引腳值
sprintf((char*)aTextBuffer, MESSAGE5, led3);
LCD_DisplayStringLine(LCD_LINE_4, (uint8_t*)aTextBuffer); //把LED3狀態(tài)更新到屏幕上
led4 = GPIO_ReadOutputDataBit(LED3_GPIO_PORT,LED4_PIN); //讀取LED4對(duì)應(yīng)引腳值
sprintf((char*)aTextBuffer, MESSAGE6, led4);
LCD_DisplayStringLine(LCD_LINE_6, (uint8_t*)aTextBuffer); //把LED4狀態(tài)更新到屏幕上
}
這就是顯示函數(shù),讀取LED對(duì)應(yīng)的值,組成字符串,最后更新到LCD,LCD顯示。
接下來(lái)就改主函數(shù)了:
int main(void)
{
int i;
Display_Init();
LEDInit();
SysTickInit();
while (1)
{
Delay(500);
GPIO_SetBits(LED4_GPIO_PORT,LED4_PIN);
GPIO_ResetBits(LED3_GPIO_PORT,LED3_PIN);
Display();
Delay(500);
GPIO_SetBits(LED3_GPIO_PORT,LED3_PIN);
GPIO_ResetBits(LED4_GPIO_PORT,LED4_PIN);
Display();
}
}
慣例,主要函數(shù)部分實(shí)現(xiàn)完了,那就看最終的顯示結(jié)果吧.