#include "lcd.h"
// TFTLCD 写指令
//-----------------------------------
void LCD_WR_Cmd(u16 cmd)
{
LCD->LCD_Cmd = cmd;
}
//-----------------------------------------------------------------------------------------------------------------
// TFTLCD 写数据
//-----------------------------------
void LCD_WR_Data(u16 data)
{
LCD->LCD_Data = data;
}
//-----------------------------------------------------------------------------------------------------------------
// 开始写 GRAM
//-----------------------------------
void LCD_WR_GRAM_Cmd(void)
{
LCD_WR_Cmd(0x2C);
}
//-----------------------------------------------------------------------------------------------------------------
// TFTLCD 读指令
//-----------------------------------
u16 LCD_RD_Cmd(void)
{
vu16 tmp;
tmp = LCD->LCD_Cmd ;
return tmp;
}
//-----------------------------------------------------------------------------------------------------------------
// TFTLCD 读数据
//-----------------------------------
u16 LCD_RD_Data(void)
{
vu16 tmp;
tmp = LCD->LCD_Data;
return tmp;
}
//-----------------------------------------------------------------------------------------------------------------
// 设置 TFTLCD 读写方向
//-----------------------------------
void Set_RW_Direction(u8 direction)
{
u8 tmp = 0;
switch(direction)
{
case L2R_U2D://从左到右,从上到下
tmp|=(0<<7)|(0<<6)|(0<<5);
break;
case L2R_D2U://从左到右,从下到上
tmp|=(1<<7)|(0<<6)|(0<<5);
break;
case R2L_U2D://从右到左,从上到下
tmp|=(0<<7)|(1<<6)|(0<<5);
break;
case R2L_D2U://从右到左,从下到上
tmp|=(1<<7)|(1<<6)|(0<<5);
break;
case U2D_L2R://从上到下,从左到右
tmp|=(0<<7)|(0<<6)|(1<<5);
break;
case U2D_R2L://从上到下,从右到左
tmp|=(0<<7)|(1<<6)|(1<<5);
break;
case D2U_L2R://从下到上,从左到右
tmp|=(1<<7)|(0<<6)|(1<<5);
break;
case D2U_R2L://从下到上,从右到左
tmp|=(1<<7)|(1<<6)|(1<<5);
break;
}
LCD_WR_Cmd(0x36);
LCD_WR_Data(tmp);
}
//-----------------------------------------------------------------------------------------------------------------
// 清屏函数(适用于 3.5寸屏)
// color:要清屏的填充色
//-----------------------------------------------------------------------------------------------------------------
void LCD_Clear(u16 color)
{
u32 index=0;
Open_Window(0,0,320,480);
LCD_WR_GRAM_Cmd();
for(index = 0; index<320*480; index++)
{
LCD_WR_Data(color);
}
}
//-----------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------
void LCD_DriveID_5310_Init()
{
u32 i;
// ID 为 5310 驱动的初始化序列
LCD_WR_Cmd(0xED);
LCD_WR_Data(0x01);
LCD_WR_Data(0xFE);
LCD_WR_Cmd(0xEE);
LCD_WR_Data(0xDE);
LCD_WR_Data(0x21);
LCD_WR_Cmd(0xF1);
LCD_WR_Data(0x01);
LCD_WR_Cmd(0xDF);
LCD_WR_Data(0x10);
//VCOMvoltage//
LCD_WR_Cmd(0xC4);
LCD_WR_Data(0x8F); //5f
LCD_WR_Cmd(0xC6);
LCD_WR_Data(0x00);
LCD_WR_Data(0xE2);
LCD_WR_Data(0xE2);
LCD_WR_Data(0xE2);
LCD_WR_Cmd(0xBF);
LCD_WR_Data(0xAA);
LCD_WR_Cmd(0xB0);
LCD_WR_Data(0x0D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x0D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x11);
LCD_WR_Data(0x00);
LCD_WR_Data(0x19);
LCD_WR_Data(0x00);
LCD_WR_Data(0x21);
LCD_WR_Data(0x00);
LCD_WR_Data(0x2D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x5D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x5D);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB1);
LCD_WR_Data(0x80);
LCD_WR_Data(0x00);
LCD_WR_Data(0x8B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x96);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB2);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x02);
LCD_WR_Data(0x00);
LCD_WR_Data(0x03);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB3);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB4);
LCD_WR_Data(0x8B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x96);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA1);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB5);
LCD_WR_Data(0x02);
LCD_WR_Data(0x00);
LCD_WR_Data(0x03);
LCD_WR_Data(0x00);
LCD_WR_Data(0x04);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB6);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB7);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3F);
LCD_WR_Data(0x00);
LCD_WR_Data(0x5E);
LCD_WR_Data(0x00);
LCD_WR_Data(0x64);
LCD_WR_Data(0x00);
LCD_WR_Data(0x8C);
LCD_WR_Data(0x00);
LCD_WR_Data(0xAC);
LCD_WR_Data(0x00);
LCD_WR_Data(0xDC);
LCD_WR_Data(0x00);
LCD_WR_Data(0x70);
LCD_WR_Data(0x00);
LCD_WR_Data(0x90);
LCD_WR_Data(0x00);
LCD_WR_Data(0xEB);
LCD_WR_Data(0x00);
LCD_WR_Data(0xDC);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xB8);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xBA);
LCD_WR_Data(0x24);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC1);
LCD_WR_Data(0x20);
LCD_WR_Data(0x00);
LCD_WR_Data(0x54);
LCD_WR_Data(0x00);
LCD_WR_Data(0xFF);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC2);
LCD_WR_Data(0x0A);
LCD_WR_Data(0x00);
LCD_WR_Data(0x04);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC3);
LCD_WR_Data(0x3C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3A);
LCD_WR_Data(0x00);
LCD_WR_Data(0x39);
LCD_WR_Data(0x00);
LCD_WR_Data(0x37);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x36);
LCD_WR_Data(0x00);
LCD_WR_Data(0x32);
LCD_WR_Data(0x00);
LCD_WR_Data(0x2F);
LCD_WR_Data(0x00);
LCD_WR_Data(0x2C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x29);
LCD_WR_Data(0x00);
LCD_WR_Data(0x26);
LCD_WR_Data(0x00);
LCD_WR_Data(0x24);
LCD_WR_Data(0x00);
LCD_WR_Data(0x24);
LCD_WR_Data(0x00);
LCD_WR_Data(0x23);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x36);
LCD_WR_Data(0x00);
LCD_WR_Data(0x32);
LCD_WR_Data(0x00);
LCD_WR_Data(0x2F);
LCD_WR_Data(0x00);
LCD_WR_Data(0x2C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x29);
LCD_WR_Data(0x00);
LCD_WR_Data(0x26);
LCD_WR_Data(0x00);
LCD_WR_Data(0x24);
LCD_WR_Data(0x00);
LCD_WR_Data(0x24);
LCD_WR_Data(0x00);
LCD_WR_Data(0x23);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC4);
LCD_WR_Data(0x62);
LCD_WR_Data(0x00);
LCD_WR_Data(0x05);
LCD_WR_Data(0x00);
LCD_WR_Data(0x84);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF0);
LCD_WR_Data(0x00);
LCD_WR_Data(0x18);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA4);
LCD_WR_Data(0x00);
LCD_WR_Data(0x18);
LCD_WR_Data(0x00);
LCD_WR_Data(0x50);
LCD_WR_Data(0x00);
LCD_WR_Data(0x0C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x17);
LCD_WR_Data(0x00);
LCD_WR_Data(0x95);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Data(0xE6);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC5);
LCD_WR_Data(0x32);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Data(0x65);
LCD_WR_Data(0x00);
LCD_WR_Data(0x76);
LCD_WR_Data(0x00);
LCD_WR_Data(0x88);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC6);
LCD_WR_Data(0x20);
LCD_WR_Data(0x00);
LCD_WR_Data(0x17);
LCD_WR_Data(0x00);
LCD_WR_Data(0x01);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC7);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC8);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xC9);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE0);
LCD_WR_Data(0x16);
LCD_WR_Data(0x00);
LCD_WR_Data(0x1C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x21);
LCD_WR_Data(0x00);
LCD_WR_Data(0x36);
LCD_WR_Data(0x00);
LCD_WR_Data(0x46);
LCD_WR_Data(0x00);
LCD_WR_Data(0x52);
LCD_WR_Data(0x00);
LCD_WR_Data(0x64);
LCD_WR_Data(0x00);
LCD_WR_Data(0x7A);
LCD_WR_Data(0x00);
LCD_WR_Data(0x8B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA8);
LCD_WR_Data(0x00);
LCD_WR_Data(0xB9);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC4);
LCD_WR_Data(0x00);
LCD_WR_Data(0xCA);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD2);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD9);
LCD_WR_Data(0x00);
LCD_WR_Data(0xE0);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE1);
LCD_WR_Data(0x16);
LCD_WR_Data(0x00);
LCD_WR_Data(0x1C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x22);
LCD_WR_Data(0x00);
LCD_WR_Data(0x36);
LCD_WR_Data(0x00);
LCD_WR_Data(0x45);
LCD_WR_Data(0x00);
LCD_WR_Data(0x52);
LCD_WR_Data(0x00);
LCD_WR_Data(0x64);
LCD_WR_Data(0x00);
LCD_WR_Data(0x7A);
LCD_WR_Data(0x00);
LCD_WR_Data(0x8B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA8);
LCD_WR_Data(0x00);
LCD_WR_Data(0xB9);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC4);
LCD_WR_Data(0x00);
LCD_WR_Data(0xCA);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD2);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD8);
LCD_WR_Data(0x00);
LCD_WR_Data(0xE0);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE2);
LCD_WR_Data(0x05);
LCD_WR_Data(0x00);
LCD_WR_Data(0x0B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x1B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x34);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Data(0x4F);
LCD_WR_Data(0x00);
LCD_WR_Data(0x61);
LCD_WR_Data(0x00);
LCD_WR_Data(0x79);
LCD_WR_Data(0x00);
LCD_WR_Data(0x88);
LCD_WR_Data(0x00);
LCD_WR_Data(0x97);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA6);
LCD_WR_Data(0x00);
LCD_WR_Data(0xB7);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC2);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC7);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD1);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD6);
LCD_WR_Data(0x00);
LCD_WR_Data(0xDD);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE3);
LCD_WR_Data(0x05);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA);
LCD_WR_Data(0x00);
LCD_WR_Data(0x1C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x33);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Data(0x50);
LCD_WR_Data(0x00);
LCD_WR_Data(0x62);
LCD_WR_Data(0x00);
LCD_WR_Data(0x78);
LCD_WR_Data(0x00);
LCD_WR_Data(0x88);
LCD_WR_Data(0x00);
LCD_WR_Data(0x97);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA6);
LCD_WR_Data(0x00);
LCD_WR_Data(0xB7);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC2);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC7);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD1);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD5);
LCD_WR_Data(0x00);
LCD_WR_Data(0xDD);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE4);
LCD_WR_Data(0x01);
LCD_WR_Data(0x00);
LCD_WR_Data(0x01);
LCD_WR_Data(0x00);
LCD_WR_Data(0x02);
LCD_WR_Data(0x00);
LCD_WR_Data(0x2A);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x4B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x5D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x74);
LCD_WR_Data(0x00);
LCD_WR_Data(0x84);
LCD_WR_Data(0x00);
LCD_WR_Data(0x93);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA2);
LCD_WR_Data(0x00);
LCD_WR_Data(0xB3);
LCD_WR_Data(0x00);
LCD_WR_Data(0xBE);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC4);
LCD_WR_Data(0x00);
LCD_WR_Data(0xCD);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD3);
LCD_WR_Data(0x00);
LCD_WR_Data(0xDD);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE5);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x02);
LCD_WR_Data(0x00);
LCD_WR_Data(0x29);
LCD_WR_Data(0x00);
LCD_WR_Data(0x3C);
LCD_WR_Data(0x00);
LCD_WR_Data(0x4B);
LCD_WR_Data(0x00);
LCD_WR_Data(0x5D);
LCD_WR_Data(0x00);
LCD_WR_Data(0x74);
LCD_WR_Data(0x00);
LCD_WR_Data(0x84);
LCD_WR_Data(0x00);
LCD_WR_Data(0x93);
LCD_WR_Data(0x00);
LCD_WR_Data(0xA2);
LCD_WR_Data(0x00);
LCD_WR_Data(0xB3);
LCD_WR_Data(0x00);
LCD_WR_Data(0xBE);
LCD_WR_Data(0x00);
LCD_WR_Data(0xC4);
LCD_WR_Data(0x00);
LCD_WR_Data(0xCD);
LCD_WR_Data(0x00);
LCD_WR_Data(0xD3);
LCD_WR_Data(0x00);
LCD_WR_Data(0xDC);
LCD_WR_Data(0x00);
LCD_WR_Data(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE6);
LCD_WR_Data(0x11);
LCD_WR_Data(0x00);
LCD_WR_Data(0x34);
LCD_WR_Data(0x00);
LCD_WR_Data(0x56);
LCD_WR_Data(0x00);
LCD_WR_Data(0x76);
LCD_WR_Data(0x00);
LCD_WR_Data(0x77);
LCD_WR_Data(0x00);
LCD_WR_Data(0x66);
LCD_WR_Data(0x00);
LCD_WR_Data(0x88);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0xBB);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0x66);
LCD_WR_Data(0x00);
LCD_WR_Data(0x55);
LCD_WR_Data(0x00);
LCD_WR_Data(0x55);
LCD_WR_Data(0x00);
LCD_WR_Data(0x45);
LCD_WR_Data(0x00);
LCD_WR_Data(0x43);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE7);
LCD_WR_Data(0x32);
LCD_WR_Data(0x00);
LCD_WR_Data(0x55);
LCD_WR_Data(0x00);
LCD_WR_Data(0x76);
LCD_WR_Data(0x00);
LCD_WR_Data(0x66);
LCD_WR_Data(0x00);
LCD_WR_Data(0x67);
LCD_WR_Data(0x00);
LCD_WR_Data(0x67);
LCD_WR_Data(0x00);
LCD_WR_Data(0x87);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0xBB);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0x77);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Data(0x56);
LCD_WR_Data(0x00);
LCD_WR_Data(0x23);
LCD_WR_Data(0x00);
LCD_WR_Data(0x33);
LCD_WR_Data(0x00);
LCD_WR_Data(0x45);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE8);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0x87);
LCD_WR_Data(0x00);
LCD_WR_Data(0x88);
LCD_WR_Data(0x00);
LCD_WR_Data(0x77);
LCD_WR_Data(0x00);
LCD_WR_Data(0x66);
LCD_WR_Data(0x00);
LCD_WR_Data(0x88);
LCD_WR_Data(0x00);
LCD_WR_Data(0xAA);
LCD_WR_Data(0x00);
LCD_WR_Data(0xBB);
LCD_WR_Data(0x00);
LCD_WR_Data(0x99);
LCD_WR_Data(0x00);
LCD_WR_Data(0x66);
LCD_WR_Data(0x00);
LCD_WR_Data(0x55);
LCD_WR_Data(0x00);
LCD_WR_Data(0x55);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Data(0x44);
LCD_WR_Data(0x00);
LCD_WR_Data(0x55);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xE9);
LCD_WR_Data(0xAA);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0x00);
LCD_WR_Data(0xAA);
LCD_WR_Cmd(0xCF);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xF0);
LCD_WR_Data(0x00);
LCD_WR_Data(0x50);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xF3);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0xF9);
LCD_WR_Data(0x06);
LCD_WR_Data(0x10);
LCD_WR_Data(0x29);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0x3A);
LCD_WR_Data(0x55); //66
LCD_WR_Cmd(0x11);
for(i=0; i<0xFFFFFFFF; i--);
LCD_WR_Cmd(0x29);
LCD_WR_Cmd(0x35);
LCD_WR_Data(0x00);
LCD_WR_Cmd(0x51);
LCD_WR_Data(0xFF);
LCD_WR_Cmd(0x53);
LCD_WR_Data(0x2C);
LCD_WR_Cmd(0x55);
LCD_WR_Data(0x82);
LCD_WR_Cmd(0x2c);
LCD_BL(ON);
LCD_Clear(WHITE);
Set_RW_Direction(L2R_U2D);
}
//-----------------------------------------------------------------------------------------------------------------
// 读液晶驱动 ID (基于 5310 驱动芯片)
//-----------------------------------
u16 RD_ID(void)
{
u16 tmp=0;
LCD_WR_Cmd(0XD4);
tmp=LCD_RD_Data(); //dummy read
tmp=LCD_RD_Data(); //读回0X01
tmp=LCD_RD_Data(); //读回0X53
tmp<<=8;
tmp|=LCD_RD_Data(); //这里读回0X10
// 加入此句可通过串口打印出驱动 ID
//printf(" LCD ID:%x\r\n",tmp); //打印LCD ID
return tmp;
}
//-----------------------------------------------------------------------------------------------------------------
// 开窗函数
//-----------------------------------------------------------------------------------------------------------------
void Open_Window(u16 Xpos, u16 Ypos, u16 Width, u16 Hight)
{
// 设置坐标
LCD_WR_Cmd(0x2A);
LCD_WR_Data(Xpos>>8);
LCD_WR_Data(Xpos&0xFF);
LCD_WR_Data( (Xpos+Width)>>8 );
LCD_WR_Data( (Xpos+Width)&0xFF );
LCD_WR_Cmd(0x2B);
LCD_WR_Data(Ypos>>8);
LCD_WR_Data(Ypos&0xFF);
LCD_WR_Data( (Ypos+Hight)>>8 );
LCD_WR_Data( (Ypos+Hight)&0xFF );
}
//-----------------------------------------------------------------------------------------------------------------
//设置光标位置
//Xpos:横坐标
//Ypos:纵坐标
//-----------------------------------------------------------------------------------------------------------------
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{
LCD_WR_Cmd(0X2A); // 设置x光标
LCD_WR_Data(Xpos>>8);
LCD_WR_Data(Xpos&0XFF);
LCD_WR_Cmd(0X2B); // 设置y光标
LCD_WR_Data(Ypos>>8);
LCD_WR_Data(Ypos&0XFF);
}
//-----------------------------------------------------------------------------------------------------------------
//画点
//x,y:坐标
//POINT_COLOR:此点的颜色
//-----------------------------------------------------------------------------------------------------------------
void LCD_DrawPoint(u16 x,u16 y,u16 color)
{
LCD_SetCursor(x,y); //设置光标位置
LCD_WR_GRAM_Cmd(); //开始写入GRAM
LCD_WR_Data(color);
}
//-----------------------------------------------------------------------------------------------------------------
//快速画点
//x,y:坐标
//color:颜色
void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color)
{
LCD_WR_Cmd(Set_X_Pos);
LCD_WR_Data(x>>8);LCD_WR_Data(x&0XFF);
LCD_WR_Cmd(Set_Y_Pos);
LCD_WR_Data(y>>8);LCD_WR_Data(y&0XFF);
LCD_WR_GRAM_Cmd();
LCD_WR_Data(color);
}
//当mdk -O1时间优化时需要设置
//延时i
void opt_delay(u8 i)
{
while(i--);
}
// 读点
// x,y:坐标点
//-----------------------------------------------------------------------------------------------------------------
u16 LCD_ReadPoint(u16 x,u16 y)
{
u16 r=0,g=0,b=0;
if(x>=LCD_WIDTH||y>=LCD_HIGHT)
return 0; //超过了范围,直接返回
LCD_SetCursor(x,y);
LCD_WR_Cmd(RD_GRAM);
opt_delay(2);
b=LCD_RD_Data();
g=r&0XFF; //对于9341/5310/5510,第一次读取的是RG的值,R在前,G在后,各占8位
g<<=8;
return (((r>>11)<<11)|((g>>10)<<5)|(b>>11));
}
//-----------------------------------------------------------------------------------------------------------------
// 在指定位置画一个指定大小的圆
// (x,y):中心点
// r :半径
//-----------------------------------------------------------------------------------------------------------------
void LCD_Draw_Circle(u16 x0,u16 y0,u8 r,u16 color)
{
int a,b;
int di;
a=0;b=r;
di=3-(r<<1); //判断下个点位置的标志
while(a<=b)
{
LCD_DrawPoint(x0+a,y0-b,color); //5
LCD_DrawPoint(x0+b,y0-a,color); //0
LCD_DrawPoint(x0+b,y0+a,color); //4
LCD_DrawPoint(x0+a,y0+b,color); //6
LCD_DrawPoint(x0-a,y0+b,color); //1
LCD_DrawPoint(x0-b,y0+a,color);
LCD_DrawPoint(x0-a,y0-b,color); //2
LCD_DrawPoint(x0-b,y0-a,color); //7
a++;
//使用Bresenham算法画圆
if(di<0)di +=4*a+6;
else
{
di+=10+4*(a-b);
b--;
}
}
}
//-----------------------------------------------------------------------------------------------------------------
// 画线
// x1,y1:起点坐标
// x2,y2:终点坐标
//-----------------------------------------------------------------------------------------------------------------
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2, u16 color)
{
u16 t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x=x2-x1; // 计算坐标增量
delta_y=y2-y1;
uRow=x1;
uCol=y1;
if(delta_x>0)incx=1; // 设置单步方向
else if(delta_x==0)incx=0; // 垂直线
else {incx=-1;delta_x=-delta_x;}
if(delta_y>0)incy=1;
else if(delta_y==0)incy=0; // 水平线
else{incy=-1;delta_y=-delta_y;}
if( delta_x>delta_y)distance=delta_x; // 选取基本增量坐标轴
else distance=delta_y;
for(t=0;t<=distance+1;t++ ) // 画线输出
{
LCD_DrawPoint(uRow,uCol,color); // 画点
xerr+=delta_x ;
yerr+=delta_y ;
if(xerr>distance)
{
xerr-=distance;
uRow+=incx;
}
if(yerr>distance)
{
yerr-=distance;
uCol+=incy;
}
}
}
//-----------------------------------------------------------------------------------------------------------------
// 画矩形
// (x1,y1),(x2,y2):矩形的对角坐标
//-----------------------------------------------------------------------------------------------------------------
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2, u16 color)
{
LCD_DrawLine(x1,y1,x2,y1,color);
LCD_DrawLine(x1,y1,x1,y2,color);
LCD_DrawLine(x1,y2,x2,y2,color);
LCD_DrawLine(x2,y1,x2,y2,color);
}
//-----------------------------------------------------------------------------------------------------------------
// 在指定区域内填充单个颜色
// (sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
// color:要填充的颜色
//-----------------------------------------------------------------------------------------------------------------
void LCD_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 color)
{
u16 i,j;
u16 xlen=0;
xlen=ex-sx+1;
for(i=sy;i<=ey;i++)
{
LCD_SetCursor(sx,i); // 设置光标位置
LCD_WR_GRAM_Cmd(); // 开始写入GRAM
for(j=0;j<xlen;j++)LCD_WR_Data(color); // 显示颜色
}
}
//-----------------------------------------------------------------------------------------------------------------
// 在指定区域内填充指定颜色块
// (sx,sy),(ex,ey):填充矩形对角坐标,区域大小为:(ex-sx+1)*(ey-sy+1)
// color:要填充的颜色
//-----------------------------------------------------------------------------------------------------------------
void LCD_Color_Fill(u16 sx,u16 sy,u16 ex,u16 ey,u16 *color)
{
u16 height,width;
u16 i,j;
width=ex-sx+1; // 得到填充的宽度
height=ey-sy+1; // 高度
for(i=0;i<height;i++)
{
LCD_SetCursor(sx,sy+i); // 设置光标位置
LCD_WR_GRAM_Cmd(); // 开始写入GRAM
for(j=0;j<width;j++)LCD_WR_Data(color[i*width+j]);// 写入数据
}
}
//-----------------------------------------------------------------------------------------------------------------
// 在指定位置显示一个字符
// x,y:起始坐标
// num:要显示的字符:" "--->"~"
// size:字体大小 12/16/24
// mode:叠加方式(1)还是非叠加方式(0)
//-----------------------------------------------------------------------------------------------------------------
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode)
{
u8 temp,t1,t;
u16 y0=y;
u8 csize=(size/8+((size%8)?1:0))*(size/2); // 得到字体一个字符对应点阵集所占的字节数
num=num-' '; // 得到偏移后的值(ASCII字库是从空格开始取模,所以-' '就是对应字符的字库)
for(t=0;t<csize;t++)
{
if(size==12)temp=asc2_1206[num][t]; // 调用1206字体
else if(size==16)temp=asc2_1608[num][t]; // 调用1608字体
else if(size==24)temp=asc2_2412[num][t]; // 调用2412字体
else return; // 没有的字库
for(t1=0;t1<8;t1++)
{
if(temp&0x80)LCD_Fast_DrawPoint(x,y,POINT_COLOR);
else if(mode==0)LCD_Fast_DrawPoint(x,y,BACK_COLOR);
temp<<=1;
y++;
if(y>=LCD_HIGHT)return; // 超区域了
if((y-y0)==size)
{
y=y0;
x++;
if(x>=LCD_WIDTH)return; // 超区域了
break;
}
}
}
}
//-----------------------------------------------------------------------------------------------------------------
//m^n函数
//返回值:m^n次方.
//-----------------------------------------------------------------------------------------------------------------
u32 LCD_Pow(u8 m,u8 n)
{
u32 result=1;
while(n--)result*=m;
return result;
}
//-----------------------------------------------------------------------------------------------------------------
//显示数字,高位为0,则不显示
//x,y :起点坐标
//len :数字的位数
//size:字体大小
//color:颜色
//num:数值(0~4294967295);
//-----------------------------------------------------------------------------------------------------------------
void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/LCD_Pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
LCD_ShowChar(x+(size/2)*t,y,' ',size,0);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,0);
}
}
//-----------------------------------------------------------------------------------------------------------------
//显示数字,高位为0,还是显示
//x,y:起点坐标
//num:数值(0~999999999);
//len:长度(即要显示的位数)
//size:字体大小
//mode:
//[7]:0,不填充;1,填充0.
//[6:1]:保留
//[0]:0,非叠加显示;1,叠加显示.
//-----------------------------------------------------------------------------------------------------------------
void LCD_ShowxNum(u16 x,u16 y,u32 num,u8 len,u8 size,u8 mode)
{
u8 t,temp;
u8 enshow=0;
for(t=0;t<len;t++)
{
temp=(num/LCD_Pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
if(mode&0X80)LCD_ShowChar(x+(size/2)*t,y,'0',size,mode&0X01);
else LCD_ShowChar(x+(size/2)*t,y,' ',size,mode&0X01);
continue;
}else enshow=1;
}
LCD_ShowChar(x+(size/2)*t,y,temp+'0',size,mode&0X01);
}
}
//-----------------------------------------------------------------------------------------------------------------
//显示字符串
//x,y:起点坐标
//width,height:区域大小
//size:字体大小
//*p:字符串起始地址
//-----------------------------------------------------------------------------------------------------------------
void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p)
{
u8 x0=x;
width+=x;
height+=y;
while((*p<='~')&&(*p>=' '))//判断是不是非法字符!
{
if(x>=width){x=x0;y+=size;}
if(y>=height)break;//退出
LCD_ShowChar(x,y,*p,size,0);
x+=size/2;
p++;
}
}
//-----------------------------------------------------------------------------------------------------------------