#include "LCD2.h"
void LCD2_GPIO_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //¿úÏß·-×aËù¶èÎa50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
//8λêy¾Yêä3ö
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //¿úÏß·-×aËù¶èÎa50MHz
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
//////////////////////////////////////////////////////////////////
//×îμ×2ãêy¾Y′«êäoˉêy
//////////////////////////////////////////////////////////////////
//D′Ãüáî
void Write_Cmd(unsigned char DH,unsigned char DL)
{
LCD2_CS=0;
LCD2_RS=0;
DataPort=DH;
LCD2_RW=0;
LCD2_RW=1;
DataPort=DL;
LCD2_RW=0;
LCD2_RW=1;
LCD2_CS=1;
}
//D′êy¾Y Ë«8λ
void Write_Data(unsigned char DH,unsigned char DL)
{
LCD2_CS=0;
LCD2_RS=1;
DataPort=DH;
LCD2_RW=0;
LCD2_RW=1;
DataPort=DL;
LCD2_RW=0;
LCD2_RW=1;
LCD2_CS=1;
}
//D′êy¾Y Ë«8λ
void Write_Data2(unsigned char DH,unsigned char DL)
{
DataPort=DH;
LCD2_RW=0;
LCD2_RW=1;
DataPort=DL;
LCD2_RW=0;
LCD2_RW=1;
}
//////////////////////////////////////////////////////////////////
//μ÷óÃéÏÃæ×îμ×2ãêμÏÖéÔ¸ß2ãD′Ãüáîoíêy¾Yoˉêy
//////////////////////////////////////////////////////////////////
/*----------------------------------------------------------------
D′Ãüáî¡¢D′êy¾Y
êäèë2Îêy£ox DèòaêäèëμÄÃüáî 16λ
y DèòaêäèëμÄêy¾Y 16λ
----------------------------------------------------------------*/
void Write_Cmd_Data (unsigned char x,unsigned int y)
{
unsigned char m,n;
m=y>>8;
n=y;
Write_Cmd(0x00,x);
Write_Data(m,n);
}
/*----------------------------------------------------------------
D′16λêy¾Y
----------------------------------------------------------------*/
void Write_Data_U16(unsigned int y)
{
// unsigned char m,n;
// m=y>>8;
// n=y;
// Write_Data2(m,n);
DataPort=y>>8;
LCD2_RW=0;
LCD2_RW=1;
DataPort=y;
LCD2_RW=0;
LCD2_RW=1;
}
/*----------------------------------------------------------------
òo¾§3õê¼»ˉ
----------------------------------------------------------------*/
void LCD2_Init(void)
{
LCD2_CS=1;
DELAY_MS(5);
LCD2_RES=0;
DELAY_MS(5);
LCD2_RES=1;
DELAY_MS(50);
Write_Cmd_Data(0x0001,0x0100);
Write_Cmd_Data(0x0002,0x0700);
Write_Cmd_Data(0x0003,0x1030);
Write_Cmd_Data(0x0004,0x0000);
Write_Cmd_Data(0x0008,0x0207);
Write_Cmd_Data(0x0009,0x0000);
Write_Cmd_Data(0x000A,0x0000);
Write_Cmd_Data(0x000C,0x0000);
Write_Cmd_Data(0x000D,0x0000);
Write_Cmd_Data(0x000F,0x0000);
//power on sequence VGHVGL
Write_Cmd_Data(0x0010,0x0000);
Write_Cmd_Data(0x0011,0x0007);
Write_Cmd_Data(0x0012,0x0000);
Write_Cmd_Data(0x0013,0x0000);
//vgh
Write_Cmd_Data(0x0010,0x1290);
Write_Cmd_Data(0x0011,0x0227);
//DELAY_MS(100);
//vregiout
Write_Cmd_Data(0x0012,0x001d); //0x001b
//DELAY_MS(100);
//vom amplitude
Write_Cmd_Data(0x0013,0x1500);
//DELAY_MS(100);
//vom H
Write_Cmd_Data(0x0029,0x0018);
Write_Cmd_Data(0x002B,0x000D);
//gamma
Write_Cmd_Data(0x0030,0x0004);
Write_Cmd_Data(0x0031,0x0307);
Write_Cmd_Data(0x0032,0x0002);// 0006
Write_Cmd_Data(0x0035,0x0206);
Write_Cmd_Data(0x0036,0x0408);
Write_Cmd_Data(0x0037,0x0507);
Write_Cmd_Data(0x0038,0x0204);//0200
Write_Cmd_Data(0x0039,0x0707);
Write_Cmd_Data(0x003C,0x0405);// 0504
Write_Cmd_Data(0x003D,0x0F02);
//ram
Write_Cmd_Data(0x0050,0x0000);
Write_Cmd_Data(0x0051,0x00EF);
Write_Cmd_Data(0x0052,0x0000);
Write_Cmd_Data(0x0053,0x013F);
Write_Cmd_Data(0x0060,0xA700);
Write_Cmd_Data(0x0061,0x0001);
Write_Cmd_Data(0x006A,0x0000);
//
Write_Cmd_Data(0x0080,0x0000);
Write_Cmd_Data(0x0081,0x0000);
Write_Cmd_Data(0x0082,0x0000);
Write_Cmd_Data(0x0083,0x0000);
Write_Cmd_Data(0x0084,0x0000);
Write_Cmd_Data(0x0085,0x0000);
//
Write_Cmd_Data(0x0090,0x0010);
Write_Cmd_Data(0x0092,0x0600);
Write_Cmd_Data(0x0093,0x0003);
Write_Cmd_Data(0x0095,0x0110);
Write_Cmd_Data(0x0097,0x0000);
Write_Cmd_Data(0x0098,0x0000);
Write_Cmd_Data(0x0007,0x0133);
// Write_Cmd_Data(0x0022);//
}
/*----------------------------------------------------------------
éèÖÃ×ø±ê
----------------------------------------------------------------*/
/*----------------------------------------------------------------
諾ֱäá¿
----------------------------------------------------------------*/
#define WINDOW_XADDR_START 0x0050 // Horizontal Start Address Set
#define WINDOW_XADDR_END 0x0051 // Horizontal End Address Set
#define WINDOW_YADDR_START 0x0052 // Vertical Start Address Set
#define WINDOW_YADDR_END 0x0053 // Vertical End Address Set
#define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set
#define GRAM_YADDR 0x0021 // GRAM Vertical Address Set
#define GRAMWR 0x0022 // memory write
void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1)
{
Write_Cmd_Data(WINDOW_XADDR_START,x0);
Write_Cmd_Data(WINDOW_XADDR_END,x1);
Write_Cmd_Data(WINDOW_YADDR_START,y0);
Write_Cmd_Data(WINDOW_YADDR_END,y1);
Write_Cmd_Data(GRAM_XADDR,x0);
Write_Cmd_Data(GRAM_YADDR,y0);
Write_Cmd (0x00,0x22);//LCD_WriteCMD(GRAMWR);
}
/*----------------------------------------------------------------
ÏÔê¾RGBÑÕé«
êäèë2Îêy£ox0£¬y0 Æeê¼×ø±ê
x1£¬y1 ½áêø×ø±ê
Color ±3¾°ÑÕé«
----------------------------------------------------------------*/
void Show_RGB (unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1,unsigned int Color)
{
unsigned int i,j,k=0;
char color1=Color>>8;
char color2=Color;
LCD_SetPos(x0,x1,y0,y1);
LCD2_CS=0;
LCD2_RS=1;
// for (i=y0;i<=y1;i++)
// {
// for (j=x0;j<=x1;j++)
// Write_Data_U16(Color);
// }
k=(y1-y0+1)*(x1-x0+1);
for (i=0;i<=k;i+=32)
{
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
// Write_Data_U16(Color);
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
/////////////////////////////
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
///////////////////////////////
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
/////////////////////////////
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
LCD2_RW=0;
DataPort=color1;
LCD2_RW=1;
LCD2_RW=0;
DataPort=Color;
LCD2_RW=1;
}
LCD2_CS=1;
}
void Delay_ms(u16 time)
{
u16 i=0;
while(time--)
{
i=12000;
while(i--);
}
}
|