📄 glcd.c
字号:
/****************************************Copyright (c)**************************************************
**
** http://www.powermcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: GLCD.c
** Descriptions: TFT操作函数库(模拟IO)
**
**------------------------------------------------------------------------------------------------------
** Created by: AVRman
** Created date: 2011-1-26
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
********************************************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "GLCD.h"
#include "HzLib.h"
#include "AsciiLib.h"
/* Private variables ---------------------------------------------------------*/
static uint8_t LCD_Code;
/* Private define ------------------------------------------------------------*/
#define ILI9320 0 /* 0x9320 */
#define ILI9325 1 /* 0x9325 */
#define ILI9328 2 /* 0x9328 */
#define ILI9331 3 /* 0x9331 */
#define SSD1298 4 /* 0x8999 */
#define SSD1289 5 /* 0x8989 */
#define ST7781 6 /* 0x7783 */
#define LGDP4531 7 /* 0x4531 */
#define SPFD5408B 8 /* 0x5408 */
#define R61505U 9 /* 0x1505 0x0505 */
#define HX8347D 10 /* 0x0047 */
#define HX8347A 11 /* 0x0047 */
#define LGDP4535 12 /* 0x4535 */
#define SSD2119 13 /* 3.5 LCD 0x9919 */
/*******************************************************************************
* Function Name : Lcd_Configuration
* Description : Configures LCD Control lines
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static void LCD_Configuration(void)
{
/* Configure the LCD Control pins */
/* EN = P0.19 , LE = P0.20 , DIR = P0.21 , CS = P0.22 , RS = P0.23 , RS = P0.23 */
/* RS = P0.23 , WR = P0.24 , RD = P0.25 , DB[0.7] = P2.0...P2.7 , DB[8.15]= P2.0...P2.7 */
LPC_GPIO0->FIODIR |= 0x03f80000;
LPC_GPIO0->FIOSET = 0x03f80000;
}
/*******************************************************************************
* Function Name : LCD_Send
* Description : LCD写数据
* Input : - byte: byte to be sent
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static __inline void LCD_Send (uint16_t byte)
{
LPC_GPIO2->FIODIR |= 0xFF; /* P2.0...P2.7 Output */
LCD_DIR(1) /* Interface A->B */
LCD_EN(0) /* Enable 2A->2B */
LPC_GPIO2->FIOPIN = byte; /* Write D0..D7 */
LCD_LE(1)
LCD_LE(0) /* latch D0..D7 */
LPC_GPIO2->FIOPIN = byte >> 8; /* Write D8..D15 */
}
/*******************************************************************************
* Function Name : wait_delay
* Description : Delay Time
* Input : - nCount: Delay Time
* Output : None
* Return : None
* Return : None
* Attention : None
*******************************************************************************/
void wait_delay(int count)
{
while(count--);
}
/*******************************************************************************
* Function Name : LCD_Read
* Description : LCD读数据
* Input : - byte: byte to be read
* Output : None
* Return : 返回读取到的数据
* Attention : None
*******************************************************************************/
static __inline uint16_t LCD_Read (void)
{
uint16_t value;
LPC_GPIO2->FIODIR &= ~(0xFF); /* P2.0...P2.7 Input */
LCD_DIR(0); /* Interface B->A */
LCD_EN(0); /* Enable 2B->2A */
wait_delay(80); /* delay some times */
value = LPC_GPIO2->FIOPIN0; /* Read D8..D15 */
LCD_EN(1); /* Enable 1B->1A */
wait_delay(80); /* delay some times */
value = (value << 8) | LPC_GPIO2->FIOPIN0; /* Read D0..D7 */
LCD_DIR(1);
return value;
}
/*******************************************************************************
* Function Name : LCD_WriteIndex
* Description : LCD写寄存器地址
* Input : - index: 寄存器地址
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static __inline void LCD_WriteIndex(uint16_t index)
{
LCD_CS(0);
LCD_RS(0);
LCD_RD(1);
LCD_Send( index );
wait_delay(70);
LCD_WR(0);
wait_delay(1);
LCD_WR(1);
LCD_CS(1);
}
/*******************************************************************************
* Function Name : LCD_WriteData
* Description : LCD写寄存器数据
* Input : - index: 寄存器数据
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static __inline void LCD_WriteData(uint16_t data)
{
LCD_CS(0);
LCD_RS(1);
LCD_Send( data );
LCD_WR(0);
wait_delay(1);
LCD_WR(1);
LCD_CS(1);
}
/*******************************************************************************
* Function Name : LCD_ReadData
* Description : 读取控制器数据
* Input : None
* Output : None
* Return : 返回读取到的数据
* Attention : None
*******************************************************************************/
static __inline uint16_t LCD_ReadData(void)
{
uint16_t value;
LCD_CS(0);
LCD_RS(1);
LCD_WR(1);
LCD_RD(0);
value = LCD_Read();
LCD_RD(1);
LCD_CS(1);
return value;
}
/*******************************************************************************
* Function Name : LCD_WriteReg
* Description : Writes to the selected LCD register.
* Input : - LCD_Reg: address of the selected register.
* - LCD_RegValue: value to write to the selected register.
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static __inline void LCD_WriteReg(uint16_t LCD_Reg,uint16_t LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
LCD_WriteIndex(LCD_Reg);
/* Write 16-bit Reg */
LCD_WriteData(LCD_RegValue);
}
/*******************************************************************************
* Function Name : LCD_WriteReg
* Description : Reads the selected LCD Register.
* Input : None
* Output : None
* Return : LCD Register Value.
* Attention : None
*******************************************************************************/
static __inline uint16_t LCD_ReadReg(uint16_t LCD_Reg)
{
uint16_t LCD_RAM;
/* Write 16-bit Index (then Read Reg) */
LCD_WriteIndex(LCD_Reg);
/* Read 16-bit Reg */
LCD_RAM = LCD_ReadData();
return LCD_RAM;
}
/*******************************************************************************
* Function Name : LCD_SetCursor
* Description : Sets the cursor position.
* Input : - Xpos: specifies the X position.
* - Ypos: specifies the Y position.
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
static void LCD_SetCursor( uint16_t Xpos, uint16_t Ypos )
{
#if ( DISP_ORIENTATION == 90 ) || ( DISP_ORIENTATION == 270 )
uint16_t temp = Xpos;
Xpos = Ypos;
Ypos = ( MAX_X - 1 ) - temp;
#elif ( DISP_ORIENTATION == 0 ) || ( DISP_ORIENTATION == 180 )
#endif
switch( LCD_Code )
{
default: /* 0x9320 0x9325 0x9328 0x9331 0x5408 0x1505 0x0505 0x7783 0x4531 0x4535 */
LCD_WriteReg(0x0020, Xpos );
LCD_WriteReg(0x0021, Ypos );
break;
case SSD1298: /* 0x8999 */
case SSD1289: /* 0x8989 */
LCD_WriteReg(0x004e, Xpos );
LCD_WriteReg(0x004f, Ypos );
break;
case HX8347A: /* 0x0047 */
case HX8347D: /* 0x0047 */
LCD_WriteReg(0x02, Xpos>>8 );
LCD_WriteReg(0x03, Xpos );
LCD_WriteReg(0x06, Ypos>>8 );
LCD_WriteReg(0x07, Ypos );
break;
case SSD2119: /* 3.5 LCD 0x9919 */
break;
}
}
/*******************************************************************************
* Function Name : LCD_Delay
* Description : Delay Time
* Input : - nCount: Delay Time
* Output : None
* Return : None
* Return : None
* Attention : None
*******************************************************************************/
static void delay_ms(uint16_t ms)
{
uint16_t i,j;
for( i = 0; i < ms; i++ )
{
for( j = 0; j < 1141; j++ );
}
}
/*******************************************************************************
* Function Name : LCD_Initializtion
* Description : Initialize TFT Controller.
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void LCD_Initializtion(void)
{
uint16_t DeviceCode;
LCD_Configuration();
DeviceCode = LCD_ReadReg(0x0000); /* 读取屏ID */
/* 不同屏驱动IC 初始化不同 */
if( DeviceCode == 0x9325 || DeviceCode == 0x9328 )
{
LCD_Code = ILI9325;
LCD_WriteReg(0x00e7,0x0010);
LCD_WriteReg(0x0000,0x0001); /* start internal osc */
LCD_WriteReg(0x0001,0x0100);
LCD_WriteReg(0x0002,0x0700); /* power on sequence */
LCD_WriteReg(0x0003,(1<<12)|(1<<5)|(1<<4)|(0<<3) ); /* importance */
LCD_WriteReg(0x0004,0x0000);
LCD_WriteReg(0x0008,0x0207);
LCD_WriteReg(0x0009,0x0000);
LCD_WriteReg(0x000a,0x0000); /* display setting */
LCD_WriteReg(0x000c,0x0001); /* display setting */
LCD_WriteReg(0x000d,0x0000);
LCD_WriteReg(0x000f,0x0000);
/* Power On sequence */
LCD_WriteReg(0x0010,0x0000);
LCD_WriteReg(0x0011,0x0007);
LCD_WriteReg(0x0012,0x0000);
LCD_WriteReg(0x0013,0x0000);
delay_ms(50); /* delay 50 ms */
LCD_WriteReg(0x0010,0x1590);
LCD_WriteReg(0x0011,0x0227);
delay_ms(50); /* delay 50 ms */
LCD_WriteReg(0x0012,0x009c);
delay_ms(50); /* delay 50 ms */
LCD_WriteReg(0x0013,0x1900);
LCD_WriteReg(0x0029,0x0023);
LCD_WriteReg(0x002b,0x000e);
delay_ms(50); /* delay 50 ms */
LCD_WriteReg(0x0020,0x0000);
LCD_WriteReg(0x0021,0x0000);
delay_ms(50); /* delay 50 ms */
LCD_WriteReg(0x0030,0x0007);
LCD_WriteReg(0x0031,0x0707);
LCD_WriteReg(0x0032,0x0006);
LCD_WriteReg(0x0035,0x0704);
LCD_WriteReg(0x0036,0x1f04);
LCD_WriteReg(0x0037,0x0004);
LCD_WriteReg(0x0038,0x0000);
LCD_WriteReg(0x0039,0x0706);
LCD_WriteReg(0x003c,0x0701);
LCD_WriteReg(0x003d,0x000f);
delay_ms(50); /* delay 50 ms */
LCD_WriteReg(0x0050,0x0000);
LCD_WriteReg(0x0051,0x00ef);
LCD_WriteReg(0x0052,0x0000);
LCD_WriteReg(0x0053,0x013f);
LCD_WriteReg(0x0060,0xa700);
LCD_WriteReg(0x0061,0x0001);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -