STM32单片机ILI9325系列TFT的驱动原理解析

STM32单片机ILI9325系列TFT的驱动原理解析,第1张

为了更好,更深入学习了解ILI9325系列TFT的驱动原理,自己做了一块TFT板子。为了方便测试,在上面集成了STM32芯片,到时候做实验的时候就焊接STM32测试,如果只是使用,就直接焊接TFT就行了。板子还在做,先上原理图与PCB

STM32单片机ILI9325系列TFT的驱动原理解析,STM32单片机ILI9325系列TFT的驱动原理解析,第2张

-------------------------等板子回来,再测试,总结继续-------------

--------板子回来了,焊接好了,简单测试了一下!-----------

---------第二部分---------------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); //设置坐标---uCGUI需要使用--2

void LCD_ili9320_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY); //设置窗体

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); //写数据

void LCD_ili9320_WriteIndex(u16 idx); //写地址

u16 LCD_ili9320_ReadData(void); //读数据

u16 LCD_ili9320_ReadRegister(u16 index); //读寄存器

void LCD_ili9320_WriteRegister(u16 index,u16 dat); //写寄存器

u16 LCD_ili9320_BGR2RGB(u16 c); //转换颜色格式

u16 LCD_ili9320_Color565(u32 RGB); // RGB颜色转为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); //初始化数据引脚 ---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); //关背光

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);//驱动器输出控制

LCD_ili9320_WriteRegister(0x02,0x0700);//LCD驱动波形控制-反转

LCD_ili9320_WriteRegister(0x03,0x1030);//进入模式--F-

LCD_ili9320_WriteRegister(0x04,0x0000);//重新调整控制寄存器大小---缩放

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);//帧标记的位置

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); //开启内部时钟

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);

//开启显示设置

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) //--功 能:设置屏幕座标

{

LCD_ili9320_WriteRegister(0x0020,x);// 行

LCD_ili9320_WriteRegister(0x0021,y);// 列

}

/****************************************************************************

* 功 能:设置窗口区域

* 入口参数:StartX 行起始座标

* StartY 列起始座标

* EndX 行结束座标

* EndY 列结束座标

****************************************************************************/

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

* 入口参数: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;

}

/****************************************************************************

* 功 能:获取指定座标的颜色值

* 入口参数:x 行座标

* y 列座标

* 出口参数:当前座标颜色值

****************************************************************************/

u16 LCD_ili9320_GetPoint(u16 x,u16 y)

{

LCD_ili9320_SetCursor(x,y);

return (LCD_ili9320_BGR2RGB(LCD_ili9320_ReadRegister(0x0022)));

}

/****************************************************************************

* 功 能:在指定座标画点

* 入口参数:x 行座标

* y 列座标

* 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;

}

/****************************************************************************

* 功 能:在指定座标范围显示一副图片

* 入口参数:StartX 行起始座标

* StartY 列起始座标

* EndX 行结束座标

* EndY 列结束座标

* 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;

}

/****************************************************************************

* 功 能:在指定座标显示一个8x16点阵的ascii字符

* 入口参数:x 行座标

* y 列座标

* 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 == ‘’)

continue;

tmp_char=ascii_8x16[((c-0x20)*16)+i];

for (j=0;j《8;j++)

{

if ( (tmp_char 》》 7-j) & 0x01 == 0x01)

LCD_ili9320_SetPoint(x+j,y+i,charColor);// 字符颜色

else

LCD_ili9320_SetPoint(x+j,y+i,bkColor);// 背景颜色

}

}

}

/****************************************************************************

* 功 能:测试液晶屏

* 说 明:显示彩条,测试液晶屏是否正常工作

****************************************************************************/

void LCD_ili9320_Test()

{

u8 R_data,G_data,B_data,i,j;

LCD_ili9320_SetCursor(0x00, 0x0000);

LCD_ili9320_WriteRegister(0x0050,0x00);//水平 GRAM起始位置

LCD_ili9320_WriteRegister(0x0051,239); //水平GRAM终止位置

LCD_ili9320_WriteRegister(0x0052,0); //垂直GRAM起始位置

LCD_ili9320_WriteRegister(0x0053,319); //垂直GRAM终止位置

Clr_Cs;

LCD_ili9320_WriteIndex(0x0022);

Set_Rs;

R_data=0;G_data=0;B_data=0;

for(j=0;j《50;j++)//红色渐强条

{

for(i=0;i《240;i++)

{

R_data=i/8;

LCD_ili9320_WriteData(R_data《《11|G_data《《5|B_data);

Clr_nWr;Set_nWr;

}

}

R_data=0x1f;G_data=0x3f;B_data=0x1f;

for(j=0;j《50;j++)

{

for(i=0;i《240;i++)

{

G_data=0x3f-(i/4);

B_data=0x1f-(i/8);

LCD_ili9320_WriteData(R_data《《11|G_data《《5|B_data);

Clr_nWr;

Set_nWr;

}

}

//----------------------------------

R_data=0;G_data=0;B_data=0;

for(j=0;j《50;j++)//绿色渐强条

{

for(i=0;i《240;i++)

{

G_data=i/4;

LCD_ili9320_WriteData(R_data《《11|G_data《《5|B_data);

Clr_nWr;

Set_nWr;

}

}

R_data=0x1f;G_data=0x3f;B_data=0x1f;

for(j=0;j《50;j++)

{

for(i=0;i《240;i++)

{

R_data=0x1f-(i/8);

B_data=0x1f-(i/8);

LCD_ili9320_WriteData(R_data《《11|G_data《《5|B_data);

Clr_nWr;

Set_nWr;

}

}

//----------------------------------

R_data=0;G_data=0;B_data=0;

for(j=0;j《60;j++) //蓝色渐强条

{

for(i=0;i《240;i++)

{

B_data=i/8;

LCD_ili9320_WriteData(R_data《《11|G_data《《5|B_data);

Clr_nWr;

Set_nWr;

}

}

B_data=0;

R_data=0x1f;G_data=0x3f;B_data=0x1f;

for(j=0;j《60;j++)

{

for(i=0;i《240;i++)

{

G_data=0x3f-(i/4);

R_data=0x1f-(i/8);

LCD_ili9320_WriteData(R_data《《11|G_data《《5|B_data);

Clr_nWr;

Set_nWr;

}

}

Set_Cs;

}

