智能车制作
标题:
关于STM32非FSMC方式驱动TFT屏的问题,求各种指导!!!!!!
[打印本页]
作者:
奋斗人生
时间:
2013-11-9 22:51
标题:
关于STM32非FSMC方式驱动TFT屏的问题,求各种指导!!!!!!
本帖最后由 奋斗人生 于 2013-11-9 23:00 编辑
最近在用STM32的普通IO口驱动TFT屏幕,弄了好久,屏幕上都没反应,就一个很简单的清屏和画点都搞不定,TFT屏是用ILI9341驱动的。。。在其它板子上用FSMC方式驱动正常(说明TFT屏幕没问题),但就是不用FSMC方式就点不亮了,,,
程序如下:求指导,我总觉得是LCD_WriteEnable();和LCD_WriteData();的问题,想知道这两个函数对不对。。。
#define LCD_CS(x) (x)?(GPIO_SetBits(GPIOA,GPIO_Pin_0))
GPIO_ResetBits(GPIOA,GPIO_Pin_0))
#define LCD_RS(x) (x)?(GPIO_SetBits(GPIOA,GPIO_Pin_8)):(GPIO_ResetBits(GPIOA,GPIO_Pin_8))
#define LCD_BL(x) (x)?(GPIO_SetBits(GPIOC,GPIO_Pin_6)):(GPIO_ResetBits(GPIOC,GPIO_Pin_6))
#define LCD_RST(x) (x)?(GPIO_SetBits(GPIOC,GPIO_Pin_7)):(GPIO_ResetBits(GPIOC,GPIO_Pin_7))
#define LCD_RD(x) (x)?(GPIO_SetBits(GPIOC,GPIO_Pin_8)):(GPIO_ResetBits(GPIOC,GPIO_Pin_8))
#define LCD_WR(x) (x)?(GPIO_SetBits(GPIOC,GPIO_Pin_9)):(GPIO_ResetBits(GPIOC,GPIO_Pin_9))
void Delay(uint32_t num)
{
uint32_t i;
for(i=0; i<num; i++);
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_8; //LCD_CS | LCD_RS
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; //D0~D15
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //Ç°ËĸöÎaLED
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //oóËĸöòà′ÎÎaBL RST
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; //oóËĸöòà′ÎÎa RD WR
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_All);
LCD_RST(1);
LCD_RS(1);
LCD_RD(1);
LCD_CS(1);
LCD_WR(1);
}
void LCD_WriteEnable(uint8_t data)
{
LCD_RS(0); //0Ãüáî
LCD_RD(1); //D′êy¾Y
LCD_CS(0); //0Ñ¡¶¨
GPIOB->ODR=data; //
LCD_WR(0); //D′êy¾Y
LCD_WR(1);
LCD_CS(1);
}
void LCD_WriteData(uint16_t data)
{
LCD_RS(1); //1êy¾Y
LCD_RD(1); //D′êy¾Y
LCD_CS(0); //0Ñ¡¶¨
GPIOB->ODR=data; //
LCD_WR(0); //D′êy¾Y
LCD_WR(1);
LCD_CS(1);
}
void LCD_PrepareToWrite(void)
{
LCD_WriteEnable(0x2C);
}
void LCD_ILI9341_Init(void)
{
LCD_RST(0);
Delay(0xFFFFF);
LCD_RST(1);
Delay(0x5FFFF);
LCD_WriteEnable(0xCF);
LCD_WriteData(0x00);
LCD_WriteData(0x81);
LCD_WriteData(0X30);
LCD_WriteEnable(0xED);
LCD_WriteData(0x64);
LCD_WriteData(0x03);
LCD_WriteData(0X12);
LCD_WriteData(0X81);
LCD_WriteEnable(0xE8);
LCD_WriteData(0x85);
LCD_WriteData(0x10);
LCD_WriteData(0x7A);
LCD_WriteEnable(0xCB);
LCD_WriteData(0x39);
LCD_WriteData(0x2C);
LCD_WriteData(0x00);
LCD_WriteData(0x34);
LCD_WriteData(0x02);
LCD_WriteEnable(0xF7);
LCD_WriteData(0x20);
LCD_WriteEnable(0xEA);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteEnable(0xC0); //Power control
LCD_WriteData(0x1B); //VRH[5:0]
LCD_WriteEnable(0xC1); //Power control
LCD_WriteData(0x01); //SAP[2:0];BT[3:0]
LCD_WriteEnable(0xC5); //VCM control
LCD_WriteData(0x30); //3F
LCD_WriteData(0x30); //3C
LCD_WriteEnable(0xC7); //VCM control2
LCD_WriteData(0XB7);
LCD_WriteEnable(0x36); // Memory Access Control
LCD_WriteData(0x68);
LCD_WriteEnable(0x3A);
LCD_WriteData(0x55);
LCD_WriteEnable(0xB1);
LCD_WriteData(0x00);
LCD_WriteData(0x1A);
LCD_WriteEnable(0xB6); // Display Function Control
LCD_WriteData(0x0A);
LCD_WriteData(0xA2);
LCD_WriteEnable(0xF2); // 3Gamma Function Disable
LCD_WriteData(0x00);
LCD_WriteEnable(0x26); //Gamma curve selected
LCD_WriteData(0x01);
LCD_WriteEnable(0xE0); //Set Gamma
LCD_WriteData(0x0F);
LCD_WriteData(0x2A);
LCD_WriteData(0x28);
LCD_WriteData(0x08);
LCD_WriteData(0x0E);
LCD_WriteData(0x08);
LCD_WriteData(0x54);
LCD_WriteData(0xA9);
LCD_WriteData(0x43);
LCD_WriteData(0x0A);
LCD_WriteData(0x0F);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteEnable(0xE1); //Set Gamma
LCD_WriteData(0x00);
LCD_WriteData(0x15);
LCD_WriteData(0x17);
LCD_WriteData(0x07);
LCD_WriteData(0x11);
LCD_WriteData(0x06);
LCD_WriteData(0x2B);
LCD_WriteData(0x56);
LCD_WriteData(0x3C);
LCD_WriteData(0x05);
LCD_WriteData(0x10);
LCD_WriteData(0x0F);
LCD_WriteData(0x3F);
LCD_WriteData(0x3F);
LCD_WriteData(0x0F);
LCD_WriteEnable(0x2B);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0xef);
LCD_WriteEnable(0x2A);
LCD_WriteData(0x00);
LCD_WriteData(0x00);
LCD_WriteData(0x01);
LCD_WriteData(0x3f);
LCD_WriteEnable(0x11); //Exit Sleep
Delay(0xFFFF);
LCD_WriteEnable(0x29); //display on
}
void LCD_StartAddrSet(uint16_t Xpos, uint16_t Ypos)
{
LCD_WriteEnable(0x2A);
LCD_WriteData(Xpos>>8);
LCD_WriteData(Xpos&0XFF);
LCD_WriteEnable(0X2B);
LCD_WriteData(Ypos>>8);
LCD_WriteData(Ypos&0XFF);
}
void LCD_Clear(uint16_t color)
{
uint32_t index;
LCD_StartAddrSet(0x0,0x0);
LCD_PrepareToWrite();
for(index=0; index<76800; index++)
{
LCD_WriteData(color);
}
}
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
{
LCD_StartAddrSet(x,y);
LCD_PrepareToWrite();
LCD_WriteData(color);
}
int main(void)
{
uint16_t i;
GPIO_Config();
LCD_ILI9341_Init();
LCD_BL(1);//开背光
LCD_Clear(0x001F);
LCD_DrawPoint(100,100,0x0000);
LCD_DrawPoint(100,101,0x0000);
LCD_DrawPoint(100,102,0x0000);
LCD_DrawPoint(100,103,0x0000);
LCD_DrawPoint(100,104,0x0000);
LCD_DrawPoint(100,105,0x0000);
LCD_DrawPoint(100,106,0x0000);
LCD_DrawPoint(100,107,0x0000);
LCD_DrawPoint(100,108,0x0000);
LCD_DrawPoint(100,109,0x0000);
while(1)
{
}
}
作者:
简单丹
时间:
2013-11-10 08:57
原子例程不是有吗?
作者:
奋斗人生
时间:
2013-11-10 09:29
简单丹 发表于 2013-11-10 08:57
原子例程不是有吗?
接原子的mini开发板上也没反应,似乎他程序里写了这个ILI9341的驱动,,,用其它开发板的FSMC方式可以正常驱动,,,
作者:
简单丹
时间:
2013-11-12 19:17
mini开发板有现成的9341IO口驱动程序啊
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2