一、FSMC手册资料
FSMC方式可以驱动多种类型的总线设备,这里显示屏使用的是8080控制方式。
二、代码
主要代码部分如下
2.1、lcd.c
#include "lcd.h"
#include "board_init.h"
#include "delay.h"
extern void LCD_InitHardware(void);
extern void LCD_WriteCmd(uint16_t cmd);
extern void LCD_WriteData(uint16_t dat);
extern uint16_t LCD_ReadData(void);
static void lcd_rst(void)
{
GPIO_SetBits(BOARD_LCD_RST_GPIO_PORT, BOARD_LCD_RST_GPIO_PIN);
delay_ms(1);
GPIO_ClearBits(BOARD_LCD_RST_GPIO_PORT, BOARD_LCD_RST_GPIO_PIN);
delay_ms(10);
GPIO_SetBits(BOARD_LCD_RST_GPIO_PORT, BOARD_LCD_RST_GPIO_PIN);
delay_ms(120);
}
void LCD_Init(LCD_Init_Type * init)
{
uint32_t id=0;
LCD_InitHardware();
lcd_rst();
LCD_WriteCmd(0x0011);
delay_ms(120);
LCD_WriteCmd(0x0036);
LCD_WriteData(0x0060);
LCD_WriteCmd(0x003A);
LCD_WriteData(0x0005);
LCD_WriteCmd(0x00B2);
LCD_WriteData(0x000C);
LCD_WriteData(0x000C);
LCD_WriteData(0x0000);
LCD_WriteData(0x0033);
LCD_WriteData(0x0033);
LCD_WriteCmd(0x00B7);
LCD_WriteData(0x0035);
LCD_WriteCmd(0x00BB);
LCD_WriteData(0x001c);
LCD_WriteCmd(0x00C0);
LCD_WriteData(0x002C);
LCD_WriteCmd(0x00C2);
LCD_WriteData(0x0001);
LCD_WriteData(0x00FF);
LCD_WriteCmd(0x00C3);
LCD_WriteData(0x000B);
LCD_WriteCmd(0x00C4);
LCD_WriteData(0x0020);
LCD_WriteCmd(0x00C6);
LCD_WriteData(0x000F);
LCD_WriteCmd(0x00D0);
LCD_WriteData(0x00A4);
LCD_WriteData(0x00A1);
LCD_WriteCmd(0x00E0);
LCD_WriteData(0x00D0);
LCD_WriteData(0x0000);
LCD_WriteData(0x0003);
LCD_WriteData(0x0009);
LCD_WriteData(0x0013);
LCD_WriteData(0x001c);
LCD_WriteData(0x003a);
LCD_WriteData(0x0055);
LCD_WriteData(0x0048);
LCD_WriteData(0x0018);
LCD_WriteData(0x0012);
LCD_WriteData(0x000e);
LCD_WriteData(0x0019);
LCD_WriteData(0x001e);
LCD_WriteCmd(0x00E1);
LCD_WriteData(0x00D0);
LCD_WriteData(0x0000);
LCD_WriteData(0x0003);
LCD_WriteData(0x0009);
LCD_WriteData(0x0005);
LCD_WriteData(0x0025);
LCD_WriteData(0x003a);
LCD_WriteData(0x0055);
LCD_WriteData(0x0050);
LCD_WriteData(0x003d);
LCD_WriteData(0x001c);
LCD_WriteData(0x001d);
LCD_WriteData(0x001d);
LCD_WriteData(0x001e);
LCD_WriteCmd(0x0029);
}
void LCD_SetWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
LCD_WriteCmd(0x2a);
LCD_WriteData(x0 >> 8);
LCD_WriteData(x0 & 0xff);
LCD_WriteData(x1 >> 8);
LCD_WriteData(x1 & 0xff);
LCD_WriteCmd(0x2b);
LCD_WriteData(y0 >> 8);
LCD_WriteData(y0 & 0xff);
LCD_WriteData(y1 >> 8);
LCD_WriteData(y1 & 0xff);
}
void LCD_ClearWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
{
LCD_SetWindow(x0, y0, x1, y1);
LCD_WriteCmd(0x2c);
for(uint32_t i = 0; i <= x1 - x0; i++)
{
for(uint32_t j = 0; j <= y1 - y0; j++)
{
LCD_WriteData(color);
}
}
}
void LCD_FillWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t * color)
{
LCD_SetWindow(x0, y0, x1, y1);
LCD_WriteCmd(0x2c);
for(uint32_t i = 0; i <= x1 - x0; i++)
{
for(uint32_t j = 0; j <= y1 - y0; j++)
{
LCD_WriteData((* color++));
}
}
}
void LCD_DrawPixel(uint16_t x, uint16_t y, uint16_t color)
{
LCD_ClearWindow(x, y, x, y, color);
}
2.2、lcd_port.c
#include "lcd.h"
#include "board_init.h"
void LCD_InitHardware(void)
{
FSMC_Init_Type fsmc_init =
{
.MemType = FSMC_MemType_SRAM,
.MemSize = FSMC_MemSize_64MB
};
FSMC_Conf_Type fsmc_conf =
{
.ReadPeriod = 0x1u,
.AddrSetTime = 0x3u,
.WriteHoldTime = 0x1u,
.WritePeriod = 0x2u,
.ReadySignal = FSMC_ReadySignal_Internal,
.SMReadPipe = 0u,
.BusWidth = FSMC_BusWidth_16b
};
FSMC_Init(BOARD_LCD_FSMC_PORT, 3, &fsmc_init);
FSMC_SetConf(BOARD_LCD_FSMC_PORT, BOARD_LCD_FSMC_SET_INDEX, &fsmc_conf);
FSMC_EnableConf(BOARD_LCD_FSMC_PORT, 3, BOARD_LCD_FSMC_SET_INDEX);
GPIO_WriteBit(BOARD_LCD_BL_GPIO_PORT, BOARD_LCD_BL_GPIO_PIN, 1u);
}
void LCD_WriteCmd(uint16_t cmd)
{
FSMC_PutData16(BOARD_LCD_FSMC_PORT, 3, 0, cmd);
}
void LCD_WriteData(uint16_t dat)
{
FSMC_PutData16(BOARD_LCD_FSMC_PORT, 3, (1u << BOARD_LCD_FSMC_RS_BIT_INDEX), dat);
}
uint16_t LCD_ReadData(void)
{
return FSMC_GetData16(BOARD_LCD_FSMC_PORT, 3, (1 << BOARD_LCD_FSMC_RS_BIT_INDEX));
}
2.3、main.c
int main(void)
{
BOARD_Init();
delay_init();
LCD_Init_Type lcd_init =
{
.DisplayMode = LCD_DisplayMode_Landspace,
};
LCD_Init(&lcd_init);
printf("\r\nmm32f5270 test.\r\n");
while(1)
{
GPIO_WriteBit(BOARD_LED0_GPIO_PORT, BOARD_LED0_GPIO_PIN, 1u);
delay_ms(100);
GPIO_WriteBit(BOARD_LED0_GPIO_PORT, BOARD_LED0_GPIO_PIN, 0u);
delay_ms(100);
LCD_ClearWindow(0u, 0u, BOARD_LCD_HEIGHT-1u, BOARD_LCD_WIDTH-1u, LCD_COLOR_RED);
delay_ms(1000);
LCD_ClearWindow(0u, 0u, BOARD_LCD_HEIGHT-1u, BOARD_LCD_WIDTH-1u, LCD_COLOR_GREEN);
delay_ms(1000);
LCD_ClearWindow(0u, 0u, BOARD_LCD_HEIGHT-1u, BOARD_LCD_WIDTH-1u, LCD_COLOR_BLUE);
delay_ms(1000);
}
}
三、程序运行
原作者:小会