文档库 最新最全的文档下载
当前位置:文档库 › 单片机并口spi串口驱动彩屏程序

单片机并口spi串口驱动彩屏程序

//广州市锐显科技有限公司液晶驱动例程
//型号:VS48272M430
#include
#include "delay.h"
#include "Pictures.h"
#include
#include

sbit ZCS=P3^0;
sbit SDO=P3^1;
sbit SDI=P3^2;
sbit SCK=P3^3;
sbit che=P3^7;
sbit MCU_RST =P3^7; //L有效

#define DATA_BUS P1
#define CONTR P3

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

//*********SPI_Delay()
void SPI_Delay(void)
{
unsigned char t;
t=1;
while(--t!=0);
}

//*********4W_SPI_Init()
void SPI_Init(void)
{
SCK = 1;
SDI = 1;
SDO = 1;
ZCS = 1;
}

//*********4W_SPI_Write()
void SPI_Write(unsigned char dat)
{
unsigned char t = 8;
do
{
SDI = (bit)(dat & 0x80);
dat <<= 1;
SCK = 0;
//SPI_Delay();
SCK = 1;
//SPI_Delay();

} while ( --t != 0 );
//SCK = 1;
//SDI = 1;
}

//*********4W_SPI_Read()
unsigned char SPI_Read()
{
unsigned char dat;
unsigned char t = 8;
SDO = 1;
do
{
SCK = 0;
//SPI_Delay();
dat <<= 1;
if ( SDO ) dat++;
SCK = 1;
//SPI_Delay();
} while ( --t != 0 );
return dat;
}

//*********SPI写命令
void LCD_CmdWrite(uchar cmd)
{
SCK = 1;
SDI = 1;
ZCS = 0;
//SPI_Delay();
SPI_Write(0x80);
SPI_Write(cmd);
ZCS = 1;
//SPI_Delay();
}

//*********SPI写数据
void LCD_DataWrite(uchar Data)
{
SCK = 1;
SDI = 1;
ZCS = 0;
SPI_Write(0x00);
SPI_Write(Data);
//SPI_Delay();
ZCS = 1;
}

//*********SPI读数据
uchar LCD_DataRead(void)
{
uchar Data;
SCK = 1;
SDO = 1;
ZCS = 0;
SPI_Write(0x40);
Data = SPI_Read();
//SPI_Delay();
ZCS = 1;
return Data;
}

//***********************写指令
void Write_Dir(uchar Cmd,uchar Data)
{
LCD_CmdWrite(Cmd);
LCD_DataWrite(Data);
}

//*********SPI读命令状态
uchar LCD_StatusRead(void)
{
uchar Data;
SCK = 1;
SDO = 1;
ZCS = 0;
//SPI_Delay();
SPI_Write(0xc0);
Data = SPI_Read();
//SPI_Delay();
ZCS = 1;
return Data;
}

//*********LCD复位
void LCD_Reset(void)
{
MCU_RST = 0;
Delay1ms(1);
MCU_RST = 1;
Delay1ms(1);
}

//*********测忙函数组
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); //
Delay1ms(1);
//Horizontal set
LCD_CmdWrite(0x14); //HDWR//Horizontal Display Width Setting Bit[6:0]
LCD_DataWrite(0x3b); //Horizontal display width(pixels) = (HDWR + 1)*8 0x27
LCD_CmdWrite(0x15); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
LCD_DataWrite(0x02); //(HNDR + 1)*8 +HNDFCR
LCD_CmdWrite(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x03); //Horizontal Non-Display Period (pixels) = (HNDR + 1)*8
LCD_CmdWrite(0x17); //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x01); //HSYNC Start Position(PCLK) = (HSTR + 1)*8
LCD_CmdWrite(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x03); //HSYNC Width [4:0] HSYNC Pulse width(PCLK) = (HPWR + 1)*8

//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0x0f); //Vertical pixels = VDHR + 1 0xef
LCD_CmdWrite(0x1a); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x01); //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(0x06); //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); //

LCD_CmdWrite(0x8c);//PWM控制设置
LCD_DataWrite(0x80);//开启PWM
LCD_CmdWrite(0x8c);//PWM控制设置
LCD_DataWrite(0x81);//开启PWM
LCD_CmdWrite(0x8d);//背光亮度
LCD_DataWrite(0xff);//亮度参数0xff-0x00
}

//********设置工作窗口区域
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);
}

//********背景颜色设置
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));
}

//********背景颜色设置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);
}

//********前景颜色设置
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));
}

//********前景颜色设置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;

tem

p=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();
}
}

//****************光标显示位置
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);
}

//********FLASH读取区域设置
void DMA_block_mode_size_setting(uint BWR,uint BHR,uint SPWR)
{
LCD_CmdWrite(0xB4);
LCD_DataWrite(BWR);
LCD_CmdWrite(0xB5);
LCD_DataWrite(BWR>>8);

LCD_CmdWrite(0xB6);
LCD_DataWrite(BHR);
LCD_CmdWrite(0xB7);
LCD_DataWrite(BHR>>8);

LCD_CmdWrite(0xB8);
LCD_DataWrite(SPWR);
LCD_CmdWrite(0xB9);
LCD_DataWrite(SPWR>>8);
}

//********FLASH读取开始位置设置
void DMA_Start_address_setting(ulong set_address)
{
LCD_CmdWrite(0xB0);
LCD_DataWrite(set_address);

LCD_CmdWrite(0xB1);
LCD_DataWrite(set_address>>8);

LCD_CmdWrite(0xB2);
LCD_DataWrite(set_addre

ss>>16);

LCD_CmdWrite(0xB3);
LCD_DataWrite(set_address>>24);
}
//********画圆:中心点,半径
void Draw_Circle(uint X,uint Y,uint R)
{
uchar temp;

temp=X;
LCD_CmdWrite(0x99);
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0x9a);
LCD_DataWrite(temp);

temp=Y;
LCD_CmdWrite(0x9b);
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0x9c);
LCD_DataWrite(temp);

temp=R;
LCD_CmdWrite(0x9d);
LCD_DataWrite(temp);
}

//********椭圆曲线:中心点,长短轴
void Draw_Ellipse(uint X,uint Y,uint R1,uint R2)
{
uchar temp;
temp=X;
LCD_CmdWrite(0xA5);
LCD_DataWrite(temp);
temp=X>>8;
LCD_CmdWrite(0xA6);
LCD_DataWrite(temp);

temp=Y;
LCD_CmdWrite(0xA7);
LCD_DataWrite(temp);
temp=Y>>8;
LCD_CmdWrite(0xA8);
LCD_DataWrite(temp);

temp=R1;
LCD_CmdWrite(0xA1);
LCD_DataWrite(temp);
temp=R1>>8;
LCD_CmdWrite(0xA2);
LCD_DataWrite(temp);

temp=R2;
LCD_CmdWrite(0xA3);
LCD_DataWrite(temp);
temp=R2>>8;
LCD_CmdWrite(0xA4);
LCD_DataWrite(temp);
}

//********画线、画矩形、三角形:起始坐标
void Draw_Line(uint XS,uint XE ,uint YS,uint YE)
{
uchar temp;
temp=XS;
LCD_CmdWrite(0x91);
LCD_DataWrite(temp);
temp=XS>>8;
LCD_CmdWrite(0x92);
LCD_DataWrite(temp);

temp=XE;
LCD_CmdWrite(0x95);
LCD_DataWrite(temp);
temp=XE>>8;
LCD_CmdWrite(0x96);
LCD_DataWrite(temp);

temp=YS;
LCD_CmdWrite(0x93);
LCD_DataWrite(temp);
temp=YS>>8;
LCD_CmdWrite(0x94);
LCD_DataWrite(temp);

temp=YE;
LCD_CmdWrite(0x97);
LCD_DataWrite(temp);
temp=YE>>8;
LCD_CmdWrite(0x98);
LCD_DataWrite(temp);
}

//********画三角形第三个点
void Draw_Triangle(uint X3,uint Y3)
{
uchar temp;
temp=X3;
LCD_CmdWrite(0xA9);
LCD_DataWrite(temp);
temp=X3>>8;
LCD_CmdWrite(0xAA);
LCD_DataWrite(temp);

temp=Y3;
LCD_CmdWrite(0xAB);
LCD_DataWrite(temp);
temp=Y3>>8;
LCD_CmdWrite(0xAC);
LCD_DataWrite(temp);
}

//****************触摸中断判断
bit Touch_Status(void)
{
uchar temp;
LCD_CmdWrite(0xF1);//INTC
temp =LCD_DataRead();
if ((temp&0x04)==0x04)
/*temp=LCD_StatusRead();
if ((temp&0x10)==0x10)*/
return 1;
else
return 0;
}

bit Chk_INT(void)
{
uchar temp;
temp=LCD_StatusRead();
if ((temp&0x20)==0x20)
return 1;
else
return 0;
}

bit Chk_INT2(void)
{
uchar temp;
LCD_CmdWrite(0x74);//INTC
temp =LCD_DataRead();
if ((temp&0x80)==0x80)
return 1;
else
return 0;
}

//**************读取X坐标
uchar ADC_X(void)
{
uchar temp;
LCD_CmdWrite(0x72);//TPXH X_coordinate high byte
//Chk_Busy();
temp=LCD_DataRead();
return temp;
}

//**************读取Y坐标
uchar ADC_Y(void)
{
uchar temp;
LCD_

CmdWrite(0x73);//TPYH Y_coordinate high byte
//Chk_Busy();
temp=LCD_DataRead();
return temp;
}

//**************读取XY坐标(高位坐标值)
uchar ADC_XY(void)
{
uchar temp;
LCD_CmdWrite(0x74);//TPXYL bit[3:2] Y_coordinate low byte bit[1:0] X_coordinate low byte
//Chk_Busy();
temp=LCD_DataRead();
return temp;
}

//****************触摸坐标显示
void TP(void)
{
unsigned int i;
Delay10ms(10);

X1=0;
X1|=ADC_X();
i=(X1<<2);
X1= i|((ADC_XY()&0x03));

Y1=0;
Y1|=ADC_Y();
i=(Y1<<2);
Y1=i|((ADC_XY()>>2)&0x03);

tabx[0]=X1/1000;
tabx[1]=X1%1000/100;
tabx[2]=X1%100/10;
tabx[3]=X1%10;
taby[0]=Y1/1000;
taby[1]=Y1%1000/100;
taby[2]=Y1%100/10;
taby[3]=Y1%10;

FontWrite_Position(100,60); //設定顯示位置
LCD_CmdWrite(0x02);
String("X = ");
LCD_DataWrite(tabx[0] |= 0x30);
Delay1ms(1);//连续显示字符必须加延时
LCD_DataWrite(tabx[1] |= 0x30);
Delay1ms(1);
LCD_DataWrite(tabx[2] |= 0x30);
Delay1ms(1);
LCD_DataWrite(tabx[3] |= 0x30);
Delay1ms(1);

FontWrite_Position(100, 140); //設定顯示位置
LCD_CmdWrite(0x02);
String("Y = ");
LCD_DataWrite(taby[0] |= 0x30);
Delay1ms(1);
LCD_DataWrite(taby[1] |= 0x30);
Delay1ms(1);
LCD_DataWrite(taby[2] |= 0x30);
Delay1ms(1);
LCD_DataWrite(taby[3] |= 0x30);
Delay1ms(1);
Write_Dir(0xf1,0x04);//clear INT state 確保上次觸碰後 TP_interrupt 清除
X1=0;
Y1=0;
}

//****************显示flash图片
void Displaypicture(uchar picnum)
{
uint picnumtemp;
Write_Dir(0X06,0X00);//FLASH频率设定
if(picnum<61)
{
Write_Dir(0X05,0X07);//FLASH设置 ac cs1,2c cs0
Write_Dir(0Xc7,0X01);
picnumtemp=picnum;
}
if(picnum>60&picnum<121)
{
Write_Dir(0X05,0X87); //ac
Write_Dir(0Xc7,0X00);
picnumtemp=picnum-60;
}
Write_Dir(0XBF,0X02);//FLASH设置
Active_Window(0,479,0,271);
MemoryWrite_Position(0,0);//内存写入位置
DMA_Start_address_setting(262144*(picnumtemp-1));
DMA_block_mode_size_setting(480,272,480);
Write_Dir(0XBF,0X03);//FLASH设置
Chk_DMA_Busy();
}

void main(void)
{
uint i;
Delay100ms(5);
LCD_Reset();
LCD_Initial();

Write_Dir(0X01,0X80);//开启显示
Active_Window(0,479,0,271);//设置工作窗口大小
while(1)
{
Text_Foreground_Color1(color_white);//前景颜色设定
Text_Background_Color1(color_blue);//背景颜色设定
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();
/*
//********SPIFLASH读取测试********
Write_Dir(0X06,0X00);//FLASH频率设定
Write_Dir(0X05,0X2e);//FLASH设置
Write_Dir(0XBF,0X02);//FLASH设置
MemoryWrite_Position(0,0);//内存写入位置

DMA_Start_address_setting(0);
DMA_block_mode_size_setting(480,272,480);
Write_Dir(0XBF,0X03);//FLASH设置
Chk_DMA_Busy();
Delay100ms(5);
Write_Dir(0X8E,0XC0);//开始清屏
Chk_Busy();
*/
Displa

ypicture(60);
Delay100ms(2);

Write_Dir(0X8E,0XC0);//开始清屏
Chk_Busy();
//********外部字符功能测试********
Write_Dir(0xC7,0x01);//开启外部字库IC
Write_Dir(0x21,0x20);//选择外部字库
Write_Dir(0x06,0x03);//设置FLASH频率
Write_Dir(0x2E,0x40);//设置字符模式24x24/间距0
Write_Dir(0x2F,0x41);//设置字符IC
Write_Dir(0x05,0xA8);//设置字符IC

FontWrite_Position(143,32);//文字写入位置
Write_Dir(0x40,0x80);//设置字符模式
LCD_CmdWrite(0x02);//写入数据命令
String("锐显科技有限公司");

Text_Foreground_Color1(color_brown);//前景颜色设定
Write_Dir(0x2E,0x01);//设置字符模式16x16/间距1
FontWrite_Position(100,100);//文字写入位置
String("TL:020-******** 186********");
FontWrite_Position(100,116);//文字写入位置
String("FX:020-********");
FontWrite_Position(100,132);//文字写入位置
String("EM:sale@https://www.wendangku.net/doc/b112505576.html,");
FontWrite_Position(100,148);//文字写入位置
String("AD:广州市复兴南路18号");

Text_Foreground_Color1(color_red);//前景颜色设定
Write_Dir(0x2E,0x00);//设置字符模式16x16/间距1
FontWrite_Position(0,180);//文字写入位置
String("VS48272M43 V2.0版本彩色液晶模块,内置中英文字库和存储FLASH,可快速存取图片;"
"同时支持8-bit或16-bit的8080/6800系列总线,支持SPI串口接口;支持2D的BTE,可用于处理大量图形文字转换");
Write_Dir(0x21,0x00);//复原寄存器
Write_Dir(0x2F,0x00);//复原寄存器

//********内部输入字符测试********
Text_Foreground_Color1(color_yellow);//前景颜色设定
Write_Dir(0x2E,0x01);//设置字符模式16x16/间距1
Write_Dir(0x40,0x80);//设置字符模式
Write_Dir(0x21,0x10);//设置为直接输入ASII码
FontWrite_Position(178,64);//文字写入位置
Write_Dir(0x22,0x00);//文字功能:放大2倍
String("https://www.wendangku.net/doc/b112505576.html,");
Delay100ms(2);

//*******************光标功能测试
Write_Dir(0x40,0xE0);//设置文字模式光标
Write_Dir(0x41,0x00);//关闭图形光标
Write_Dir(0x44,0x1f);//光标闪烁周期
Write_Dir(0x45,0x81);//光标大小
Delay100ms(10);
Write_Dir(0x21,0x00);//复原寄存器
Write_Dir(0x40,0x00);//复原寄存器

//*******************图形光标
Write_Dir(0x84,0x00);//光标颜色0设定
Write_Dir(0x85,0xff);//光标颜色1设定
Write_Dir(0x41,0x08);//CGRAM写入
Write_Dir(0x40,0x00);//设置图形模式光标
LCD_CmdWrite(0x02);
for(i=0;i<256;i++)
{
LCD_DataWrite(Cursor_Picture[i]);
Chk_Busy();
}
Cursor_Position(150,180);
Write_Dir(0x41,0x80);//图形光标开启
Delay100ms(5);
Write_Dir(0x41,0x00);//关闭图形光标

//********PWM背光控制测试********
Write_Dir(0x8d,0x0f);//背光亮度调节
Delay100ms(3);
Write_Dir(0x8d,0x3f);//背光亮度调节
Delay100ms(3);
Write_Dir(0x8d,0xff);//

背光亮度调节
Delay100ms(3);

//********部分窗口清屏测试********
Write_Dir(0X8E,0X80);//开始清屏(显示窗口)
Chk_Busy();

Write_Dir(0X8E,0X40);//设定清屏区间(工作窗口)
Active_Window(40,150,100,200);//设置工作窗口大小
Text_Background_Color1(color_green);//背景颜色设定
Write_Dir(0X8E,0XC0);//开始清屏
Chk_Busy();

Active_Window(150,479,180,271);//设置工作窗口大小
Text_Background_Color1(color_cyan);//背景颜色设定
Write_Dir(0X8E,0XC0);//开始清屏
Chk_Busy();

//********内存写入测试********
Active_Window(150,229,0,79);//设置工作窗口大小
MemoryWrite_Position(150,0);//内存写入位置
LCD_CmdWrite(0x02);//写入寄存器数据
i=6400; //80X80点阵数据量
while(i--)
{
LCD_DataWrite(0xff);//黄色
Chk_Busy();
LCD_DataWrite(0xe0);
Chk_Busy();
}
Delay100ms(3);

//********几何图案绘图测试********
Active_Window(0,479,0,271);//设置工作窗口大小
//Chk_Busy();
Draw_Ellipse(120,68,100,50);//画曲线
Text_Foreground_Color1(color_cyan);//颜色设定
Write_Dir(0XA0,0X10);//设定参数
Write_Dir(0XA0,0X90);//开始画
Delay100ms(2);
Write_Dir(0XA0,0X91);//开始画
Delay100ms(2);
Write_Dir(0XA0,0X92);//开始画
Delay100ms(2);
Write_Dir(0XA0,0X93);//开始画
Delay100ms(2);

Draw_Ellipse(120,68,100,50);//画椭圆
Text_Foreground_Color1(color_red);//颜色设定
Write_Dir(0XA0,0X00);//设定参数
Write_Dir(0XA0,0X80);//开始画
Delay100ms(2);
Write_Dir(0XA0,0X40);//设定是否填充
Write_Dir(0XA0,0XC0);//开始画
Delay100ms(2);

Draw_Circle(360,68,60);//画圆
Text_Foreground_Color1(color_green);//颜色设定
Write_Dir(0X90,0X00);//设定参数
Write_Dir(0X90,0X40);//开始画
Delay100ms(2);
Write_Dir(0X90,0X20);//设定参数
Write_Dir(0X90,0X60);//开始画
Delay100ms(2);

Draw_Line(10,110,136,262);//画矩形
Text_Foreground_Color1(color_brown);//颜色设定
Write_Dir(0X90,0X10);//设定参数
Write_Dir(0X90,0X90);//开始画
Delay100ms(2);
Write_Dir(0X90,0X30);//设定参数
Write_Dir(0X90,0XB0);//开始画
Delay100ms(2);

Draw_Line(260,365,262,136);//画三角形
Draw_Triangle(470,262);//画三角形第三个点
Text_Foreground_Color1(color_purple);//颜色设定
Write_Dir(0X90,0X01);//设定参数
Write_Dir(0X90,0X81);//开始画
Delay100ms(2);
Write_Dir(0X90,0X21);//设定参数
Write_Dir(0X90,0XA1);//开始画
Delay100ms(2);

Draw_Line(130,240,136,262);//画圆角矩形
Draw_Ellipse(0,0,10,15);//设定半径
Text_Foreground_Color1(color_yellow);//颜色设定
Write_Dir(0XA0,0X20);//设定是否填充
Write_Dir(0XA0,0XA0);//开始画
Delay100ms(2);
Write_Dir(0XA0,0X60);//设定是否填充
Write_Dir(0XA0,0XE0);//开始画
Delay100ms(2);

Draw_Line(10,470

,10,262);//画线段
Text_Foreground_Color1(color_black);//颜色设定
Write_Dir(0X90,0X00);//设定参数
Write_Dir(0X90,0X80);//开始画
Delay100ms(2);

//**********************BTE颜色填充
BTE_Size(15,68);
Write_Dir(0x51,0xcc);//光栅设定
for(i=0;i<32;i++)
{
Text_Foreground_Color(i,0,0);
BTE_Source(0,i*15,0,0);//BTE起始位置设置
Write_Dir(0x50,0x80);//BET开启
Chk_BTE_Busy();

Text_Foreground_Color(0,i*2,0);
BTE_Source(0,i*15,0,68);//BTE起始位置设置
Write_Dir(0x50,0x80);//BET开启
Chk_BTE_Busy();

Text_Foreground_Color(0,0,i);
BTE_Source(0,i*15,0,136);//BTE起始位置设置
Write_Dir(0x50,0x80);//BET开启
Chk_BTE_Busy();

Text_Foreground_Color(i,i*2,i);
BTE_Source(0,i*15,0,204);//BTE起始位置设置
Write_Dir(0x50,0x80);//BET开启
Chk_BTE_Busy();
}
Delay100ms(2);

//**********************BTE颜色扩充
Text_Background_Color1(color_purple);//背景颜色设置
Text_Foreground_Color1(color_yellow);//前景颜色设置
BTE_Source(0,0,0,0);//BTE起始位置设置
BTE_Size(104,100);//BTE大小设置
Write_Dir(0x51,0x78);//光栅设定
Write_Dir(0x50,0x80);//BET开启
Chk_Busy();
LCD_CmdWrite(0x02);//写入数据
for(i=0;i<1300;i++)
{
LCD_DataWrite(Pic1[i]);
Chk_Busy();
}
Chk_BTE_Busy();
Delay100ms(2);

//**********************BTE颜色扩充移动
BTE_Source(0,200,0,0);//BTE起始位置设置
BTE_Size(104,100);//BTE大小设置
Text_Foreground_Color1(color_purple);//前景颜色设置(滤除背景色)
Write_Dir(0x51,0xc5);//光栅设定
Write_Dir(0x50,0x80);//BET开启
Delay100ms(5);

//**********************卷动功能测试
Scroll_Window(0,103,0,99); //指定要卷动的活动区
i=0;
while(i++<99){Delay10ms(1); Scroll(i,i);} //注意:卷动偏移值必须小于卷动设定范围
while(i-->0){Delay10ms(1); Scroll(i,i);}
while(i++<99){Delay10ms(1); Scroll(i,i);}
while(i-->0){Delay10ms(1); Scroll(i,i);}
Delay100ms(5);


/*
//********触摸功能测试********
Write_Dir(0x21,0x10);//设置为直接输入ASII码
Active_Window(0,479,0,271);
FontWrite_Position(40,200);
String("Touch to display the coordinate");

Write_Dir(0xf0,0x04);//开启中断
Write_Dir(0x71,0x00);//设置为4线触摸屏
Write_Dir(0x70,0xB2);//开启触摸功能,设置触摸参数

//while(1)
for(i=0;i<50000;i++)
{
Write_Dir(0xf1,0x04);//clear INT state 確保上次觸碰後 TP_interrupt 清除
Delay10ms(5);
if(Touch_Status())
//if(Chk_INT2())
{
TP();
//gg();
}
else
{
FontWrite_Position(100,60);
LCD_CmdWrite(0x02);
String("X = 0000");
FontWrite_Position(100, 140);
LCD_CmdWrite(0x02);
String("Y = 0000");
}
//Delay10ms(10);
}
*/
}

}


相关文档