本帖最后由 红色的枫叶 于 2015-5-22 17:48 编辑
TFT初始化以后用TFT_Write_Color刷屏,碰运气成功过一次,之后自己改了些代码,就没有成功过了,现在都不知道哪里出问题了,求教各位解答,TFT控制芯片是R61408
#include "stm32f30x.h"
#include "stm32f30x_rcc.h"
#include "stm32f30x_gpio.h"
static uint16_t fac_ms= 0;
static uint16_t fac_us= 0;
#define SET_CS GPIO_SetBits(GPIOC, GPIO_Pin_9);
#define SET_WR GPIO_SetBits(GPIOC, GPIO_Pin_8);
#define SET_RST GPIO_SetBits(GPIOE, GPIO_Pin_9);
#define SET_RS GPIO_SetBits(GPIOC, GPIO_Pin_12);
#define SET_RD GPIO_SetBits(GPIOC, GPIO_Pin_10);
#define SET_BL GPIO_SetBits(GPIOC, GPIO_Pin_2);
#define CLR_CS GPIO_ResetBits(GPIOC, GPIO_Pin_9);
#define CLR_WR GPIO_ResetBits(GPIOC, GPIO_Pin_8);
#define CLR_RST GPIO_ResetBits(GPIOE, GPIO_Pin_9);
#define CLR_RS GPIO_ResetBits(GPIOC, GPIO_Pin_12);
#define CLR_RD GPIO_ResetBits(GPIOC, GPIO_Pin_10);
#define CLR_BL GPIO_ResetBits(GPIOC, GPIO_Pin_2);
void GPIO_Configure(void) //GPIO初始化
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void LED_On(void) //点亮LED灯光
{
GPIO_SetBits(GPIOE, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
}
void LED_Off(void) //熄灭LED灯光
{
GPIO_ResetBits(GPIOE, GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
}
void delay_init(uint8_t SYSCLK)
{
SysTick->CTRL&=0xfffffffb;
fac_us=SYSCLK/8;
fac_ms=(uint16_t)fac_us*1000;
}
void delay_ms(uint16_t ms) /延时
{
SysTick->LOAD=(uint32_t)ms*fac_ms;
SysTick->CTRL|=0x01;
while(!(SysTick->CTRL&(1<<16)));
SysTick->CTRL&=0xfffffffe;
SysTick->VAL=0x0000;
}
void TFT_Write_com(uint16_t com) //写命令函数
{
SET_RD;
CLR_CS;
CLR_RS;
GPIOD->ODR = com;
CLR_WR;
SET_WR;
SET_CS;
}
void TFT_Write_dat(uint16_t dat) //写数据函数
{
SET_RD;
CLR_CS;
SET_RS;
GPIOD->ODR = dat;
CLR_WR;
SET_WR;
SET_CS;
}
void TFT_Light_On(void) //打开TFT背光
{
SET_BL;
}
void TFT_Configure(void) //TFT初始化
{
delay_ms(1000);
SET_RST;
delay_ms(200);
CLR_RST;
delay_ms(200);
SET_RST;
delay_ms(200);
TFT_Write_com(0x11);
delay_ms(100);
TFT_Write_com(0xB0);
TFT_Write_dat(0x04);
TFT_Write_com(0xB3);//Frame Memory Access and Interface Setting
TFT_Write_dat(0x02);
TFT_Write_dat(0x00);
TFT_Write_com(0xC1);//Panel Driving Setting
TFT_Write_dat(0x23);
TFT_Write_dat(0x31);//NL
TFT_Write_dat(0x99);
TFT_Write_dat(0x21);
TFT_Write_dat(0x20);
TFT_Write_dat(0x00);
TFT_Write_dat(0x10);//DIVI
TFT_Write_dat(0x28);//RTN
TFT_Write_dat(0x0C);//BP
TFT_Write_dat(0x0A);//FP
TFT_Write_dat(0x00);
TFT_Write_dat(0x00);
TFT_Write_dat(0x00);
TFT_Write_dat(0x21);
TFT_Write_dat(0x01);
TFT_Write_com(0xC2);//Display V-Timing Setting
TFT_Write_dat(0x00);
TFT_Write_dat(0x06);
TFT_Write_dat(0x06);
TFT_Write_dat(0x01);
TFT_Write_dat(0x03);
TFT_Write_dat(0x00);
TFT_Write_com(0xC8);//GAMMA
TFT_Write_dat(0x01);
TFT_Write_dat(0x0A);
TFT_Write_dat(0x12);
TFT_Write_dat(0x1C);
TFT_Write_dat(0x2B);
TFT_Write_dat(0x45);
TFT_Write_dat(0x3F);
TFT_Write_dat(0x29);
TFT_Write_dat(0x17);
TFT_Write_dat(0x13);
TFT_Write_dat(0x0F);
TFT_Write_dat(0x04);
TFT_Write_dat(0x01);
TFT_Write_dat(0x0A);
TFT_Write_dat(0x12);
TFT_Write_dat(0x1C);
TFT_Write_dat(0x2B);
TFT_Write_dat(0x45);
TFT_Write_dat(0x3F);
TFT_Write_dat(0x29);
TFT_Write_dat(0x17);
TFT_Write_dat(0x13);
TFT_Write_dat(0x0F);
TFT_Write_dat(0x04);
TFT_Write_com(0xC9);//GAMMA
TFT_Write_dat(0x01);
TFT_Write_dat(0x0A);
TFT_Write_dat(0x12);
TFT_Write_dat(0x1C);
TFT_Write_dat(0x2B);
TFT_Write_dat(0x45);
TFT_Write_dat(0x3F);
TFT_Write_dat(0x29);
TFT_Write_dat(0x17);
TFT_Write_dat(0x13);
TFT_Write_dat(0x0F);
TFT_Write_dat(0x04);
TFT_Write_dat(0x01);
TFT_Write_dat(0x0A);
TFT_Write_dat(0x12);
TFT_Write_dat(0x1C);
TFT_Write_dat(0x2B);
TFT_Write_dat(0x45);
TFT_Write_dat(0x3F);
TFT_Write_dat(0x29);
TFT_Write_dat(0x17);
TFT_Write_dat(0x13);
TFT_Write_dat(0x0F);
TFT_Write_dat(0x04);
TFT_Write_com(0xCA);//GAMMA
TFT_Write_dat(0x01);
TFT_Write_dat(0x0A);
TFT_Write_dat(0x12);
TFT_Write_dat(0x1C);
TFT_Write_dat(0x2B);
TFT_Write_dat(0x45);
TFT_Write_dat(0x3F);
TFT_Write_dat(0x29);
TFT_Write_dat(0x17);
TFT_Write_dat(0x13);
TFT_Write_dat(0x0F);
TFT_Write_dat(0x04);
TFT_Write_dat(0x01);
TFT_Write_dat(0x0A);
TFT_Write_dat(0x12);
TFT_Write_dat(0x1C);
TFT_Write_dat(0x2B);
TFT_Write_dat(0x45);
TFT_Write_dat(0x3F);
TFT_Write_dat(0x29);
TFT_Write_dat(0x17);
TFT_Write_dat(0x13);
TFT_Write_dat(0x0F);
TFT_Write_dat(0x04);
TFT_Write_com(0xD0);//Power Setting (Charge Pump Setting)
TFT_Write_dat(0x99);//DC
TFT_Write_dat(0x03);
TFT_Write_dat(0xCE);
TFT_Write_dat(0xA6);
TFT_Write_dat(0x00);//CP or SR
TFT_Write_dat(0x43);//VC3, VC2
TFT_Write_dat(0x20);
TFT_Write_dat(0x10);
TFT_Write_dat(0x01);
TFT_Write_dat(0x00);
TFT_Write_dat(0x01);
TFT_Write_dat(0x01);
TFT_Write_dat(0x00);
TFT_Write_dat(0x03);
TFT_Write_dat(0x01);
TFT_Write_dat(0x00);
TFT_Write_com(0xD3);//Power Setting for Internal Mode
TFT_Write_dat(0x33);//AP
TFT_Write_com(0xD5);//VPLVL/VNLVL Setting
TFT_Write_dat(0x2A);
TFT_Write_dat(0x2A);
TFT_Write_com(0xD6);//
TFT_Write_dat(0x01);//
TFT_Write_com(0xD6);//
TFT_Write_dat(0xA8);//
TFT_Write_com(0xDE);//VCOMDC Setting
TFT_Write_dat(0x01);
TFT_Write_dat(0x4F);
TFT_Write_com(0xE6);//VCOMDC Setting
TFT_Write_dat(0x4F);
TFT_Write_com(0xFA);//VDC_SEL Setting
TFT_Write_dat(0x03);
delay_ms(100);
TFT_Write_com(0x2A);
TFT_Write_dat(0x00);
TFT_Write_dat(0x00);
TFT_Write_dat(0x01);
TFT_Write_dat(0xDF);
TFT_Write_com(0x2B);
TFT_Write_dat(0x00);
TFT_Write_dat(0x00);
TFT_Write_dat(0x03);
TFT_Write_dat(0x1F);
TFT_Write_com(0x36);
TFT_Write_dat(0x60);
TFT_Write_com(0x3A);
TFT_Write_dat(0x77);
TFT_Write_com(0x29);
delay_ms(20);
TFT_Write_com(0x2C);
delay_ms(10);
//Lcd_ColorBox(0,0,480,800,Yellow);
TFT_Light_On();
}
void TFT_Write_Block(u16 Xstart, u16 Xend, u16 Ystart, u16 Yend)
{
TFT_Write_com(0x2a);
TFT_Write_dat(Xstart>>8);
TFT_Write_dat(Xstart&0xff);
TFT_Write_dat(Xend>>8);
TFT_Write_dat(Xend&0xff);
TFT_Write_com(0x2b);
TFT_Write_dat(Ystart>>8);
TFT_Write_dat(Ystart&0xff);
TFT_Write_dat(Yend>>8);
TFT_Write_dat(Yend&0xff);
TFT_Write_com(0x2c);
}
void TFT_Write_Color(void) //刷屏
{
u32 i;
TFT_Write_Block(0, 479, 0, 799);
CLR_CS;
SET_RS;
SET_RD;
//GPIOD->ODR = 0xffff;
for(i= 0; i< 480*800; i+=2)
{
GPIOD->ODR = 0x00ff; //根据R61408的datasheet,输入24bit的RGB数据顺序是第一个16bit输入RG,第二个16bit输入BR,第三个16bit输入GB,三次输入两个像素的RGB数据
CLR_WR;
SET_WR;
GPIOD->ODR = 0xff00;
CLR_WR;
SET_WR;
GPIOD->ODR = 0xffff;
CLR_WR;
SET_WR;
}
SET_CS;
}
int main(void)
{
SystemInit();
SystemCoreClockUpdate();
GPIO_Configure();
delay_init(72);
delay_ms(1000);
TFT_Configure();
TFT_Write_Color();
while(1)
{
//LED_On();
delay_ms(1000);
//LED_Off();
delay_ms(1000);
}
}
|