為了更好,更深入學(xué)習(xí)了解ILI9325系列TFT的驅(qū)動原理,自己做了一塊TFT板子。為了方便測試,在上面集成了STM32芯片,到時候做實驗的時候就焊接STM32測試,如果只是使用,就直接焊接TFT就行了。板子還在做,先上原理圖與PCB。
-------------------------等板子回來,再測試,總結(jié)繼續(xù)-------------
--------板子回來了,焊接好了,簡單測試了一下!-----------
---------第二部分---------------ili9320.h------------------代碼簡單分析------
#ifndef _ILI9320_H_
#define _ILI9320_H_
#include “stm32f10x.h”
#define DB0_7_RCC RCC_APB2Periph_GPIOB
#define DB_8_15_RCC RCC_APB2Periph_GPIOC
//-------------------------------------------
#define nCsPin_RCC RCC_APB2Periph_GPIOC
#define nCsPin_Port GPIOC
#define nCsPin GPIO_Pin_11
#define RsPin_RCC RCC_APB2Periph_GPIOC
#define RsPin_Port GPIOC
#define RsPin GPIO_Pin_8
#define nWrPin_RCC RCC_APB2Periph_GPIOC
#define nWrPin_Port GPIOC
#define nWrPin GPIO_Pin_9
#define nRdPin_RCC RCC_APB2Periph_GPIOC
#define nRdPin_Port GPIOC
#define nRdPin GPIO_Pin_10
#define nRstPin_RCC RCC_APB2Periph_GPIOC
#define nRstPin_Port GPIOC
#define nRstPin GPIO_Pin_12
#define LightPin_RCC RCC_APB2Periph_GPIOB
#define LightPin_Port GPIOB
#define LightPin GPIO_Pin_0
//-----------------------------------------
#define Set_nWrnCsPin_Port-》BSRR = nWrPin // GPIO_SetBits (nWrPin_Port, nWrPin)
#define Clr_nWrnCsPin_Port-》BRR = nWrPin // GPIO_ResetBits (nWrPin_Port, nWrPin)
#define Set_Cs nCsPin_Port-》BSRR = nCsPin // GPIO_SetBits (nCsPin_Port, nCsPin)
#define Clr_Cs nCsPin_Port-》BRR = nCsPin// GPIO_ResetBits (nCsPin_Port, nCsPin)
#define Set_Rs RsPin_Port-》BSRR = RsPin// GPIO_SetBits (RsPin_Port, RsPin)
#define Clr_Rs RsPin_Port-》BRR = RsPin // GPIO_ResetBits (RsPin_Port, RsPin)
#define Set_nRdnRdPin_Port-》BSRR = nRdPin// GPIO_SetBits (nRdPin_Port, nRdPin)
#define Clr_nRdnRdPin_Port-》BRR = nRdPin // GPIO_ResetBits (nRdPin_Port, nRdPin)
#define Set_RstnRstPin_Port-》BSRR = nRstPin// GPIO_SetBits (nRstPin_Port, nRstPin)
#define Clr_RstnRstPin_Port-》BRR = nRstPin // GPIO_ResetBits (nRstPin_Port, nRstPin)
#define Set_LightLightPin_Port-》BSRR = LightPin// GPIO_SetBits (LightPin_Port, LightPin)
#define Clr_LightLightPin_Port-》BRR = LightPin// GPIO_ResetBits (LightPin_Port, LightPin)
//---------------------------------
#define White 0xFFFF
#define Black 0x0000
#define Grey 0xF7DE
#define Blue 0x001F
#define Blue2 0x051F
#define Red 0xF800
#define Magenta 0xF81F
#define Green 0x07E0
#define Cyan 0x7FFF
#define Yellow 0xFFE0
void Lcd_Configuration(void); //初始化GPIO
void LCD_ili9320_Initializtion(void); //初始化ILI9320---uCGUI需要使用--1
void LCD_ili9320_Reset(void);
void LCD_ili9320_BackLight(u8 status); //背光
void LCD_ili9320_SetCursor(u16 x,u16 y); //設(shè)置坐標(biāo)---uCGUI需要使用--2
void LCD_ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY); //設(shè)置窗體
void LCD_ili9320_DrawPicture(u16 StartX,u16 StartY,u16 EndX,u16 EndY,u16 *pic);//畫圖片
void LCD_ili9320_SetPoint(u16 x,u16 y,u16 point);//畫點---uCGUI需要使用--3
u16 LCD_ili9320_GetPoint(u16 x,u16 y); //讀取點顏色---uCGUI需要使用--4
void LCD_ili9320_PutChar(u16 x,u16 y,u8 c,u16 charColor,u16 bkColor); //顯示字符--需要字體頭文件
void LCD_ili9320_Clear(u16 dat); //清屏
void LCD_ili9320_Delay(u32 nCount);
void LCD_ili9320_Test(void);
void LCD_ili9320_WriteData(u16 dat); //寫數(shù)據(jù)
void LCD_ili9320_WriteIndex(u16 idx); //寫地址
u16 LCD_ili9320_ReadData(void); //讀數(shù)據(jù)
u16 LCD_ili9320_ReadRegister(u16 index); //讀寄存器
void LCD_ili9320_WriteRegister(u16 index,u16 dat); //寫寄存器
u16 LCD_ili9320_BGR2RGB(u16 c); //轉(zhuǎn)換顏色格式
u16 LCD_ili9320_Color565(u32 RGB); // RGB顏色轉(zhuǎn)為16位(565)
void LCD_ili9320_DrawHLine(uint16_t usX1 , uint16_t usY1 , uint16_t usX2 , uint16_t usColor);//水平線---uCGUI需要使用--5
void LCD_ili9320_DrawVLine(uint16_t usX1 , uint16_t usY1 , uint16_t usY2 , uint16_t usColor);//垂直線---uCGUI需要使用--6
void LCD_ili9320_FillRect(u16 x0, u16 y0, u16 x1, u16 y1,u16 color);//填充矩形---uCGUI需要使用--7
void LCD_ili9320_Line(u16 x0, u16 y0, u16 x1, u16 y1,u16 color); // 畫任意直線線
void LCD_ili9320_Circle(u16 cx,u16 cy,u16 r,u16 color,u8 fill); // 畫園
void LCD_ili9320_Rectangle(u16 x0, u16 y0, u16 x1, u16 y1,u16 color,u8 fill); // 畫矩形--填充或者不填充
void LCD_ili9320_Square(u16 x0, u16 y0, u16 with, u16 color,u8 fill); // 畫正方形--填充或者不填充
void LCD_ili9320_Text(u16 x, u16 y, u8 *str, u16 len,u16 Color, u16 bkColor); //簡單測試--顯示漸變色條
#endif
---------第三部分----------------ili9320.c------代碼分析------
#include “ili9320.h”
#include “ili9320_font.h”
void Lcd_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB “ RCC_APB2Periph_GPIOC, ENABLE); //初始化數(shù)據(jù)引腳 ---DB0~~DB7是PB8~~PB15 DB8~~DB15是PC0~~PC7----------//
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(nCsPin_RCC, ENABLE); // 控制腳 CS ------PC11----//
GPIO_InitStructure.GPIO_Pin = nCsPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(nCsPin_Port, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RsPin_RCC, ENABLE); // 控制腳 RS -------PC8---//
GPIO_InitStructure.GPIO_Pin = RsPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(RsPin_Port, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(nWrPin_RCC, ENABLE); // 控制腳 WR ----PC9--//
GPIO_InitStructure.GPIO_Pin = nWrPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(nWrPin_Port, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(nRdPin_RCC, ENABLE); // 控制腳 RD ---PC10--//
GPIO_InitStructure.GPIO_Pin = nRdPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(nRdPin_Port, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(nRstPin_RCC, ENABLE); // 控制腳 RST ---PC12--//
GPIO_InitStructure.GPIO_Pin = nRstPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(nRstPin_Port, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(LightPin_RCC, ENABLE); // 控制腳背光 --PB00---//
GPIO_InitStructure.GPIO_Pin = LightPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(LightPin_Port, &GPIO_InitStructure);
}
void delayms(int count) // X1ms
{
int i,j;
for(i=0;i for(j=0;j《1000;j++);
}
void LCD_ili9320_Initializtion (void) //--功 能:初始化 ILI9320 控制器
{
volatile u16 i, j, k;
u32 DeviceCode = 0;
Lcd_Configuration();
LCD_ili9320_BackLight(0); //關(guān)背光
delayms(200);
Clr_Rst;
delayms(200);
LCD_ili9320_WriteData(0xffff);
Set_Rst; Set_nWr; Set_Cs; Set_Rs; Set_nRd; Set_Rst;
delayms(200);
LCD_ili9320_WriteRegister(0x0000,0x0001); // Start OCS
delayms(200);
DeviceCode = LCD_ili9320_ReadRegister(0x0000); // 讀控制器型號 ILI9320
if(DeviceCode == 0x9320||0x9300)
{
LCD_ili9320_WriteRegister(0x00,0x0000);
LCD_ili9320_WriteRegister(0x01,0x0100);//驅(qū)動器輸出控制
LCD_ili9320_WriteRegister(0x02,0x0700);//LCD驅(qū)動波形控制-反轉(zhuǎn)
LCD_ili9320_WriteRegister(0x03,0x1030);//進入模式--F-
LCD_ili9320_WriteRegister(0x04,0x0000);//重新調(diào)整控制寄存器大小---縮放
LCD_ili9320_WriteRegister(0x08,0x0202);//Display Contral 2.(0x0207)
LCD_ili9320_WriteRegister(0x09,0x0000);//Display Contral 3.(0x0000)
LCD_ili9320_WriteRegister(0x0a,0x0000);//Frame信號輸出間隔
LCD_ili9320_WriteRegister(0x0c,(1《《0)); //RGB顯示接口控制1--16位
LCD_ili9320_WriteRegister(0x0d,0x0000);//幀標(biāo)記的位置
LCD_ili9320_WriteRegister(0x0f,0x0000); //RGB顯示接口控制1
delayms(5);
LCD_ili9320_WriteRegister(0x07,0x0101);//Display Contral.
delayms(5);
LCD_ili9320_WriteRegister(0x10,(1《《12)|(0《《8)|(1《《7)|(1《《6)|(0《《4));//Power Control 1.(0x16b0)
LCD_ili9320_WriteRegister(0x11,0x0007); //Power Control 2.(0x0001)
LCD_ili9320_WriteRegister(0x12,(1《《8)|(1《《4)|(0《《0));//Power Control 3.(0x0138)
LCD_ili9320_WriteRegister(0x13,0x0b00);//Power Control 4.
LCD_ili9320_WriteRegister(0x29,0x0000); //Power Control 7.
LCD_ili9320_WriteRegister(0x2b,(1《《14)|(1《《4));//幀速率和色彩控制---70
LCD_ili9320_WriteRegister(0x50,0);//Set X Star240*320
LCD_ili9320_WriteRegister(0x51,239); //水平GRAM終止位置Set X End.
LCD_ili9320_WriteRegister(0x52,0);//Set Y Star
LCD_ili9320_WriteRegister(0x53,319);//Set Y End.t.
LCD_ili9320_WriteRegister(0x60,0x2700);//門掃描控制器
LCD_ili9320_WriteRegister(0x61,0x0001);//Driver Output Control.
LCD_ili9320_WriteRegister(0x6a,0x0000); //Vertical Srcoll Control.
LCD_ili9320_WriteRegister(0x80,0x0000); //局部影像控制器1
LCD_ili9320_WriteRegister(0x81,0x0000); //局部影像控制器1--起始地址
LCD_ili9320_WriteRegister(0x82,0x0000); //局部影像控制器1--終止地址
LCD_ili9320_WriteRegister(0x83,0x0000); //Displsy Position? Partial Display 2.
LCD_ili9320_WriteRegister(0x84,0x0000); //RAM Address Start? Partial Display 2.
LCD_ili9320_WriteRegister(0x85,0x0000); //RAM Address End? Partial Display 2.
LCD_ili9320_WriteRegister(0x90,(0《《7)|(16《《0)); //平板接口控制器1(0x0013)
LCD_ili9320_WriteRegister(0x92,0x0000);//Panel Interface Contral 2.(0x0000)
LCD_ili9320_WriteRegister(0x93,0x0001); //Panel Interface Contral 3.
LCD_ili9320_WriteRegister(0x95,0x0110); //Frame Cycle Contral.(0x0110)
LCD_ili9320_WriteRegister(0x97,(0《《8)); //
LCD_ili9320_WriteRegister(0x98,0x0000); //Frame Cycle Contral.
LCD_ili9320_WriteRegister(0x07,0x0173);//(0x0173)
}
else if(DeviceCode==0x9325||DeviceCode==0x9328)//ILI9325
{
LCD_ili9320_WriteRegister(0x00e7,0x0010);
LCD_ili9320_WriteRegister(0x0000,0x0001); //開啟內(nèi)部時鐘
LCD_ili9320_WriteRegister(0x0001,0x0100);
LCD_ili9320_WriteRegister(0x0002,0x0700); //電源開啟
LCD_ili9320_WriteRegister(0x0003,(1《《12)|(3《《4)|(0《《3) ); //65K
LCD_ili9320_WriteRegister(0x0004,0x0000);
LCD_ili9320_WriteRegister(0x0008,0x0207);
LCD_ili9320_WriteRegister(0x0009,0x0000);
LCD_ili9320_WriteRegister(0x000a,0x0000);//display setting
LCD_ili9320_WriteRegister(0x000c,0x0001); //display setting
LCD_ili9320_WriteRegister(0x000d,0x0000);//0f3c
LCD_ili9320_WriteRegister(0x000f,0x0000);
//電源配置
LCD_ili9320_WriteRegister(0x0010,0x0000);
LCD_ili9320_WriteRegister(0x0011,0x0007);
LCD_ili9320_WriteRegister(0x0012,0x0000);
LCD_ili9320_WriteRegister(0x0013,0x0000);
delayms(5);
LCD_ili9320_WriteRegister(0x0010,0x1590);
LCD_ili9320_WriteRegister(0x0011,0x0227);
delayms(5);
LCD_ili9320_WriteRegister(0x0012,0x009c);
delayms(5);
LCD_ili9320_WriteRegister(0x0013,0x1900);
LCD_ili9320_WriteRegister(0x0029,0x0023);
LCD_ili9320_WriteRegister(0x002b,0x000e);
delayms(5);
LCD_ili9320_WriteRegister(0x0020,0x0000);
LCD_ili9320_WriteRegister(0x0021,0x013f);
delayms(5);
//伽馬校正
LCD_ili9320_WriteRegister(0x0030,0x0007);
LCD_ili9320_WriteRegister(0x0031,0x0707);
LCD_ili9320_WriteRegister(0x0032,0x0006);
LCD_ili9320_WriteRegister(0x0035,0x0704);
LCD_ili9320_WriteRegister(0x0036,0x1f04);
LCD_ili9320_WriteRegister(0x0037,0x0004);
LCD_ili9320_WriteRegister(0x0038,0x0000);
LCD_ili9320_WriteRegister(0x0039,0x0706);
LCD_ili9320_WriteRegister(0x003c,0x0701);
LCD_ili9320_WriteRegister(0x003d,0x000f);
delayms(5);
LCD_ili9320_WriteRegister(0x0050,0x0000); //水平GRAM起始位置
LCD_ili9320_WriteRegister(0x0051,0x00ef);//水平GRAM終止位置
LCD_ili9320_WriteRegister(0x0052,0x0000); //垂直GRAM起始位置
LCD_ili9320_WriteRegister(0x0053,0x013f); //垂直GRAM終止位置
LCD_ili9320_WriteRegister(0x0060,0xa700);
LCD_ili9320_WriteRegister(0x0061,0x0001);
LCD_ili9320_WriteRegister(0x006a,0x0000);
LCD_ili9320_WriteRegister(0x0080,0x0000);
LCD_ili9320_WriteRegister(0x0081,0x0000);
LCD_ili9320_WriteRegister(0x0082,0x0000);
LCD_ili9320_WriteRegister(0x0083,0x0000);
LCD_ili9320_WriteRegister(0x0084,0x0000);
LCD_ili9320_WriteRegister(0x0085,0x0000);
LCD_ili9320_WriteRegister(0x0090,0x0010);
LCD_ili9320_WriteRegister(0x0092,0x0000);
LCD_ili9320_WriteRegister(0x0093,0x0003);
LCD_ili9320_WriteRegister(0x0095,0x0110);
LCD_ili9320_WriteRegister(0x0097,0x0000);
LCD_ili9320_WriteRegister(0x0098,0x0000);
//開啟顯示設(shè)置
LCD_ili9320_WriteRegister(0x0007,0x0133);
LCD_ili9320_WriteRegister(0x0020,0x0000);
LCD_ili9320_WriteRegister(0x0021,0x013f);
}
delayms(200);
LCD_ili9320_BackLight(1);//開背光
}
void LCD_ili9320_SetCursor(u16 x,u16 y) //--功 能:設(shè)置屏幕座標(biāo)
{
LCD_ili9320_WriteRegister(0x0020,x);// 行
LCD_ili9320_WriteRegister(0x0021,y);// 列
}
/****************************************************************************
* 功 能:設(shè)置窗口區(qū)域
* 入口參數(shù):StartX 行起始座標(biāo)
* StartY 列起始座標(biāo)
* EndX 行結(jié)束座標(biāo)
* EndY 列結(jié)束座標(biāo)
****************************************************************************/
void LCD_ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY)
{
LCD_ili9320_SetCursor(StartX,StartY);
LCD_ili9320_WriteRegister(0x0050, StartX);
LCD_ili9320_WriteRegister(0x0052, StartY);
LCD_ili9320_WriteRegister(0x0051, EndX);
LCD_ili9320_WriteRegister(0x0053, EndY);
}
/****************************************************************************
* 功 能:將屏幕填充成指定的顏色,如清屏,則填充 0xffff
* 入口參數(shù):dat 填充值
****************************************************************************/
void LCD_ili9320_Clear(u16 dat)
{
u32 i;
LCD_ili9320_SetCursor(0x0000, 0x0000);
Clr_Cs;
LCD_ili9320_WriteIndex(0x0022);
Set_Rs;
for(i = 0; i 《 768000; i++) //240*320=76800
{
LCD_ili9320_WriteData(dat);
Clr_nWr;
Set_nWr;
}
Set_Cs;
}
/****************************************************************************
* 功 能:獲取指定座標(biāo)的顏色值
* 入口參數(shù):x 行座標(biāo)
* y 列座標(biāo)
* 出口參數(shù):當(dāng)前座標(biāo)顏色值
****************************************************************************/
u16 LCD_ili9320_GetPoint(u16 x,u16 y)
{
LCD_ili9320_SetCursor(x,y);
return (LCD_ili9320_BGR2RGB(LCD_ili9320_ReadRegister(0x0022)));
}
/****************************************************************************
* 功 能:在指定座標(biāo)畫點
* 入口參數(shù):x 行座標(biāo)
* y 列座標(biāo)
* point 點的顏色
****************************************************************************/
void LCD_ili9320_SetPoint(u16 x,u16 y,u16 point)
{
if ((x》240)||(y》320))
return;
LCD_ili9320_SetCursor(x,y);
Clr_Cs;
LCD_ili9320_WriteIndex(0x0022);
Set_Rs;
LCD_ili9320_WriteData(point);
Clr_nWr;Set_nWr;
Set_Cs;
}
/****************************************************************************
* 功 能:在指定座標(biāo)范圍顯示一副圖片
* 入口參數(shù):StartX 行起始座標(biāo)
* StartY 列起始座標(biāo)
* EndX 行結(jié)束座標(biāo)
* EndY 列結(jié)束座標(biāo)
* pic 圖片頭指針
* 說 明:圖片取模格式為水平掃描,16位顏色模式
****************************************************************************/
void LCD_ili9320_DrawPicture(u16 StartX,u16 StartY,u16 EndX,u16 EndY,u16 *pic)
{
u16 i;
LCD_ili9320_SetWindows(StartX,StartY,EndX,EndY);
LCD_ili9320_SetCursor(StartX,StartY);
Clr_Cs;
LCD_ili9320_WriteIndex(0x0022);
Set_Rs;
for (i=0;i《(EndX*EndY);i++)
{
LCD_ili9320_WriteData(*pic++);
Clr_nWr;Set_nWr;
}
Set_Cs;
}
/****************************************************************************
* 功 能:在指定座標(biāo)顯示一個8x16點陣的ascii字符
* 入口參數(shù):x 行座標(biāo)
* y 列座標(biāo)
* charColor 字符的顏色
* bkColor 字符背景顏色
* 說 明:顯示范圍限定為可顯示的ascii碼
****************************************************************************/
void LCD_ili9320_PutChar(u16 x,u16 y,u8 c,u16 charColor,u16 bkColor)
{
u16 i=0;
u16 j=0;
u8 tmp_char=0;
for (i=0;i《16;i++)
{
if(c == ‘