- IC型号
企业档案
- 相关证件: 
- 会员类型:
- 会员年限:12年
- 阿库IM:
- 地址:杭州市余杭区仁和街道永泰路2号22幢
- E-mail:752574498@qq.com
3.5寸彩屏测试程序
发布时间: 2016/10/31 10:20:18 | 981 次阅读
//杭州佳显科技有限公司液晶驱动例程
//型号:HGF035-320*240
#include <absacc.h>
//#include "delay.h"
//#include "Pictures.h"
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit rs=P3^0;
sbit cs=P3^4;
sbit wr=P3^1;
sbit rd=P3^3;
sbit INT=P3^6;
sbit LCD_RST =P3^5; //L有效
#define DATA_BUS P0
unsigned int X1,Y1,X2,Y2,X3,Y3,X4,Y4;
uchar taby[4];
uchar tabx[4];
uint x[6],y[6],xmin,ymin,xmax,ymax;
//#define uchar unsigned char
//#define uint unsigned int
//#define ulong unsigned long
#define color_brown 0x40c0
#define color_black 0x0000
#define color_white 0xffff
#define color_red 0xf800
#define color_green 0x07e0
#define color_blue 0x001f
#define color_yellow color_red|color_green
#define color_cyan color_green|color_blue
#define color_purple color_red|color_blue
/** 延时子程序**/
void Delay1ms(uint t) //12M晶振大约延时1ms
{uint i,j;
for(i=0;i<t;i++)
for(j=0;j<109*2;j++)
_nop_();
}
void LCD_CmdWrite(unsigned char Cmd)
{
rd = 1;
cs = 0;
rs = 1;
DATA_BUS = Cmd;
wr = 0;
wr = 1;
cs= 1;
DATA_BUS = 0xff;
rs = 0;
/*
//6800模式
cs =0; // chip enable.
wr = 0; //
rs = 1; // rs = 0;
DATA_BUS = Cmd;
rd = 1; //
;
;
rd = 0; //
cs =1; // chip disable.
*/
}
void LCD_DataWrite(unsigned char Data)
{
rd = 1;
cs = 0;
rs = 0;
DATA_BUS = Data;
wr = 0;
wr = 1;
cs = 1;
DATA_BUS = 0xff;
rs = 1;
/*
//6800模式
cs =0; // chip enable.
wr = 0; //
rs = 1; // rs = 0;
DATA_BUS = Data;
rd = 0; //
;
;
rd = 0; //
cs =1; // chip disable
*/
}
//***********************写指令
void Write_Dir(uchar Cmd,uchar Data)
{
LCD_CmdWrite(Cmd);
LCD_DataWrite(Data);
}
//***********************读状态
uchar LCD_StatusRead(void)
{
uchar Data;
cs = 0;
rs= 1;
wr = 1;
rd = 0;
Data = DATA_BUS;
rd = 1;
cs= 1;
DATA_BUS = 0xff;
rs = 0;
return Data;
/*
//6800模式
uchar reg_rddata;
DATA_BUS = 0xff;
cs =0; // chip enable.
wr = 1; //
rs = 1; //
rd = 1; // rd = 0;
reg_rddata = DATA_BUS;
;
;
rd = 0; // rd = 1;
cs =1; // chip disable.
return(reg_rddata);
*/
}
//***********************读数据
uchar LCD_DataRead(void)
{
uchar Data;
wr = 1;
cs = 0;
rs = 0;
rd = 0;
Data = DATA_BUS;
rd = 1;
cs = 1;
rs = 1;
return Data;
/*
//6800模式
uchar reg_rddata;
DATA_BUS = 0xff;
cs =0; // chip enable.
wr = 1; //
rs = 0; //
rd = 1; // rd = 0;
reg_rddata = DATA_BUS;
;
;
rd = 0; // rd = 1;
cs =1; // chip disable.
return(reg_rddata);
*/
}
//*********LCD复位
void LCD_Reset(void)
{
LCD_RST = 0;
Delay1ms(10);
LCD_RST = 1;
Delay1ms(10);
}
//*********测忙函数组(status register)
/*D7:Memory Read/Write Busy (Include Font Write Busy) 0 : No Memory Read/Write event. 1 : Memory Read/Write busy.
D6: BTE Busy 0 : BTE is done or idle. 1 : BTE is busy.
D5:Touch Panel Event Detected 0 : Touch Panel is not touched. 1 : Touch Panel is touched.
D4:Sleep Mode Status 0: RA8875 in Normal mode. 1: RA8875 in Sleep mode.
D3~D1:NC
D0:Serial Flash/ROM Busy Serial Flash/ROM busy status at Direct Access Mode
*/
void Chk_Busy(void)
{
uchar temp;
do
{
temp=LCD_StatusRead();
}while((temp&0x80)==0x80);
}
void Chk_BTE_Busy(void)
{
uchar temp;
do
{
temp=LCD_StatusRead();
}while((temp&0x40)==0x40);
}
void Chk_DMA_Busy(void)
{
uchar temp;
do
{
LCD_CmdWrite(0xBF);
temp =LCD_DataRead();
}while((temp&0x01)==0x01);
}
//********倍频设置
void PLL_ini(void)
{
LCD_CmdWrite(0x88);
LCD_DataWrite(0x0a);
Delay1ms(1);
LCD_CmdWrite(0x89);
LCD_DataWrite(0x02);
Delay1ms(1);
}
//********液晶初始化
void LCD_Initial(void)
{
PLL_ini();
LCD_CmdWrite(0x10); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface
LCD_DataWrite(0x0c); // 1x 64k color 1x 16bit
LCD_CmdWrite(0x04); //PCLK
LCD_DataWrite(0x03); //11b: PCLK period = 8 times of System Clock period.
Delay1ms(10);
//Horizontal set
LCD_CmdWrite(0x14); //HDWR//Horizontal Display Width Setting Bit[6:0] (320/8-1)
LCD_DataWrite(0x27); //Horizontal display width(pixels) = (HDWR + 1)*8 0x3b
LCD_CmdWrite(0x15); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
LCD_DataWrite(0x02); //(HNDR + 1)*8 +HNDFCR 0x00~0x07
LCD_CmdWrite(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x03); //Horizontal Non-Display Period (pixels) = (HNDR + 1)*8+HNDFTR 0x00~0x1f
LCD_CmdWrite(0x17); //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x01); //HSYNC Start Position(pixels) = (HSTR + 1)*8
LCD_CmdWrite(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x03); //HSYNC Width [4:0] HSYNC Pulse width(pixels) = (HPWR + 1)*8
//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0xef); //Vertical pixels = VDHR + 1 0xef
LCD_CmdWrite(0x1a); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x00); //Vertical pixels = VDHR + 1 0x00
LCD_CmdWrite(0x1b); //VNDR0 //Vertical Non-Display Period Bit [7:0]
LCD_DataWrite(0x0F); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1c); //VNDR1 //Vertical Non-Display Period Bit [8]
LCD_DataWrite(0x00); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1d); //VSTR0 //VSYNC Start Position[7:0]
LCD_DataWrite(0x0e); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1e); //VSTR1 //VSYNC Start Position[8]
LCD_DataWrite(0x00); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1f); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
LCD_DataWrite(0x01); //VSYNC Pulse Width(PCLK) = (VPWR + 1)
//LCD_CmdWrite(0x04); //PCLK
//LCD_DataWrite(0x01); //
}
//********设置工作窗口区域
void Active_Window(uint XL,uint XR ,uint YT ,uint YB)
{
uchar temp;
//setting active window X
temp=XL;
LCD_CmdWrite(0x30);//HSAW0
LCD_DataWrite(temp);
temp=XL>>8;
LCD_CmdWrite(0x31);//HSAW1
LCD_DataWrite(temp);
temp=XR;
LCD_CmdWrite(0x34);//HEAW0
LCD_DataWrite(temp);
temp=XR>>8;
LCD_CmdWrite(0x35);//HEAW1
LCD_DataWrite(temp);
//setting active window Y
temp=YT;
LCD_CmdWrite(0x32);//VSAW0
LCD_DataWrite(temp);
temp=YT>>8;
LCD_CmdWrite(0x33);//VSAW1
LCD_DataWrite(temp);
temp=YB;
LCD_CmdWrite(0x36);//VEAW0
LCD_DataWrite(temp);
temp=YB>>8;
LCD_CmdWrite(0x37);//VEAW1
LCD_DataWrite(temp);
}
//********BTE背景颜色设置
void Text_Background_Color1(uint b_color)
{
LCD_CmdWrite(0x60);//BGCR0
LCD_DataWrite((uchar)(b_color>>11));
LCD_CmdWrite(0x61);//BGCR0
LCD_DataWrite((uchar)(b_color>>5));
LCD_CmdWrite(0x62);//BGCR0
LCD_DataWrite((uchar)(b_color));
}
//********BTE背景颜色设置2
void Text_Background_Color(uchar setR, setG, setB)
{
LCD_CmdWrite(0x60);//BGCR0
LCD_DataWrite(setR);
LCD_CmdWrite(0x61);//BGCR0
LCD_DataWrite(setG);
LCD_CmdWrite(0x62);//BGCR0
LCD_DataWrite(setB);
}
//********BTE前景颜色设置
void Text_Foreground_Color1(uint b_color)
{
LCD_CmdWrite(0x63);//BGCR0
LCD_DataWrite((uchar)(b_color>>11));
LCD_CmdWrite(0x64);//BGCR0
LCD_DataWrite((uchar)(b_color>>5));
LCD_CmdWrite(0x65);//BGCR0
LCD_DataWrite((uchar)(b_color));
}
//********BT前景颜色设置2
void Text_Foreground_Color(uchar setR,setG,setB)
{
LCD_CmdWrite(0x63);//BGCR0
LCD_DataWrite(setR);
LCD_CmdWrite(0x64);//BGCR0
LCD_DataWrite(setG);
LCD_CmdWrite(0x65);//BGCR0·
LCD_DataWrite(setB);
}
//***********************BTE区域大小设置
void BTE_Size(width,height)
{
uchar temp;
temp=width;
LCD_CmdWrite(0x5c);//BET读写区域宽度
LCD_DataWrite(temp);
temp=width>>8;
LCD_CmdWrite(0x5d);//BET读写区域宽度
LCD_DataWrite(temp);
temp=height;
LCD_CmdWrite(0x5e);//BET读写区域高度
LCD_DataWrite(temp);
temp=height>>8;
LCD_CmdWrite(0x5f);//BET读写区域高度
LCD_DataWrite(temp);
}
//***********************BTE起始位置设置
void BTE_Source(uint SX,uint DX ,uint SY ,uint DY)
{
uchar temp,temp1;
temp=SX;
LCD_CmdWrite(0x54);//BTE读取数据水平位置
LCD_DataWrite(temp);
temp=SX>>8;
LCD_CmdWrite(0x55);//BET读取数据水平位置
LCD_DataWrite(temp);
temp=DX;
LCD_CmdWrite(0x58);//BET写入目标水平位置
LCD_DataWrite(temp);
temp=DX>>8;
LCD_CmdWrite(0x59);//BET写入目标水平位置
LCD_DataWrite(temp);
temp=SY;
LCD_CmdWrite(0x56);//BTE读取数据垂直位置
LCD_DataWrite(temp);
temp=SY>>8;
LCD_CmdWrite(0x57);
temp1 = LCD_DataRead();
temp1 &= 0x80;
temp=temp|temp1;
LCD_CmdWrite(0x57);//BTE读取数据垂直位置
LCD_DataWrite(temp);
temp=DY;
LCD_CmdWrite(0x5a);//BTE写入数据垂直位置
LCD_DataWrite(temp);
temp=DY>>8;
LCD_CmdWrite(0x5b);
temp1 = LCD_DataRead();
temp1 &= 0x80;
temp=temp|temp1;
LCD_CmdWrite(0x5b);//BTE写入数据垂直位置
LCD_DataWrite(temp);
}
//********内存写入位置
void MemoryWrite_Position(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x46);
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x47);
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x48);
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x49);
LCD_DataWrite(temp);
}
//********文字写入位置
void FontWrite_Position(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x2A);
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x2B);
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x2C);
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x2D);
LCD_DataWrite(temp);
}
//****************输入字符
void String(uchar *str)
{
Write_Dir(0x40,0x80);//设置字符模式
LCD_CmdWrite(0x02);
while(*str != '\0')
{
LCD_DataWrite(*str);
++str;
Chk_Busy();
}
}
//****************输入256色16*16图片
void show_pic(void)
{
uint i;
Write_Dir(0x40,0x00);//设置字符模式 MWCR0,1:文本0:绘图
LCD_CmdWrite(0x02);//MRWC
for(i=0;i<512;i++)
{
// LCD_DataWrite(pic[i]);
Chk_Busy();
}
}
//****************光标显示位置
void Cursor_Position(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x80);//GCHP0
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x81);//GCHP1
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x82);//GCVP0
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x83);//GCVP1
LCD_DataWrite(temp);
}
//****************卷动窗口大小
void Scroll_Window(uint XL,uint XR ,uint YT ,uint YB)
{
uchar temp;
temp=XL;
LCD_CmdWrite(0x38);//HSSW0
LCD_DataWrite(temp);
temp=XL>>8;
LCD_CmdWrite(0x39);//HSSW1
LCD_DataWrite(temp);
temp=XR;
LCD_CmdWrite(0x3c);//HESW0
LCD_DataWrite(temp);
temp=XR>>8;
LCD_CmdWrite(0x3d);//HESW1
LCD_DataWrite(temp);
temp=YT;
LCD_CmdWrite(0x3a);//VSSW0
LCD_DataWrite(temp);
temp=YT>>8;
LCD_CmdWrite(0x3b);//VSSW1
LCD_DataWrite(temp);
temp=YB;
LCD_CmdWrite(0x3e);//VESW0
LCD_DataWrite(temp);
temp=YB>>8;
LCD_CmdWrite(0x3f);//VESW1
LCD_DataWrite(temp);
}
//****************窗口卷动偏移量设置
void Scroll(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x24);//HOFS0
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x25);//HOFS1
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x26);//VOFS0
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x27);//VOFS1
LCD_DataWrite(temp);
}
void main(void)
{
uint i;
Delay1ms(100);
LCD_Reset();
LCD_Initial();
Write_Dir(0X01,0X80);//开启显示
Active_Window(0,319,0,239);//设置工作窗口大小
while(1)
{
Text_Foreground_Color1(color_white);//前景颜色设定
Text_Background_Color1(color_blue);//背景颜色设定
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
//********PWM背光控制测试********
LCD_CmdWrite(0x8a);//PWM控制设置
LCD_DataWrite(0x81);//开启PWM
Write_Dir(0x8b,0x00);//背光亮度调节
Delay1ms(1000);
Write_Dir(0x8b,0x4F);//背光亮度调节
Delay1ms(1000);
Write_Dir(0x8b,0x8F);//背光亮度调节
Delay1ms(1000);
Write_Dir(0x8b,0xff);//背光亮度调节
Delay1ms(1000);
//********内部输入字符测试********
Text_Foreground_Color1(color_yellow);//前景颜色设定
Write_Dir(0x2E,0x01);//设置字符模式16x16/间距1
Write_Dir(0x40,0x80);//设置字符模式
Write_Dir(0x21,0x10);//设置为直接输入ASII码
FontWrite_Position(20,10);//文字写入位置
Write_Dir(0x22,0x05);//文字功能:放大2倍 FNCR1
String("www.tsingtek.com");
Write_Dir(0x22,0x00);
Delay1ms(1000);
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
//********外部字符功能测试********
Active_Window(0,319,0,239);//设置工作窗口大小
Write_Dir(0x20,0x00);
Write_Dir(0x21,0x20);//选择外部字库
Write_Dir(0x06,0x03);//设置FLASH频率
Write_Dir(0x2E,0x80);//设置字符模式32x32/间距0
Write_Dir(0x2F,0x81);//设置字符IC
Write_Dir(0x05,0x08);//设置SROC
Write_Dir(0x22,0x00);
FontWrite_Position(0,84);//文字写入位置
Write_Dir(0x40,0x80);//设置字符模式 MWCR0,1:文本0:绘图
LCD_CmdWrite(0x02);//写入数据命令
String("杭州清达光电技术有限公司");
Text_Foreground_Color1(color_brown);//前景颜色设定
Write_Dir(0x2E,0x40);//设置字符模式16x16/间距1
FontWrite_Position(0,132);//文字写入位置
String("TEL:0571-85121224");
FontWrite_Position(0,154);//文字写入位置
String("FAX:0571-85121304");
FontWrite_Position(0,178);//文字写入位置
String("EMAIL:sale@tsingtek.com");
FontWrite_Position(250,202);//文字写入位置
String("ADD:费家塘路588号");
Delay1ms(1000);
Write_Dir(0x21,0x00);//复原寄存器
Write_Dir(0x2F,0x00);//复原寄存器
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
//********显示一张256色16*16图片******
MemoryWrite_Position(80,80);
Active_Window(0,319,0,239);
show_pic();
Delay1ms(1000);
}
}
//型号:HGF035-320*240
#include <absacc.h>
//#include "delay.h"
//#include "Pictures.h"
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit rs=P3^0;
sbit cs=P3^4;
sbit wr=P3^1;
sbit rd=P3^3;
sbit INT=P3^6;
sbit LCD_RST =P3^5; //L有效
#define DATA_BUS P0
unsigned int X1,Y1,X2,Y2,X3,Y3,X4,Y4;
uchar taby[4];
uchar tabx[4];
uint x[6],y[6],xmin,ymin,xmax,ymax;
//#define uchar unsigned char
//#define uint unsigned int
//#define ulong unsigned long
#define color_brown 0x40c0
#define color_black 0x0000
#define color_white 0xffff
#define color_red 0xf800
#define color_green 0x07e0
#define color_blue 0x001f
#define color_yellow color_red|color_green
#define color_cyan color_green|color_blue
#define color_purple color_red|color_blue
/** 延时子程序**/
void Delay1ms(uint t) //12M晶振大约延时1ms
{uint i,j;
for(i=0;i<t;i++)
for(j=0;j<109*2;j++)
_nop_();
}
void LCD_CmdWrite(unsigned char Cmd)
{
rd = 1;
cs = 0;
rs = 1;
DATA_BUS = Cmd;
wr = 0;
wr = 1;
cs= 1;
DATA_BUS = 0xff;
rs = 0;
/*
//6800模式
cs =0; // chip enable.
wr = 0; //
rs = 1; // rs = 0;
DATA_BUS = Cmd;
rd = 1; //
;
;
rd = 0; //
cs =1; // chip disable.
*/
}
void LCD_DataWrite(unsigned char Data)
{
rd = 1;
cs = 0;
rs = 0;
DATA_BUS = Data;
wr = 0;
wr = 1;
cs = 1;
DATA_BUS = 0xff;
rs = 1;
/*
//6800模式
cs =0; // chip enable.
wr = 0; //
rs = 1; // rs = 0;
DATA_BUS = Data;
rd = 0; //
;
;
rd = 0; //
cs =1; // chip disable
*/
}
//***********************写指令
void Write_Dir(uchar Cmd,uchar Data)
{
LCD_CmdWrite(Cmd);
LCD_DataWrite(Data);
}
//***********************读状态
uchar LCD_StatusRead(void)
{
uchar Data;
cs = 0;
rs= 1;
wr = 1;
rd = 0;
Data = DATA_BUS;
rd = 1;
cs= 1;
DATA_BUS = 0xff;
rs = 0;
return Data;
/*
//6800模式
uchar reg_rddata;
DATA_BUS = 0xff;
cs =0; // chip enable.
wr = 1; //
rs = 1; //
rd = 1; // rd = 0;
reg_rddata = DATA_BUS;
;
;
rd = 0; // rd = 1;
cs =1; // chip disable.
return(reg_rddata);
*/
}
//***********************读数据
uchar LCD_DataRead(void)
{
uchar Data;
wr = 1;
cs = 0;
rs = 0;
rd = 0;
Data = DATA_BUS;
rd = 1;
cs = 1;
rs = 1;
return Data;
/*
//6800模式
uchar reg_rddata;
DATA_BUS = 0xff;
cs =0; // chip enable.
wr = 1; //
rs = 0; //
rd = 1; // rd = 0;
reg_rddata = DATA_BUS;
;
;
rd = 0; // rd = 1;
cs =1; // chip disable.
return(reg_rddata);
*/
}
//*********LCD复位
void LCD_Reset(void)
{
LCD_RST = 0;
Delay1ms(10);
LCD_RST = 1;
Delay1ms(10);
}
//*********测忙函数组(status register)
/*D7:Memory Read/Write Busy (Include Font Write Busy) 0 : No Memory Read/Write event. 1 : Memory Read/Write busy.
D6: BTE Busy 0 : BTE is done or idle. 1 : BTE is busy.
D5:Touch Panel Event Detected 0 : Touch Panel is not touched. 1 : Touch Panel is touched.
D4:Sleep Mode Status 0: RA8875 in Normal mode. 1: RA8875 in Sleep mode.
D3~D1:NC
D0:Serial Flash/ROM Busy Serial Flash/ROM busy status at Direct Access Mode
*/
void Chk_Busy(void)
{
uchar temp;
do
{
temp=LCD_StatusRead();
}while((temp&0x80)==0x80);
}
void Chk_BTE_Busy(void)
{
uchar temp;
do
{
temp=LCD_StatusRead();
}while((temp&0x40)==0x40);
}
void Chk_DMA_Busy(void)
{
uchar temp;
do
{
LCD_CmdWrite(0xBF);
temp =LCD_DataRead();
}while((temp&0x01)==0x01);
}
//********倍频设置
void PLL_ini(void)
{
LCD_CmdWrite(0x88);
LCD_DataWrite(0x0a);
Delay1ms(1);
LCD_CmdWrite(0x89);
LCD_DataWrite(0x02);
Delay1ms(1);
}
//********液晶初始化
void LCD_Initial(void)
{
PLL_ini();
LCD_CmdWrite(0x10); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface
LCD_DataWrite(0x0c); // 1x 64k color 1x 16bit
LCD_CmdWrite(0x04); //PCLK
LCD_DataWrite(0x03); //11b: PCLK period = 8 times of System Clock period.
Delay1ms(10);
//Horizontal set
LCD_CmdWrite(0x14); //HDWR//Horizontal Display Width Setting Bit[6:0] (320/8-1)
LCD_DataWrite(0x27); //Horizontal display width(pixels) = (HDWR + 1)*8 0x3b
LCD_CmdWrite(0x15); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
LCD_DataWrite(0x02); //(HNDR + 1)*8 +HNDFCR 0x00~0x07
LCD_CmdWrite(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x03); //Horizontal Non-Display Period (pixels) = (HNDR + 1)*8+HNDFTR 0x00~0x1f
LCD_CmdWrite(0x17); //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x01); //HSYNC Start Position(pixels) = (HSTR + 1)*8
LCD_CmdWrite(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x03); //HSYNC Width [4:0] HSYNC Pulse width(pixels) = (HPWR + 1)*8
//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0xef); //Vertical pixels = VDHR + 1 0xef
LCD_CmdWrite(0x1a); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x00); //Vertical pixels = VDHR + 1 0x00
LCD_CmdWrite(0x1b); //VNDR0 //Vertical Non-Display Period Bit [7:0]
LCD_DataWrite(0x0F); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1c); //VNDR1 //Vertical Non-Display Period Bit [8]
LCD_DataWrite(0x00); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1d); //VSTR0 //VSYNC Start Position[7:0]
LCD_DataWrite(0x0e); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1e); //VSTR1 //VSYNC Start Position[8]
LCD_DataWrite(0x00); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1f); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
LCD_DataWrite(0x01); //VSYNC Pulse Width(PCLK) = (VPWR + 1)
//LCD_CmdWrite(0x04); //PCLK
//LCD_DataWrite(0x01); //
}
//********设置工作窗口区域
void Active_Window(uint XL,uint XR ,uint YT ,uint YB)
{
uchar temp;
//setting active window X
temp=XL;
LCD_CmdWrite(0x30);//HSAW0
LCD_DataWrite(temp);
temp=XL>>8;
LCD_CmdWrite(0x31);//HSAW1
LCD_DataWrite(temp);
temp=XR;
LCD_CmdWrite(0x34);//HEAW0
LCD_DataWrite(temp);
temp=XR>>8;
LCD_CmdWrite(0x35);//HEAW1
LCD_DataWrite(temp);
//setting active window Y
temp=YT;
LCD_CmdWrite(0x32);//VSAW0
LCD_DataWrite(temp);
temp=YT>>8;
LCD_CmdWrite(0x33);//VSAW1
LCD_DataWrite(temp);
temp=YB;
LCD_CmdWrite(0x36);//VEAW0
LCD_DataWrite(temp);
temp=YB>>8;
LCD_CmdWrite(0x37);//VEAW1
LCD_DataWrite(temp);
}
//********BTE背景颜色设置
void Text_Background_Color1(uint b_color)
{
LCD_CmdWrite(0x60);//BGCR0
LCD_DataWrite((uchar)(b_color>>11));
LCD_CmdWrite(0x61);//BGCR0
LCD_DataWrite((uchar)(b_color>>5));
LCD_CmdWrite(0x62);//BGCR0
LCD_DataWrite((uchar)(b_color));
}
//********BTE背景颜色设置2
void Text_Background_Color(uchar setR, setG, setB)
{
LCD_CmdWrite(0x60);//BGCR0
LCD_DataWrite(setR);
LCD_CmdWrite(0x61);//BGCR0
LCD_DataWrite(setG);
LCD_CmdWrite(0x62);//BGCR0
LCD_DataWrite(setB);
}
//********BTE前景颜色设置
void Text_Foreground_Color1(uint b_color)
{
LCD_CmdWrite(0x63);//BGCR0
LCD_DataWrite((uchar)(b_color>>11));
LCD_CmdWrite(0x64);//BGCR0
LCD_DataWrite((uchar)(b_color>>5));
LCD_CmdWrite(0x65);//BGCR0
LCD_DataWrite((uchar)(b_color));
}
//********BT前景颜色设置2
void Text_Foreground_Color(uchar setR,setG,setB)
{
LCD_CmdWrite(0x63);//BGCR0
LCD_DataWrite(setR);
LCD_CmdWrite(0x64);//BGCR0
LCD_DataWrite(setG);
LCD_CmdWrite(0x65);//BGCR0·
LCD_DataWrite(setB);
}
//***********************BTE区域大小设置
void BTE_Size(width,height)
{
uchar temp;
temp=width;
LCD_CmdWrite(0x5c);//BET读写区域宽度
LCD_DataWrite(temp);
temp=width>>8;
LCD_CmdWrite(0x5d);//BET读写区域宽度
LCD_DataWrite(temp);
temp=height;
LCD_CmdWrite(0x5e);//BET读写区域高度
LCD_DataWrite(temp);
temp=height>>8;
LCD_CmdWrite(0x5f);//BET读写区域高度
LCD_DataWrite(temp);
}
//***********************BTE起始位置设置
void BTE_Source(uint SX,uint DX ,uint SY ,uint DY)
{
uchar temp,temp1;
temp=SX;
LCD_CmdWrite(0x54);//BTE读取数据水平位置
LCD_DataWrite(temp);
temp=SX>>8;
LCD_CmdWrite(0x55);//BET读取数据水平位置
LCD_DataWrite(temp);
temp=DX;
LCD_CmdWrite(0x58);//BET写入目标水平位置
LCD_DataWrite(temp);
temp=DX>>8;
LCD_CmdWrite(0x59);//BET写入目标水平位置
LCD_DataWrite(temp);
temp=SY;
LCD_CmdWrite(0x56);//BTE读取数据垂直位置
LCD_DataWrite(temp);
temp=SY>>8;
LCD_CmdWrite(0x57);
temp1 = LCD_DataRead();
temp1 &= 0x80;
temp=temp|temp1;
LCD_CmdWrite(0x57);//BTE读取数据垂直位置
LCD_DataWrite(temp);
temp=DY;
LCD_CmdWrite(0x5a);//BTE写入数据垂直位置
LCD_DataWrite(temp);
temp=DY>>8;
LCD_CmdWrite(0x5b);
temp1 = LCD_DataRead();
temp1 &= 0x80;
temp=temp|temp1;
LCD_CmdWrite(0x5b);//BTE写入数据垂直位置
LCD_DataWrite(temp);
}
//********内存写入位置
void MemoryWrite_Position(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x46);
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x47);
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x48);
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x49);
LCD_DataWrite(temp);
}
//********文字写入位置
void FontWrite_Position(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x2A);
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x2B);
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x2C);
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x2D);
LCD_DataWrite(temp);
}
//****************输入字符
void String(uchar *str)
{
Write_Dir(0x40,0x80);//设置字符模式
LCD_CmdWrite(0x02);
while(*str != '\0')
{
LCD_DataWrite(*str);
++str;
Chk_Busy();
}
}
//****************输入256色16*16图片
void show_pic(void)
{
uint i;
Write_Dir(0x40,0x00);//设置字符模式 MWCR0,1:文本0:绘图
LCD_CmdWrite(0x02);//MRWC
for(i=0;i<512;i++)
{
// LCD_DataWrite(pic[i]);
Chk_Busy();
}
}
//****************光标显示位置
void Cursor_Position(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x80);//GCHP0
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x81);//GCHP1
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x82);//GCVP0
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x83);//GCVP1
LCD_DataWrite(temp);
}
//****************卷动窗口大小
void Scroll_Window(uint XL,uint XR ,uint YT ,uint YB)
{
uchar temp;
temp=XL;
LCD_CmdWrite(0x38);//HSSW0
LCD_DataWrite(temp);
temp=XL>>8;
LCD_CmdWrite(0x39);//HSSW1
LCD_DataWrite(temp);
temp=XR;
LCD_CmdWrite(0x3c);//HESW0
LCD_DataWrite(temp);
temp=XR>>8;
LCD_CmdWrite(0x3d);//HESW1
LCD_DataWrite(temp);
temp=YT;
LCD_CmdWrite(0x3a);//VSSW0
LCD_DataWrite(temp);
temp=YT>>8;
LCD_CmdWrite(0x3b);//VSSW1
LCD_DataWrite(temp);
temp=YB;
LCD_CmdWrite(0x3e);//VESW0
LCD_DataWrite(temp);
temp=YB>>8;
LCD_CmdWrite(0x3f);//VESW1
LCD_DataWrite(temp);
}
//****************窗口卷动偏移量设置
void Scroll(uint X,uint Y)
{
uchar temp;
temp=X;
LCD_CmdWrite(0x24);//HOFS0
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x25);//HOFS1
LCD_DataWrite(temp);
temp=Y;
LCD_CmdWrite(0x26);//VOFS0
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x27);//VOFS1
LCD_DataWrite(temp);
}
void main(void)
{
uint i;
Delay1ms(100);
LCD_Reset();
LCD_Initial();
Write_Dir(0X01,0X80);//开启显示
Active_Window(0,319,0,239);//设置工作窗口大小
while(1)
{
Text_Foreground_Color1(color_white);//前景颜色设定
Text_Background_Color1(color_blue);//背景颜色设定
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
//********PWM背光控制测试********
LCD_CmdWrite(0x8a);//PWM控制设置
LCD_DataWrite(0x81);//开启PWM
Write_Dir(0x8b,0x00);//背光亮度调节
Delay1ms(1000);
Write_Dir(0x8b,0x4F);//背光亮度调节
Delay1ms(1000);
Write_Dir(0x8b,0x8F);//背光亮度调节
Delay1ms(1000);
Write_Dir(0x8b,0xff);//背光亮度调节
Delay1ms(1000);
//********内部输入字符测试********
Text_Foreground_Color1(color_yellow);//前景颜色设定
Write_Dir(0x2E,0x01);//设置字符模式16x16/间距1
Write_Dir(0x40,0x80);//设置字符模式
Write_Dir(0x21,0x10);//设置为直接输入ASII码
FontWrite_Position(20,10);//文字写入位置
Write_Dir(0x22,0x05);//文字功能:放大2倍 FNCR1
String("www.tsingtek.com");
Write_Dir(0x22,0x00);
Delay1ms(1000);
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
//********外部字符功能测试********
Active_Window(0,319,0,239);//设置工作窗口大小
Write_Dir(0x20,0x00);
Write_Dir(0x21,0x20);//选择外部字库
Write_Dir(0x06,0x03);//设置FLASH频率
Write_Dir(0x2E,0x80);//设置字符模式32x32/间距0
Write_Dir(0x2F,0x81);//设置字符IC
Write_Dir(0x05,0x08);//设置SROC
Write_Dir(0x22,0x00);
FontWrite_Position(0,84);//文字写入位置
Write_Dir(0x40,0x80);//设置字符模式 MWCR0,1:文本0:绘图
LCD_CmdWrite(0x02);//写入数据命令
String("杭州清达光电技术有限公司");
Text_Foreground_Color1(color_brown);//前景颜色设定
Write_Dir(0x2E,0x40);//设置字符模式16x16/间距1
FontWrite_Position(0,132);//文字写入位置
String("TEL:0571-85121224");
FontWrite_Position(0,154);//文字写入位置
String("FAX:0571-85121304");
FontWrite_Position(0,178);//文字写入位置
String("EMAIL:sale@tsingtek.com");
FontWrite_Position(250,202);//文字写入位置
String("ADD:费家塘路588号");
Delay1ms(1000);
Write_Dir(0x21,0x00);//复原寄存器
Write_Dir(0x2F,0x00);//复原寄存器
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
//********显示一张256色16*16图片******
MemoryWrite_Position(80,80);
Active_Window(0,319,0,239);
show_pic();
Delay1ms(1000);
}
}
上一篇:HG1223211演示程序