我把例程中的LCD驱动程序单独拿出来,自己做LCD的驱动实验,用红色刷新屏幕时,屏幕上有区域没有刷新,不知道是什么原因?
代码如下:
#include "lcd.h"
#include "stm32f10x.h"
#include "delay.h"
#include "typedef.h"
#define LCD_ILI9341_CMD(index) LCD_WR_REG(index)
#define LCD_ILI9341_Parameter(val) LCD_WR_Data(val)
static void LCD_GPIO_Config(void);
static void LCD_FSMC_Config(void);
static void LCD_Rst(void);
static void LCDInitConf(void);
static void LCDDataStart(void);
static void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 使能FSMC时钟*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
/* 使能FSMC对应相应管脚时钟*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* 配置LCD复位控制管脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* 配置FSMC相对应的数据线,FSMC-D0~D15: PD 14 15 0 1,PE 7 8 9 10 11 12 13 14 15,PD 8 9 10*/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |
GPIO_Pin_1 |
GPIO_Pin_8 |
GPIO_Pin_9 |
GPIO_Pin_10 |
GPIO_Pin_14 |
GPIO_Pin_15;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 |
GPIO_Pin_8 |
GPIO_Pin_9 |
GPIO_Pin_10 |
GPIO_Pin_11 |
GPIO_Pin_12 |
GPIO_Pin_13 |
GPIO_Pin_14 |
GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* 配置FSMC相对应的控制线
* PD4-FSMC_NOE CD-RD
* PD5-FSMC_NWE CD-WR
* PD7-FSMC_NE1 CD-CS
* PD11-FSMC_A16 CD-DC
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; /* RD -- read */
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; /* WR -- write */
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; /* CS -- chip select */
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; /* RS/DC -- data/command */
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* tft control gpio init */
GPIO_ResetBits(GPIOD, GPIO_Pin_13);
GPIO_SetBits(GPIOE, GPIO_Pin_1);
GPIO_ResetBits(GPIOD, GPIO_Pin_3);
GPIO_SetBits(GPIOD, GPIO_Pin_6);
}
static void LCD_FSMC_Config(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
p.FSMC_AddressSetupTime = 0x02; //地址建立时间
p.FSMC_AddressHoldTime = 0x00; //地址保持时间
p.FSMC_DataSetupTime = 0x05; //数据建立时间
p.FSMC_BusTurnAroundDuration = 0x00;
p.FSMC_CLKDivision = 0x00;
p.FSMC_DataLatency = 0x00;
p.FSMC_AccessMode = FSMC_AccessMode_B; // 一般使用模式B来控制LCD
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* 使能 FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
static void LCD_Rst(void)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_1); //低电平复位
DelayMs(10);
GPIO_SetBits(GPIOE, GPIO_Pin_1 );
DelayMs(12);
}
static void LCDInitConf(void)
{
LCD_ILI9341_CMD(0xCF);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x81);
LCD_ILI9341_Parameter(0x30);
LCD_ILI9341_CMD(0xED);
LCD_ILI9341_Parameter(0x64);
LCD_ILI9341_Parameter(0x03);
LCD_ILI9341_Parameter(0x12);
LCD_ILI9341_Parameter(0x81);
LCD_ILI9341_CMD(0xE8);
LCD_ILI9341_Parameter(0x85);
LCD_ILI9341_Parameter(0x10);
LCD_ILI9341_Parameter(0x78);
LCD_ILI9341_CMD(0xCB);
LCD_ILI9341_Parameter(0x39);
LCD_ILI9341_Parameter(0x2C);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x34);
LCD_ILI9341_Parameter(0x02);
LCD_ILI9341_CMD(0xF7);
LCD_ILI9341_Parameter(0x20);
LCD_ILI9341_CMD(0xEA);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_CMD(0xB1);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x1B);
LCD_ILI9341_CMD(0xB6);
LCD_ILI9341_Parameter(0x0A);
LCD_ILI9341_Parameter(0xA2);
LCD_ILI9341_CMD(0xC0);
LCD_ILI9341_Parameter(0x35);
LCD_ILI9341_CMD(0xC1);
LCD_ILI9341_Parameter(0x11);
LCD_ILI9341_CMD(0xC5);
LCD_ILI9341_Parameter(0x45);
LCD_ILI9341_Parameter(0x45);
LCD_ILI9341_CMD(0xC7);
LCD_ILI9341_Parameter(0xA2);
LCD_ILI9341_CMD(0xF2);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_CMD(0x26);
LCD_ILI9341_Parameter(0x01);
LCD_ILI9341_CMD(0xE0); //Set Gamma
LCD_ILI9341_Parameter(0x0F);
LCD_ILI9341_Parameter(0x26);
LCD_ILI9341_Parameter(0x24);
LCD_ILI9341_Parameter(0x0B);
LCD_ILI9341_Parameter(0x0E);
LCD_ILI9341_Parameter(0x09);
LCD_ILI9341_Parameter(0x54);
LCD_ILI9341_Parameter(0xA8);
LCD_ILI9341_Parameter(0x46);
LCD_ILI9341_Parameter(0x0C);
LCD_ILI9341_Parameter(0x17);
LCD_ILI9341_Parameter(0x09);
LCD_ILI9341_Parameter(0x0F);
LCD_ILI9341_Parameter(0x07);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_CMD(0XE1); //Set Gamma
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x19);
LCD_ILI9341_Parameter(0x1B);
LCD_ILI9341_Parameter(0x04);
LCD_ILI9341_Parameter(0x10);
LCD_ILI9341_Parameter(0x07);
LCD_ILI9341_Parameter(0x2A);
LCD_ILI9341_Parameter(0x47);
LCD_ILI9341_Parameter(0x39);
LCD_ILI9341_Parameter(0x03);
LCD_ILI9341_Parameter(0x06);
LCD_ILI9341_Parameter(0x06);
LCD_ILI9341_Parameter(0x30);
LCD_ILI9341_Parameter(0x38);
LCD_ILI9341_Parameter(0x0F);
LCD_ILI9341_CMD(0x36);
LCD_ILI9341_Parameter(0x68); /*横屏 左上角到(起点)到右下角(终点)扫描方式*/
LCD_ILI9341_CMD(0X2A);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x01);
LCD_ILI9341_Parameter(0x3F);
LCD_ILI9341_CMD(0X2B);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0x00);
LCD_ILI9341_Parameter(0xEF);
LCD_ILI9341_CMD(0x3a); // Memory Access Control
LCD_ILI9341_Parameter(0x55);
LCD_ILI9341_CMD(0x11); //Exit Sleep
DelayMs(10);
LCD_ILI9341_CMD(0x29); //display on
LCD_ILI9341_CMD(0x2c);
}
static void LCDDataStart(void)
{
LCD_ILI9341_CMD(0x2C);//开始写
}
void LCDInit(void)
{
UL i = 0;
LCD_GPIO_Config();
LCD_FSMC_Config();
LCD_Rst();
LCDInitConf();
LCDDataStart();
for(i=0; i<(320*240); i++)
{
LCD_WR_Data(RED);
}
} |