文档库

最新最全的文档下载
当前位置:文档库 > clcd_driver.h

clcd_driver.h


#ifndef CLCD_DRIVER_H
#define CLCD_DRIVER_H

#include "math.h"

//#define DATA P0

/*#define LCD_CS GpioDataRegs.GPBDAT.bit.GPIOB4
#define LCD_RS GpioDataRegs.GPBDAT.bit.GPIOB3
#define LCD_WR GpioDataRegs.GPBDAT.bit.GPIOB5
#define LCD_RD GpioDataRegs.GPBDAT.bit.GPIOB6
#define LCD_RST GpioDataRegs.GPBDAT.bit.GPIOB7

#define DATA0 GpioDataRegs.GPBDAT.bit.GPIOB8
#define DATA1 GpioDataRegs.GPBDAT.bit.GPIOB10
#define DATA2 GpioDataRegs.GPBDAT.bit.GPIOB14
#define DATA3 GpioDataRegs.GPBDAT.bit.GPIOB12
#define DATA4 GpioDataRegs.GPBDAT.bit.GPIOB11
#define DATA5 GpioDataRegs.GPBDAT.bit.GPIOB15
#define DATA6 GpioDataRegs.GPBDAT.bit.GPIOB13
#define DATA7 GpioDataRegs.GPBDAT.bit.GPIOB9
#define NC1 GpioDataRegs.GPBDAT.bit.GPIOB0
#define NC2 GpioDataRegs.GPBDAT.bit.GPIOB2 */

#define LCD_CS GpioDataRegs.GPADAT.bit.GPIOA0
#define LCD_RS GpioDataRegs.GPADAT.bit.GPIOA5
#define LCD_WR GpioDataRegs.GPADAT.bit.GPIOA7
#define LCD_RD GpioDataRegs.GPADAT.bit.GPIOA9
#define LCD_RST GpioDataRegs.GPADAT.bit.GPIOA2

#define DATA0 GpioDataRegs.GPADAT.bit.GPIOA11
#define DATA1 GpioDataRegs.GPADAT.bit.GPIOA14
#define DATA2 GpioDataRegs.GPADAT.bit.GPIOA13
#define DATA3 GpioDataRegs.GPADAT.bit.GPIOA12
#define DATA4 GpioDataRegs.GPADAT.bit.GPIOA10
#define DATA5 GpioDataRegs.GPADAT.bit.GPIOA8
#define DATA6 GpioDataRegs.GPADAT.bit.GPIOA6
#define DATA7 GpioDataRegs.GPADAT.bit.GPIOA4

#define NC1 GpioDataRegs.GPADAT.bit.GPIOA3
#define NC2 GpioDataRegs.GPADAT.bit.GPIOA15
#define NC3 GpioDataRegs.GPADAT.bit.GPIOA1

void delay(unsigned int);
void DATA_to_LCD(unsigned int);
void LCD_WRITE_CMD(unsigned char indexH,unsigned char indexL);
void LCD_WRITE_DATA(unsigned int DataH,unsigned int DataL);
void LCD_Init(void);
void LCD_SET_LOCATION(unsigned int x,unsigned int y);

void draw_point(unsigned int x,unsigned int y,unsigned int c);
void draw_rectangle(unsigned int x,unsigned int y,unsigned int w,unsigned int h, unsigned int c);
void draw_fill_rectangle(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned int c);
void draw_line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int c);
void draw_round(unsigned int x,unsigned int y,unsigned int r,unsigned int c);

extern unsigned int read_flash();

void delay(unsigned int t)
{
while(--t);
}

void DATA_to_LCD(unsigned int data)
{
DATA0=data%2;
data>>=1;

DATA1=data%2;
data>>=1;

DATA2=data%2;
data>>=1;

DATA3=data%2;
data>>=1;

DATA4=data%2;
data>>=1;

DATA5=data%2;
data>>=1;

DATA6=data%2;
data>>=1;

DATA7=data%2;
}


void LCD_WRITE_CMD(unsigned char indexH,unsigned char indexL) //写命令到TFT
{
LCD_CS = 0;
LCD_RS = 0;
LCD_RD = 1;
// delay(10);
DATA_to_LCD(indexH);
// delay(10);
LCD_WR = 0;
LCD_WR = 1;
// dela

y(10);
DATA_to_LCD(indexL);
// delay(10);
LCD_WR = 0;
LCD_WR = 1;
LCD_CS = 1;
LCD_RS = 1;
}

void LCD_WRITE_DATA(unsigned int DataH,unsigned int DataL) //写数据到TFT
{
LCD_CS = 0;
LCD_RS = 1;
LCD_RD = 1;

DATA_to_LCD(DataH);
// delay(10);
LCD_WR = 0;
LCD_WR = 1;
// delay(10);
DATA_to_LCD(DataL);
// delay(10);
LCD_WR = 0;
LCD_WR = 1;
LCD_CS = 1;
LCD_RS = 0;
}

