⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcddriver.c.c

📁 TFT4267绘图参考程序
💻 C
字号:
//=========================================
//
//  Copyright 2008 Tietong Electronic Equipment Co.,Ltd.
//
//  文 件 名: TFT LCD 举例
//  目标器件: LPC2292
//  编写日期: 2008/05/27
//  作    者: ken
//	
//=========================================
   	#include "define.h"

	#define TFTLCDCOM		(*((volatile unsigned short *) 0x83200000))
	#define TFTLCDDAT		(*((volatile unsigned short *) 0x83200002))
	#define TFTLCDRST		(1<<22)
	#define  SET_WINDOW_SX_EX   0x0046      // window地址设置--x0,x1 (R46H)
	#define  SET_WINDOW_SY      0x0048      // window地址设置--y0 (R48H)
	#define  SET_WINDOW_EY      0x0047      // window地址设置--y1 (R47H) 

	#define  SETADDRX         0x0020      // GRAM地址设置    0-239  (240)
	#define  SETADDRY         0x0021	  // GRAM地址设置	  0-319	 (320)
	#define  WRRDDATA         0x0022      // 写/读GRAM数据命令

// 定义TFT4267初始化数据信息
	#define     DATA_END        0xFF00
	typedef  struct
	{  
		UINT16  com;             // 命令字
   		UINT16  dat;             // 数据
   		UINT16  dly;             // 命令延时控制(如50)

	}  STCOM_INI;

	const STCOM_INI  TFT4267_INI[] = 
	{   // 电源设置
	    {0x0000, 0x0001, 10},   // Start Oscillation
	    {0x000B, 0x0000,  0},   // Frame cycle setting
	    {0x000C, 0x0000, 15},   // External display interface setting
	    {0x0011, 0x2E00,  0},   // Power control2 setting
	    {0x0014, 0x1119,  0},   // Power control5 setting
	    {0x0010, 0x1040, 15},   // Power control1 setting
	    {0x0013, 0x0040, 15},   // Power control4 setting
	    {0x0013, 0x0060, 15},   // Power control4
	    {0x0013, 0x0070, 60},   // Power control4
	    {0x0011, 0x3100,  0},   // Power control2
	    {0x0010, 0x1600, 20},   // Power control1 
	    
	    // 显示设置
	    {0x0001, 0x0927,   0},  // Driver output setting (240x320 mode, GS=0, SS=1)
	    {0x0002, 0x0700,   0},  // LCD driving waveform setting
	    {0x0003, 0x1030,   0},  // Entry mode setting (TRI=0, DFM=0, BGR=1, ID1:ID0 =11)
	    {0x0007, 0x0004,   0},  // Display control1 (VLE2:VLE1=00, REV=1)
	    {0x0008, 0x0505,   0},  // Display control2
	    {0x0009, 0x0000,   0},  // ***
	    
	    {0x0040, 0x0000,   0},  // Gate scan position (start G1 scan)
	    {0x0041, 0x0000,   0},  // Vertical scroll setting
	    {0x0042,    319,   0},  // Screen end position (320-1)
	    {0x0043,      0,   0},  // Screen start position (0)
	    {0x0044,      0,   0},  // 2th Screen end position
	    {0x0045,      0,   0},  // 2th Screen start position
	    {0x0046, 0xEF00,   0},  // window addr set for x0,x1 (0, 239)
	    {0x0047, 0x013F,   0},  // window addr set for y0    (319)
	    {0x0048, 0x0000,   20}, // window addr set for y1    (0)
	    
	    {0x0030, 0x0404,   0},  // Gamma control1
	    {0x0031, 0x0006,   0},  // Gamma control2
	    {0x0032, 0x0000,   0},  // Gamma control3
	    {0x0033, 0x0202,   0},  // Gamma control4
	    {0x0034, 0x0707,   0},  // Gamma control5
	    {0x0035, 0x0107,   0},  // Gamma control6
	    {0x0036, 0x0303,   0},  // Gamma control7
	    {0x0037, 0x0202,   0},  // Gamma control8
	    {0x0038, 0x1100,   0},  // Gamma control9
	    {0x0039, 0x1100,   0},  // Gamma control10
	    
	    // 打开显示
	    {0x0007, 0x0015,  40},  // Display control (GON=1, open disp)
	    {0x0007, 0x0017,  40},
	    {0x0020, 0x0000,   0},  // set GRAM addr(AD7--0)
	    {0x0021, 0x0000,  20},  // set GRAM addr(AD16--8)
	    
	    {DATA_END,    0,  0}
	};