/****************************************************************************

* 功 能:RRRRRGGGGGGBBBBB 改为 BBBBBGGGGGGRRRRR 格式

* 入口参数:c BRG 颜色值

* 出口参数:RGB 颜色值

****************************************************************************/

u16 LCD_ili9320_BGR2RGB(u16 c)

{

u16 r, g, b, rgb;

b = (c》》0) & 0x1f;

g = (c》》5) & 0x3f;

r = (c》》11) & 0x1f;

rgb = (b《《11) + (g《《5) + (r《《0);

return( rgb );

}

/****************************************************************************

* 功 能:写 ili9320 控制器寄存器地址

* 入口参数:idx 寄存器地址

****************************************************************************/

void LCD_ili9320_WriteIndex(u16 idx)

{

Clr_Rs;

Set_nRd;

LCD_ili9320_WriteData(idx);

Clr_nWr;

Set_nWr;

Set_Rs;

}

/****************************************************************************

* 功 能:写 ili9320 寄存器数据

* 入口参数:dat 寄存器数据

* 说 明:向控制器指定地址写入数据,调用前需先写寄存器地址,内部函数

****************************************************************************/

void LCD_ili9320_WriteData(u16 data)

{

GPIOB-》ODR = (GPIOB-》ODR & 0x00ff) | (((data 《《 8) 》》 8) 《《 8);// 低8位数据写入CPIOB高8位

GPIOC-》ODR = (GPIOC-》ODR & 0xff00) | (((data 》》 8) 《《 8) 》》 8);// 高8位数据写入CPIOC低8位

}

/****************************************************************************

* 功 能:读取控制器数据

* 出口参数:返回读取到的数据

****************************************************************************/

u16 LCD_ili9320_ReadData(void)

{

//========================================================================

// ** **

// ** nCS ----\__________________________________________/------- **

// ** RS ------\____________/----------------------------------- **

// ** nRD -------------------------\_____/--------------------- **

// ** nWR --------\_______/-------------------------------------- **

// ** DB[0:15] ---------[index]----------[data]----------------------- **

// ** **

//========================================================================

u32 tmp;

GPIO_InitTypeDef GPIO_InitStructure;

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_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入模式

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_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOC, &GPIO_InitStructure);

tmp = ((GPIOB-》IDR & 0xff00) 》》 8); //PB的高8位为数据的低8位

tmp |= ((GPIOC-》IDR & 0x00ff) 《《 8);//PC的低8位为数据的高8位

//再次将GPIO恢复为输出模式

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_50MHz;

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_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(GPIOC, &GPIO_InitStructure);

return tmp;

}

/****************************************************************************

* 功 能:读取指定地址寄存器的值

* 入口参数:index 寄存器地址

* 出口参数:寄存器值

****************************************************************************/

u16 LCD_ili9320_ReadRegister(u16 index)

{

Clr_Cs;

LCD_ili9320_WriteIndex(index);

Clr_nRd;

index = LCD_ili9320_ReadData();

Set_nRd;

Set_Cs;

return index;

}

/****************************************************************************

* 功 能:写指定地址寄存器的值

* 入口参数:index 寄存器地址

* :dat 寄存器值

****************************************************************************/

void LCD_ili9320_WriteRegister(u16 index,u16 dat)

{

/************************************************************************

** **

** nCS ----\__________________________________________/------- **

** RS ------\____________/----------------------------------- **

** nRD ------------------------------------------------------- **

** nWR --------\_______/--------\_____/----------------------- **

** DB[0:15] ---------[index]----------[data]----------------------- **

** **

************************************************************************/

Clr_Cs;

Clr_Rs;

Set_nRd;

LCD_ili9320_WriteData(index);//地址

Clr_nWr;

Set_nWr;

Set_Rs;

LCD_ili9320_WriteData(dat); //值

Clr_nWr;

Set_nWr;

Set_Cs;

}

/****************************************************************************

* 功 能:复位 ili9320 控制器

* 说 明:复位控制器,内部函数

****************************************************************************/

void LCD_ili9320_Reset()

{

}

/****************************************************************************

* 功 能:开、关液晶背光

* 入口参数:status 1:背光开 0:背光关

****************************************************************************/

void LCD_ili9320_BackLight(u8 status)

{

if ( status 》= 1 )

Clr_Light; //低电平开背光

else

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/dianzi/2603704.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-08-09
下一篇 2022-08-09

发表评论

登录后才能评论

评论列表(0条)

保存