void LCD_Init(void) //TFT初始化函数
{

NC1=0;
NC2=0;
NC3=0;


LCD_RST=1;
delay(20);
LCD_RST=0;

delay(60);

LCD_RST=1;
delay(60);
//------------------------------------Display Control Setting--------------------------------------//
LCD_WRITE_CMD(0x00,0x01);
LCD_WRITE_DATA(0x01,0x00); // Output Direct

LCD_WRITE_CMD(0x00,0x02);
LCD_WRITE_DATA(0x07,0x00); // Line Inversion

LCD_WRITE_CMD(0x00,0x03);
LCD_WRITE_DATA(0x10,0x30); // Entry Mode (65K, BGR)//0x10,0x30


LCD_WRITE_CMD(0x00,0x08);
LCD_WRITE_DATA(0x03,0x02); // Porch Setting

LCD_WRITE_CMD(0x00,0x09);
LCD_WRITE_DATA(0x00,0x00); // Scan Cycle

LCD_WRITE_CMD(0x00,0x0a);
LCD_WRITE_DATA(0x00,0x04); // FMARK off
//-----------------------------------End Display Control setting-----------------------------------------//
//-------------------------------- Power Control Registers Initial --------------------------------------//
LCD_WRITE_CMD(0x00,0x10);
LCD_WRITE_DATA(0x07,0x90); // Power Control1 07 90

LCD_WRITE_CMD(0x00,0x11);
LCD_WRITE_DATA(0x00,0x05); // Power Control2

LCD_WRITE_CMD(0x00,0x12);
LCD_WRITE_DATA(0x00,0x00); // Power Control3

LCD_WRITE_CMD(0x00,0x13);
LCD_WRITE_DATA(0x00,0x00); // Power Control4 00 04
//---------------------------------End Power Control Registers Initial -------------------------------//
delay(130);
//--------------------------------- Power Supply Startup 1 Setting------------------------------------//
LCD_WRITE_CMD(0x00,0x10);
LCD_WRITE_DATA(0x12,0xb0); // Power Control1 15 b0

delay(60);

LCD_WRITE_CMD(0x00,0x11);
LCD_WRITE_DATA(0x00,0x07); // Power Control2 00 06
delay(60);
//--------------------------------- End Power Supply Startup 1 Setting------------------------------//
LCD_WRITE_CMD(0x00,0x12);
LCD_WRITE_DATA(0x00,0x8c); // Power Control3 00 8c

LCD_WRITE_CMD(0x00,0x13);
LCD_WRITE_DATA(0x17,0x00); // Power Control4 1b 00

LCD_WRITE_CMD(0x00,0x29);
LCD_WRITE_DATA(0x00,0x22); // VCOMH setting 00 22
//--------------------------------- End Power Supply Startup 2 Setting------------------------------//
delay(60);
//-------------------------------------Gamma Cluster Setting-------------------------------------------//
LCD_WRITE_CMD(0x00,0x30);
LCD_WRITE_DATA(0x00,0x00);

LCD_WRITE_CMD(0x00,0x31);
LCD_WRITE_DATA(0x01,0x04);

LCD_WRITE_CMD(0x00,0x32);
LCD_WRITE_DATA(0x00,0x00);

LCD_WRITE_CMD(0x00,0x35);
LCD_WRITE_DATA(0x02,0x03);

LCD_WRITE_CMD(0

x00,0x36);
LCD_WRITE_DATA(0x04,0x05);

LCD_WRITE_CMD(0x00,0x37);
LCD_WRITE_DATA(0x00,0x00);

LCD_WRITE_CMD(0x00,0x38);
LCD_WRITE_DATA(0x02,0x03);

LCD_WRITE_CMD(0x00,0x39);
LCD_WRITE_DATA(0x00,0x00);

LCD_WRITE_CMD(0x00,0x3c);
LCD_WRITE_DATA(0x02,0x03);

LCD_WRITE_CMD(0x00,0x3d);
LCD_WRITE_DATA(0x04,0x05);

//---------------------------------------End Gamma Setting---------------------------------------------//
//----------------------------------Display Windows 240 X 320----------------------------------------//
LCD_WRITE_CMD(0x00,0x50);
LCD_WRITE_DATA(0x00,0x00); // Horizontal Address Start Position

LCD_WRITE_CMD(0x00,0x51);
LCD_WRITE_DATA(0x00,0xef); // Horizontal Address End Position

LCD_WRITE_CMD(0x00,0x52);
LCD_WRITE_DATA(0x00,0x00); // Vertical Address Start Position

LCD_WRITE_CMD(0x00,0x53);
LCD_WRITE_DATA(0x01,0x3f); // Vertical Address End Position
//----------------------------------End Display Windows 240 X 320----------------------------------//

LCD_WRITE_CMD(0x00,0x60);
LCD_WRITE_DATA(0xa7,0x00); // Gate scan control

LCD_WRITE_CMD(0x00,0x61);
LCD_WRITE_DATA(0x00,0x01); // Non-display Area setting

LCD_WRITE_CMD(0x00,0x90);
LCD_WRITE_DATA(0x00,0x33); // RTNI setting

LCD_WRITE_CMD(0x00,0x07);
LCD_WRITE_DATA(0x01,0x33); // Display Control1
delay(60);
}

void LCD_SET_LOCATION(unsigned int x,unsigned int y) //设置X、Y坐标,做好写RAM的准备
{
LCD_WRITE_CMD(0x00,0x20);
LCD_WRITE_DATA(0x00,y%256); //设置Y坐标位置

LCD_WRITE_CMD(0x00,0x21);
LCD_WRITE_DATA(x>>8,x%256); //设置X坐标位置
LCD_WRITE_CMD(0x00,0x22); //指向RAM寄存器,准备写数据到RAM
}


/*****************************************************************
*在指定的坐标点画指定颜色的点 注意到 x的范围为0~319 y的范围为0~239
******************************************************************/
void draw_point(unsigned int x,unsigned int y,unsigned int c)
{

LCD_SET_LOCATION(x,y);

LCD_WRITE_DATA(c>>8,c%256);
}

/***********************************************************************************************
**在指定的坐标点绘制指定大小(宽度 高度 )指定颜色的矩形框
************************************************************************************************/
void draw_rectangle(unsigned int x,unsigned int y,unsigned int w,unsigned int h, unsigned int c)
{
int i,j;

for(j=y;jdraw_point(x,j,c);//绘制左边框

for(i=x;i{
draw_point(i,y,c);
draw_point(i,y+h-1,c);
}

for(j=y;j
draw_point(x+w-1,j,c);

}

/**************************************************************************
*在指定的矩形区域内填充单色
**************************************************************************/
void draw_fill_rectangle(unsigned int x,unsigned int y,unsigned in

t w,unsigned int h,unsigned int c)
{
int i,j;

unsigned int cH=c>>8;
unsigned int cL=c%256;
for(i=0;i{
LCD_SET_LOCATION(x+i,y);
for(j=0;jLCD_WRITE_DATA(cH,cL);
}
}

/**********************************************************************
*用指定的颜色绘制两点之间的直线
**********************************************************************/
void draw_line(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2,unsigned int c)
{
float k;
unsigned int i;
unsigned int cH=c>>8;
unsigned int cL=c%256;
if(x1==x2)//若是垂直于x轴的直线
{
if(y1>y2)
{
LCD_SET_LOCATION(x2,y2);//以(x2,y2)为起点
for(i=0;i<=y1-y2;i++)
LCD_WRITE_DATA(cH,cL);
}
else
{
LCD_SET_LOCATION(x1,y1); //以(x1,y1)为起点
for(i=0;i<=y2-y1;i++)
LCD_WRITE_DATA(cH,cL);
}
}
else
{
k=(y1*1.0-y2*1.0)/(x1*1.0-x2*1.0); //计算斜率

if(x1{
for(i=0;i<=x2-x1;i++) //以(x1,y1)为起点
draw_point(x1+i,y1+k*1.0*i,c);
}

else
{
for(i=0;i<=x1-x2;i++) //以(x2,y2)为起点
draw_point(x2+i,y2+k*1.0*i,c);
}
}

}

/*****************************************************************
绘制圆
******************************************************************/
void draw_round(unsigned int x,unsigned int y,unsigned int r,unsigned int c)
{
unsigned int i,j;
for(i=0;i<=r;i++)
{
j=sqrt(r*r-i*i);
draw_point(x-i,y+j,c);
draw_point(x-i,y-j,c);

draw_point(x+i,y+j,c);
draw_point(x+i,y-j,c);
}

draw_point(x-r+1,y+1,c);
draw_point(x+r-1,y-1,c);

}

void draw_pic(unsigned int x,unsigned int y,unsigned char const *pic)
{
unsigned int i,j;
unsigned int cH;
unsigned int cL;
unsigned int xt=8;
unsigned long n;
unsigned int w;
unsigned int h;

w=pic[2];
w<<=8;
w+=pic[3];
h=pic[4];
h<<=8;
h+=pic[5];
n=h*2;

for(i=0;i{
LCD_SET_LOCATION(i+x,y);
xt+=n;
for(j=0;j{
cH=pic[xt+j];
cL=pic[xt+j+1];

LCD_WRITE_DATA(cH,cL);
}
}
}

#endif

TOP相关主题