/*==============================================
	函  数:
	功  能:毫秒级延时
	参  数:
	返  回:
================================================*/
void  DelaymS(UINT32 no)
{  
	UINT32 i;
	
	for(; no>0; no--)
	{  
		for(i=0; i<900; i++);
	}
}
/*==============================================
	函  数:
	功  能:LCD写数据
	参  数:
	返  回:
================================================*/
void LcdWriteDat(UINT16 iData)
{
	TFTLCDDAT=iData;
}
/*==============================================
	函  数:
	功  能:LCD写命令
	参  数:
	返  回:
================================================*/
void LcdWriteCmd(UINT16 iCmd)
{
	TFTLCDCOM=iCmd;
}		
/*==============================================
	函  数:
	功  能: 液晶复位
	参  数:
	返  回:
================================================*/
void  LcdReset(void)
{   
	PINSEL1 = PINSEL1 & (~(0x03<<12));
    IO0DIR = IO0DIR | TFTLCDRST;    

    IO0CLR = TFTLCDRST;
    DelaymS(10);
    IO0SET = TFTLCDRST;
    DelaymS(10);   
}
/*==============================================
	函  数:
	功  能:写GRAM地址,并使能写数据允许
	参  数:
	返  回:
================================================*/
void LcdWriteAddress(UINT16 x,UINT16 y)
{
	LcdWriteCmd(SETADDRX);		  //写入设置GRAM_X_地址命令
	LcdWriteDat(x);
	LcdWriteCmd(SETADDRY);		  //写入设置GRAM_Y_地址命令
	LcdWriteDat(y);

	LcdWriteCmd(WRRDDATA);			//写入读/写DGAM命令
}
/*==============================================
	函  数:
	功  能:设置窗口
	参  数:
	返  回:
================================================*/
void SetWindows(UINT16 x0,UINT16 y0,UINT16 x1,UINT16 y1)
{		
	UINT16  hea_hsa;

	hea_hsa = (x1<<8) | x0;		 //设置窗口尺寸
	LcdWriteCmd(SET_WINDOW_SX_EX);    	
	LcdWriteDat(hea_hsa);   
	LcdWriteCmd(SET_WINDOW_SY);   	
	LcdWriteDat(y0);	 
	LcdWriteCmd(SET_WINDOW_EY);   	
	LcdWriteDat(y1);
}

/*==============================================
	函  数:
	功  能:整屏填充同一种颜色	(data=0x0000为清屏)
	参  数:
	返  回:
================================================*/
void LcdFillScream(UINT16 data)
{
	UINT16 i;
	UINT16 j;	 

	SetWindows(0,0,239,319);    //设置窗口
	LcdWriteAddress(0,0);		//写入地址0,0,并数据使能

	for(i=0;i<240;i++)
	for(j=0;j<320;j++)
	{
		LcdWriteDat(data);
	}	
}
/*==============================================
	函  数:
	功  能:液晶初始化
	参  数:
	返  回:
================================================*/
void  LcdIni(void)  
{       
	UINT8  i;
	STCOM_INI  init_dat;
  
    LcdReset();					           // 复位TFT液晶

    for(i=0; i<100; i++)                   // 写入液晶初始化命令
    {   
		init_dat = TFT4267_INI[i];	       //读取结构数据
        if(init_dat.com==DATA_END) break;
      
        LcdWriteCmd(init_dat.com);
        LcdWriteDat(init_dat.dat);            
        DelaymS(init_dat.dly);      
    }

	LcdFillScream(0x0000);				   //清屏
}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -