📄 tft61505.c
字号:
void TFT_Init(void)
{
Lcd_Io_Init();
GPIO_SetBits(GPIOD,TFT_PWM);
GPIO_ResetBits(GPIOD,TFT_RES); //低电平复位
Lcd_Delay();
Lcd_Delay();
GPIO_SetBits(GPIOD,TFT_RES);
Lcd_Delay();
Lcd_Delay();
Lcd_Send_Command(0x00);
Lcd_Delay();
Lcd_Init();
Lcd_Clear();
// touch_Init();
/*for(i=0;i<240;i++)
{
Set_Ram_Addr(240,i);
Lcd_Send_Command(0x22);
Lcd_Send_Data(BLUE);
}*/
//Show_Mmp565(80, 80,142, 144, gImage_ccc);
Lcd_Put_Pixel(128,128,YELLOW);
//u8 str[41];
//for(u8 i=0;i<40;i++)
// str[i] = i %26 + 'A'; ;
// str[40]=0;
//Lcd_Show_String(0, 0, str, YELLOW, YELLOW, 0);
//Lcd_Show_String(0, 16, str, YELLOW, YELLOW, 0);
Lcd_Show_String(45, 110, "HuaZhong Normal University", RED, YELLOW, 1);
Lcd_Show_String(230, 220, "littleworm", YELLOW, YELLOW, 0);
//ClickCounter=0;
//SysTick_CounterCmd(SysTick_Counter_Enable);
//DispLine(0, 0,319, 239,YELLOW);
//DispLine(0, 239,319, 0,RED);
//SysTick_CounterCmd(SysTick_Counter_Disable);
//SysTick_CounterCmd(SysTick_Counter_Clear);
//ClickCounter=0;
//ClickCounter=0;
//SysTick_CounterCmd(SysTick_Counter_Enable);
//Lcd_Draw_Line(0, 0,319, 239,YELLOW);
//Lcd_Draw_Line(0, 239,319, 0,RED);
//SysTick_CounterCmd(SysTick_Counter_Disable);
//SysTick_CounterCmd(SysTick_Counter_Clear);
//ClickCounter=0;
//==============================
//Show_HZ24(40,0,wu);
//Show_HZ24(40+40,0,han);
//Show_HZ24(40+40*2,0,li);
//Show_HZ24(40+40*3,0,gong);
//Show_HZ24(40+40*4,0,da);
//Show_HZ24(40+40*5,0,xue);
}
//--------GPIO on TFT Init--------------
void Lcd_Io_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
//D0-D15
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/*
CS PD15
RS PD14
RW PD13
RD PD12
PWM PD11
RES PD10
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12 | GPIO_Pin_11 |GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits( GPIOD, TFT_CS | TFT_RS | TFT_RW | TFT_RD | TFT_PWM | TFT_RES );
/*
DOUT PD9
INT PD8
DIN PD7
BUSY PD6
DCLK PD5
TCS PD4
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits( GPIOD, TFT_TCS | TFT_DCLK | TFT_DIN );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void Lcd_Delay()
{
for (u16 i=0; i<0xffff; i++);
}
void Lcd_Send_Command(unsigned int out_data)
{
TFT_RS_SET(0);
GPIOE->ODR=out_data;
TFT_RW_SET(0);
TFT_CS_SET(0);
TFT_RW_SET(1);
TFT_CS_SET(1);
}
void Lcd_Send_Data(unsigned int out_data)
{
TFT_RS_SET(1);
TFT_CS_SET(0);
GPIOE->ODR=out_data;
TFT_RW_SET(0);
TFT_RW_SET(1);
TFT_CS_SET(1);
}
//=================================
/*
Display Type:4
BPP setting:3
USB Speed:2
Bus Mode:1
Seg:kuan
Com:320
interval:0000
*/
void Lcd_Init(void)
{
Lcd_Write_Com(0x00,0x0000);Lcd_Delay();
Lcd_Write_Com(0x07,0x0001);Lcd_Delay();//Display Control 1
Lcd_Write_Com(0x08,0x0405);Lcd_Delay();//Display Control 2 0808
Lcd_Write_Com(0x30,0x0707);Lcd_Delay();
Lcd_Write_Com(0x31,0x0407);Lcd_Delay();
Lcd_Write_Com(0x32,0x0203);Lcd_Delay();
Lcd_Write_Com(0x33,0x0303);Lcd_Delay();
Lcd_Write_Com(0x34,0x0303);Lcd_Delay();
Lcd_Write_Com(0x35,0x0202);Lcd_Delay();
Lcd_Write_Com(0x36,0x1007);Lcd_Delay();//0x1111
Lcd_Write_Com(0x37,0x0707);Lcd_Delay();//0x0606
Lcd_Write_Com(0x38,0x0407);Lcd_Delay();//0x0606
Lcd_Write_Com(0x39,0x0203);Lcd_Delay();//0x0606
Lcd_Write_Com(0x3a,0x0202);Lcd_Delay();
Lcd_Write_Com(0x3b,0x0303);Lcd_Delay();
Lcd_Write_Com(0x3c,0x0606);Lcd_Delay();
Lcd_Write_Com(0x3d,0x1313);Lcd_Delay();
Lcd_Write_Com(0x07,0x0101);Lcd_Delay();//Display Control 1
Lcd_Write_Com(0x17,0x0001);Lcd_Delay();//Power Control 5
Lcd_Write_Com(0x10,0x13b0);Lcd_Delay();//Power Control 1 0x08b0
Lcd_Write_Com(0x11,0x0007);Lcd_Delay();//Power Control 2 0007
Lcd_Write_Com(0x12,0x011e);Lcd_Delay();//Power Control 3
Lcd_Write_Com(0x13,0x0e00);Lcd_Delay();//Power Control 4 0x1400
Lcd_Write_Com(0x29,0x0004);Lcd_Delay();//VCOM High Voltage 0x0c
Lcd_Write_Com(0x2a,0x0000);Lcd_Delay();//VCOM High Voltage 0x0080
Lcd_Write_Com(0x12,0x01B8);Lcd_Delay();//Power Control 3 0x013e
Lcd_Write_Com(0x01,0x0000);Lcd_Delay();//Driver Output Control
Lcd_Write_Com(0x02,0x0300);Lcd_Delay();//LCD Driving Wave Control 0x0701
Lcd_Write_Com(0x03,0x1038);Lcd_Delay();//Entry Mode 0x1030
Lcd_Write_Com(0x04,0x0000);Lcd_Delay();//Resizing Control
Lcd_Write_Com(0x09,0x0028);Lcd_Delay();//Display Control 3 0x0028
Lcd_Write_Com(0x0c,0x0000);Lcd_Delay();//interface select
Lcd_Write_Com(0x50,0x0000);Lcd_Delay();//Window Horizontal RAM Address Start
Lcd_Write_Com(0x51,0x00ef);Lcd_Delay();//Window Horizontal RAM Address End
Lcd_Write_Com(0x52,0x0000);Lcd_Delay();//Window Vertical RAM Address Start
Lcd_Write_Com(0x53,0x013f);Lcd_Delay();//Window Vertical RAM Address End
Lcd_Write_Com(0x60,0x2700);Lcd_Delay();//Driver Output Control
Lcd_Write_Com(0x61,0x0001);Lcd_Delay();//Base Image Display Control
Lcd_Write_Com(0x90,0x0015);Lcd_Delay();//Panel interface control 1 0010
Lcd_Write_Com(0x92,0x0000);Lcd_Delay();//Panel interface control 2
Lcd_Write_Com(0x93,0x0000);Lcd_Delay();//Panel interface control 3
Lcd_Write_Com(0x20,0x00ef);Lcd_Delay();//RAM Address Set (Horizontal Address)
Lcd_Write_Com(0x21,0x013f);Lcd_Delay();//RAM Address Set (Vertical Address)
Lcd_Write_Com(0x07,0x0021);Lcd_Delay();//Display Control 1
Lcd_Write_Com(0x07,0x0061);Lcd_Delay();//Display Control 1
Lcd_Write_Com(0x07,0x0173);Lcd_Delay();//Display Control 1
Lcd_Write_Com(0x10,0x16b0);Lcd_Delay();//10bo 0x18b0
Lcd_Write_Com(0x20,0x0000);Lcd_Delay();
Lcd_Write_Com(0x21,0x0000);Lcd_Delay();
}
void Lcd_Write_Com(unsigned int address,unsigned int num)
{
Lcd_Send_Command(address);
Lcd_Send_Data(num);
}
void Show_Single_Color(unsigned int Color)
{
unsigned int i;
unsigned int j;
Lcd_Write_Com(0x0020,0); //行首址0
Lcd_Write_Com(0x0021,0); //列首址0
Lcd_Send_Command(0x22);
//GPIO_SetBits(GPIOD,RS);
for(j=0;j<chang;j++)
for(i=0;i<kuan;i++)
Lcd_Send_Data(Color);
}
void Lcd_Clear(void)
{
Show_Single_Color(BLACK);
}
void Set_Ram_Addr(unsigned int x,unsigned int y)
{
Lcd_Write_Com(0x0020,y); //行首址
Lcd_Write_Com(0x0021,x); //列首址
}
void Show_Single_Ascii(unsigned int x, unsigned int y, unsigned char *pAscii, unsigned int LineColor,unsigned int FillColor, unsigned char Mod)
{
unsigned char i, j;
unsigned char str;
unsigned int OffSet;
//OffSet = (*pAscii - 32)*16;
OffSet = ((*pAscii - 32)<<4);
for (i=0;i<16;i++)
{
Set_Ram_Addr(x,y+i);
Lcd_Send_Command(0x22);
str = *(AsciiLib + OffSet + i);
for (j=0;j<8;j++)
{
if ( str & (0x80>>j) ) //0x80>>j
{
Lcd_Send_Data((unsigned int)(LineColor&0xffff));
}
else
{
if (Mod)
Lcd_Send_Data((unsigned int)(FillColor&0xffff));
else
{
Set_Ram_Addr(x+j+1,y+i);
Lcd_Send_Command(0x22);
}
}
}
}
}
/**************************************************************************************
* 名 称: Lcd_Show_String
* 功 能: 在指定的位置显示多个字符
* 参 数: x : x坐标
* y : y坐标
* LineColor : 字符的颜色
* FillColor : 字符背景颜色
* 返 回 值: 无
*
* 修改历史:
* 版本 日期 作者 改动内容和原因
* ----------------------------------------------------
* 1.0 2007.6.13 lcf 基本的功能完成
**************************************************************************************/
void Lcd_Show_String(unsigned int x, unsigned int y, unsigned char *pStr, unsigned int LineColor,unsigned int FillColor, unsigned char Mod)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -