自己把51的驱动一直,驱动器时ILI9325,可是一直驱动不了,连清屏都做不到,程序如下
lcd.h
#ifndef _LCD_H
#define _LCD_H
#include "sys.h"
#include "msp430x14x.h"
//定义控制端口
#define DATA_L_IN P2DIR =0X00
#define DATA_H_IN P4DIR =0X00 //数据口设置为输入
#define DATA_L_OUT P2DIR =0XFF
#define DATA_H_OUT P4DIR =0XFF //数据口设置为输出
#define TFT_L2MCU P2IN
#define TFT_H2MCU P4IN ` //要输出的口
#define MCU2TFT_L P2OUT
#define MCU2TFT_H P4OUT //输入的数据
#define CMD_OUT P3DIR=0XFF
#define RS_H P3OUT |=BIT0
#define RS_L P3OUT &=~BIT0 //RS 数据/命令 分别设置为高低电平
#define WR_H P3OUT |=BIT1
#define WR_L P3OUT &=~BIT1 //WR 写使能 分别设置为高低电平
#define RD_H P3OUT |=BIT2
#define RD_L P3OUT &=~BIT2 //RD 读使能 分别设置为高低电平
#define CS_H P3OUT |=BIT3
#define CS_L P3OUT &=~BIT3 //CS 片选端 分别设置为高低电平
#define REST_H P3OUT |=BIT4
#define REST_L P3OUT &=~BIT4 //复位端
#define CS P3OUT&BIT3
//定义LCD的尺寸
#define LCD_W 240
#define LCD_H 320
extern ulong BACK_COLOR,POINT_COLOR;
void LCD_Init();
void LCD_Clear(uint Color); //清屏
void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2);
void LCD_WR_DATA(int da); //发送16位参数
void LCD_WR_REG(int da);
void LCD_WR_DATA8(char VH,char VL); //发送数据-8位参数
void LCD_DrawPoint(uint x,uint y);//画点
void LCD_DrawPoint_big(uint x,uint y);//画一个大点
uint LCD_ReadPoint(uint x,uint y); //读点
void Draw_Circle(uint x0,uint y0,uchar r);
void LCD_DrawLine(uint x1, uint y1, uint x2, uint y2);
void LCD_DrawRectangle(uint x1, uint y1, uint x2, uint y2);
void LCD_Fill(uint xsta,uint ysta,uint xend,uint yend,uint color);
/*void LCD_ShowChar(uint x,uint y,uchar num,uchar mode);//显示一个字符
void LCD_ShowNum(uint x,uint y,ulong num,uchar len);//显示数字
void LCD_Show2Num(uint x,uint y,uint num,uchar len);//显示2个数字
void LCD_ShowString(uint x,uint y,const uchar *p); //显示一个字符串,16字体
void showhanzi(unsigned int x,unsigned int y,unsigned char index);*/
//画笔颜 {MOD}
#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 //棕 {MOD}
#define BRRED 0XFC07 //棕红 {MOD}
#define GRAY 0X8430 //灰 {MOD}
//GUI颜 {MOD}
#define DARKBLUE 0X01CF //深蓝 {MOD}
#define LIGHTBLUE 0X7D7C //浅蓝 {MOD}
#define GRAYBLUE 0X5458 //灰蓝 {MOD}
//以上三 {MOD}为PANEL的颜 {MOD}
#define LIGHTGREEN 0X841F //浅绿 {MOD}
#define LGRAY 0XC618 //浅灰 {MOD}(PANNEL),窗体背景 {MOD}
#define LGRAYBLUE 0XA651 //浅灰蓝 {MOD}(中间层颜 {MOD})
#define LBBLUE 0X2B12 //浅棕蓝 {MOD}(选择条目的反 {MOD})
#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; //背景 {MOD},画笔 {MOD}
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:要清屏的填充 {MOD}
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:此点的颜 {MOD}
void LCD_DrawPoint(uint x,uint y)
{
Address_set(x,y,x,y);//设置光标位置
LCD_WR_DATA(POINT_COLOR);
}
此帖出自
小平头技术问答
一周热门 更多>