//画笔颜色
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕红色
#define GRAY 0X8430 //灰色
//GUI颜色
#define DARKBLUE 0X01CF //深蓝色
#define LIGHTBLUE 0X7D7C //浅蓝色
#define GRAYBLUE 0X5458 //灰蓝色
//以上三色为PANEL的颜色
#define LIGHTGREEN 0X841F //浅绿色
#define LGRAY 0XC618 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE 0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE 0X2B12 //浅棕蓝色(选择条目的反色)
#endif
lcd.c
#include <msp430x14x.h>
#include <intrinsics.h>
#include "LCD.h"
#include "sys.h"
/*代码测试环境:单片机msp430f149,晶振8MHZ 单片机工作电压为3.3v
管脚高电平输出为3.3v,可直接驱动TFT彩屏
控制线:RS-P3.0; WR-P3.1; RD-P3.2; CS-P3.3 REST-P3.4
数据线:低八位P4口 高八位P5口*/
ulong BACK_COLOR,POINT_COLOR; //背景色,画笔色
void LCD_Write_Bus(char VH ,char VL) //十六位并行数据写入函数
{
MCU2TFT_H=VH;
MCU2TFT_L=VL;
WR_L;
WR_H;
}
void LCD_WR_DATA8(char VH,char VL)//发送八位数据
{
RS_H;
LCD_Write_Bus(VH,VL);
}
void LCD_WR_DATA(int da)
{
RS_H;
LCD_Write_Bus(da>>8,da);
}
void LCD_WR_REG(int da)
{
RS_L;
LCD_Write_Bus(da>>8,da);
}
void LCD_WR_REG_DATA(int reg,int da)
{
LCD_WR_REG(reg);
LCD_WR_DATA(da);
}
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
{
LCD_WR_REG(0x0020);LCD_WR_DATA8(x1>>8,x1); //设置X坐标位置
LCD_WR_REG(0x0021);LCD_WR_DATA8(y1>>8,y1); //设置Y坐标位置
LCD_WR_REG(0x0050);LCD_WR_DATA8(x1>>8,x1); //开始X
LCD_WR_REG(0x0052);LCD_WR_DATA8(y1>>8,y1); //开始Y
LCD_WR_REG(0x0051);LCD_WR_DATA8(x2>>8,x2); //结束X
LCD_WR_REG(0x0053);LCD_WR_DATA8(y2>>8,y2); //结束Y
LCD_WR_REG(0x0022);
}
void LCD_Init()
{
CMD_OUT;
DATA_L_OUT;
DATA_H_OUT;
REST_H;
delayms(5);
REST_L;
delayms(5);
REST_H;
CS_H;
RD_H;
WR_H;
delayms(5);
CS_L; //打开片选使能
LCD_WR_REG_DATA(0x0001,0x0100);
LCD_WR_REG_DATA(0x0002,0x0700);
LCD_WR_REG_DATA(0x0003,0x1030);
LCD_WR_REG_DATA(0x0004,0x0000);
LCD_WR_REG_DATA(0x0008,0x0207);
LCD_WR_REG_DATA(0x0009,0x0000);
LCD_WR_REG_DATA(0x000A,0x0000);
LCD_WR_REG_DATA(0x000C,0x0000);
LCD_WR_REG_DATA(0x000D,0x0000);
LCD_WR_REG_DATA(0x000F,0x0000);
//power on sequence VGHVGL
LCD_WR_REG_DATA(0x0010,0x0000);
LCD_WR_REG_DATA(0x0011,0x0007);
LCD_WR_REG_DATA(0x0012,0x0000);
LCD_WR_REG_DATA(0x0013,0x0000);
//vgh
LCD_WR_REG_DATA(0x0010,0x1290);
LCD_WR_REG_DATA(0x0011,0x0227);
//delayms(100);
//vregiout
LCD_WR_REG_DATA(0x0012,0x001d); //0x001b
//delayms(100);
//vom amplitude
LCD_WR_REG_DATA(0x0013,0x1500);
//delayms(100);
//vom H
LCD_WR_REG_DATA(0x0029,0x0018);
LCD_WR_REG_DATA(0x002B,0x000D);
//gamma
LCD_WR_REG_DATA(0x0030,0x0004);
LCD_WR_REG_DATA(0x0031,0x0307);
LCD_WR_REG_DATA(0x0032,0x0002);// 0006
LCD_WR_REG_DATA(0x0035,0x0206);
LCD_WR_REG_DATA(0x0036,0x0408);
LCD_WR_REG_DATA(0x0037,0x0507);
LCD_WR_REG_DATA(0x0038,0x0204);//0200
LCD_WR_REG_DATA(0x0039,0x0707);
LCD_WR_REG_DATA(0x003C,0x0405);// 0504
LCD_WR_REG_DATA(0x003D,0x0F02);
//ram
LCD_WR_REG_DATA(0x0050,0x0000);
LCD_WR_REG_DATA(0x0051,0x00EF);
LCD_WR_REG_DATA(0x0052,0x0000);
LCD_WR_REG_DATA(0x0053,0x013F);
LCD_WR_REG_DATA(0x0060,0xA700);
LCD_WR_REG_DATA(0x0061,0x0001);
LCD_WR_REG_DATA(0x006A,0x0000);
//
LCD_WR_REG_DATA(0x0080,0x0000);
LCD_WR_REG_DATA(0x0081,0x0000);
LCD_WR_REG_DATA(0x0082,0x0000);
LCD_WR_REG_DATA(0x0083,0x0000);
LCD_WR_REG_DATA(0x0084,0x0000);
LCD_WR_REG_DATA(0x0085,0x0000);
//
LCD_WR_REG_DATA(0x0090,0x0010);
LCD_WR_REG_DATA(0x0092,0x0600);
LCD_WR_REG_DATA(0x0093,0x0003);
LCD_WR_REG_DATA(0x0095,0x0110);
LCD_WR_REG_DATA(0x0097,0x0000);
LCD_WR_REG_DATA(0x0098,0x0000);
LCD_WR_REG_DATA(0x0007,0x0133);
}
//清屏函数
//Color:要清屏的填充色
void LCD_Clear(uint Color)
{
uchar VH,VL;
uint i,j;
VH=Color>>8;
VL=Color;
Address_set(0,0,LCD_W-1,LCD_H-1);
for(i=0;i<LCD_W;i++)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA8(VH,VL);
}
}
}
//画点
//POINT_COLOR:此点的颜色
void LCD_DrawPoint(uint x,uint y)
{
Address_set(x,y,x,y);//设置光标位置
LCD_WR_DATA(POINT_COLOR);
} |