#include "stm32f10x.h"
#include "ILI9325.h"
#include "ILI9325_Font.h"
#include "fsmc.h"
#include "delay.h"
//功 能:写 ili9325 控制器寄存器地址
#define LCD_WriteIndex(Index) *(vu16 *)(Bank1_LCD_C)=Index
// 功 能:写 数据
#define LCD_WriteData(data) *(vu16 *)(Bank1_LCD_D)= data
//功 能:读取数据
#define LCD_ReadData() *(vu16 *)(Bank1_LCD_D)
//读取指定地址寄存器的值 内部函数
__inline u16 LCD_ReadRegister(u16 index)
{
LCD_WriteIndex(index);
return LCD_ReadData();
}
/****************************************************************************
* 名 称:void LCD_WriteRegister(u16 index,u16 dat)
* 功 能:写指定地址寄存器的值
* 入口参数:index 寄存器地址
* :dat 寄存器值
* 说 明:内部函数
****************************************************************************/
__inline void LCD_WriteRegister(u16 index,u16 dat)
{
LCD_WriteIndex(index);
LCD_WriteData(dat);
}
/****************************************************************************
* 名 称:LCD_Reset()
* 功 能:复位 ili9325 控制器
* 说 明:复位控制器,内部函数
****************************************************************************/
void LCD_Reset(void)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_1); //PE1 --->LCD_RST PE1=0;
LCD_Delay(1000);
GPIO_SetBits(GPIOE, GPIO_Pin_1); //PE1=1;
LCD_Delay(1000);
}
/****************************************************************************
* 名 称:void LCD_Delay(vu32 nCount)
* 功 能:延时
* 入口参数:nCount 延时值
* 出口参数:无
****************************************************************************/
void LCD_Delay(u32 nCount)
{
for(; nCount != 0; nCount--);
}
/****************************************************************************
* 名 称:LCD_Init()
* 功 能:初始化 ILI9325 控制器
****************************************************************************/
void LCDILI9325_Init(void)
{
TFTIL9325_GPIO_Configuration(); //FSMC || TFTILI9325 相关引脚初始化
FSMC_Init(); //FSMC 初始化
LCD_Reset(); //LCD 复位
LCD_WriteRegister(0x00E3,0x3008);
LCD_WriteRegister(0x00E7,0x0012);
LCD_WriteRegister(0x00EF,0x1231);
LCD_WriteRegister(0x0000,0x0001);//开启内部时钟
LCD_WriteRegister(0x0001,0x0100);
LCD_WriteRegister(0x0002,0x0700);//电源开启
//LCD_WriteRegister(0x0003,(1<<3)|(1<<4) ); //65K RGB
//DRIVE TABLE(寄存器 03H)
//BIT3=AM BIT4:5=ID0:1
//AM ID0 ID1 FUNCATION
// 0 0 0 R->L D->U
// 1 0 0 D->U R->L
// 0 1 0 L->R D->U
// 1 1 0 D->U L->R
// 0 0 1 R->L U->D
// 1 0 1 U->D R->L
// 0 1 1 L->R U->D 正常就用这个.
// 1 1 1 U->D L->R
LCD_WriteRegister(0x0003,(1<<12)|(3<<4)|(0<<3) );//65K
LCD_WriteRegister(0x0004,0x0000);
LCD_WriteRegister(0x0008,0x0207);
LCD_WriteRegister(0x0009,0x0000);
LCD_WriteRegister(0x000a,0x0000);//display setting 1 frame
LCD_WriteRegister(0x000c,0x0001);//display setting 16 bit
LCD_WriteRegister(0x000d,0x0000);//0f3c
LCD_WriteRegister(0x000f,0x0000);
//电源配置
LCD_WriteRegister(0x0010,0x0000);
LCD_WriteRegister(0x0011,0x0007);
LCD_WriteRegister(0x0012,0x0000);
LCD_WriteRegister(0x0013,0x0000);
LCD_Delay(50);
LCD_WriteRegister(0x0010,0x1590);
LCD_WriteRegister(0x0011,0x0227);
LCD_Delay(50);
LCD_WriteRegister(0x0012,0x009c);
LCD_Delay(50);
LCD_WriteRegister(0x0013,0x1900);
LCD_WriteRegister(0x0029,0x0023);
LCD_WriteRegister(0x002b,0x000e);
LCD_Delay(50);
LCD_WriteRegister(0x0020,0x0000);
LCD_WriteRegister(0x0021,0x013f);
LCD_Delay(50);
//伽马校正
LCD_WriteRegister(0x0030,0x0007);
LCD_WriteRegister(0x0031,0x0707);
LCD_WriteRegister(0x0032,0x0006);
LCD_WriteRegister(0x0035,0x0704);
LCD_WriteRegister(0x0036,0x1f04);
LCD_WriteRegister(0x0037,0x0004);
LCD_WriteRegister(0x0038,0x0000);
LCD_WriteRegister(0x0039,0x0706);
LCD_WriteRegister(0x003c,0x0701);
LCD_WriteRegister(0x003d,0x000f);
LCD_Delay(50);
LCD_WriteRegister(0x0050,0x0000); //水平GRAM起始位置
LCD_WriteRegister(0x0051,0x00ef); //水平GRAM终止位置
LCD_WriteRegister(0x0052,0x0000); //垂直GRAM起始位置
LCD_WriteRegister(0x0053,0x013f); //垂直GRAM终止位置
LCD_WriteRegister(0x0060,0xa700);
LCD_WriteRegister(0x0061,0x0001);
LCD_WriteRegister(0x006a,0x0000);
LCD_WriteRegister(0x0080,0x0000);
LCD_WriteRegister(0x0081,0x0000);
LCD_WriteRegister(0x0082,0x0000);
LCD_WriteRegister(0x0083,0x0000);
LCD_WriteRegister(0x0084,0x0000);
LCD_WriteRegister(0x0085,0x0000);
LCD_WriteRegister(0x0090,0x0010);
LCD_WriteRegister(0x0092,0x0000);
LCD_WriteRegister(0x0093,0x0003);
LCD_WriteRegister(0x0095,0x0110);
LCD_WriteRegister(0x0097,0x0000);
LCD_WriteRegister(0x0098,0x0000);
//开启显示设置
LCD_WriteRegister(0x0007,0x0133);
LCD_WriteRegister(0x0020,0x0000);
LCD_WriteRegister(0x0021,0x013f); //????
//GPIOD->BSRR = 1<<13;//点亮背光
LCD_Clear(0x0); //黑屏
}
/****************************************************************************
* 功 能:设置屏幕座标
* 入口参数:x 行座标
* y 列座标
****************************************************************************/
__inline void LCD_SetCursor(u16 x,u16 y)
{
LCD_WriteRegister(0x20, y);
LCD_WriteRegister(0x21, 319-x);
}
/****************************************************************************
* 名 称:void LCD_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY)
* 功 能:设置窗口区域
* 入口参数:StartX 行起始座标
* StartY 列起始座标
* EndX 行结束座标
* EndY 列结束座标
* 调用方法:LCD_SetWindows(0,0,100,100);
****************************************************************************/
void LCD_SetWindows(u16 StartX,u16 StartY,u16 EndX,u16 EndY) //????????????//
{
LCD_SetCursor(StartX,StartY);
LCD_WriteRegister(0x50, StartX);
LCD_WriteRegister(0x52, StartY);
LCD_WriteRegister(0x51, EndX);
LCD_WriteRegister(0x53, EndY);
}
/****************************************************************************
* 名 称:void LCD_Clear(u16 dat)
* 功 能:将屏幕填充成指定的颜色,如清屏,则填充 0xffff
* 入口参数:dat 填充值
* 调用方法:LCD_Clear(0xffff);
****************************************************************************/
void LCD_Clear(u16 color)
{
u32 i;
LCD_SetCursor(0x00, 0x00);
LCD_WriteIndex(0x22);
for(i=0;i<76800;i++)
{
LCD_WriteData(color);
}
}
/****************************************************************************
* 名 称:u16 LCD_GetPoint(u16 x,u16 y)
* 功 能:获取指定座标的颜色值
* 入口参数:x 行座标
* y 列座标
* 出口参数:当前座标颜色值
* 调用方法:i=LCD_GetPoint(10,10);
****************************************************************************/
u16 LCD_GetPoint(u16 x,u16 y)
{
u16 temp;
LCD_SetCursor(x,y);
LCD_WriteIndex(0x22);
temp = LCD_ReadData(); //dummy
return LCD_BGR2RGB(temp);
}
/********************************************
- 1
- 2
前往页