/* Includes ------------------------------------------------------------------*/
#include "GLCD1.h"
//#include "HzLib.h"
#include "AsciiLib.h"
#include ‹math.h›
/* Private variables ---------------------------------------------------------*/
static uint16_t DeviceCode;
static uint16_t TimerPeriod = 0;
static uint16_t Channel2Pulse = 1000;
/* Private define ------------------------------------------------------------*/
/* 使用总线方式时定义地址 */
/* 挂在不同的BANK,使用不同地址线时请自行换算地址 */
#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* RS = 0 */
#define LCD_RAM (*((volatile unsigned short *) 0x60020000)) /* RS = 1 */
#define B_N 0x0F
#define B_P 0xFF
/************************************************** *****************************
* Function Name : LCD_CtrlLinesConfig
* Description : Configures LCD Control lines (FSMC Pins) in alternate function
Push-Pull mode.
* Input : None
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
static void LCD_CtrlLinesConfig(void)
{
// GPIO_InitTypeDef GPIO_InitStructure;
/* Enable FSMC, GPIOD, GPIOE and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
/* PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9),
PE.13(D10), PE.14(D11), PE.15(D12) */
GPIOE-›CRL|=GPIO_CRL_MODE7;
GPIOE-›CRL&=~GPIO_CRL_CNF7_0;
GPIOE-›CRL|=GPIO_CRL_CNF7_1;
GPIOE-›CRH&=~(GPIO_CRH_CNF8_0|GPIO_CRH_CNF9_0|GPIO_CRH_CNF10_ 0|GPIO_CRH_CNF11_0|GPIO_CRH_CNF12_0|GPIO_CRH_CNF13 _0|GPIO_CRH_CNF14_0|GPIO_CRH_CNF15_0);
GPIOE-›CRH|=GPIO_CRH_CNF8_1|GPIO_CRH_CNF9_1|GPIO_CRH_CNF1 0_1|GPIO_CRH_CNF11_1|GPIO_CRH_CNF12_1|GPIO_CRH_CNF 13_1|GPIO_CRH_CNF14_1|GPIO_CRH_CNF15_1;
GPIOE-›CRH|=GPIO_CRH_MODE8|GPIO_CRH_MODE9|GPIO_CRH_MODE10 |GPIO_CRH_MODE11|GPIO_CRH_MODE12|GPIO_CRH_MODE13|G PIO_CRH_MODE14|GPIO_CRH_MODE15;
/*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | 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_AF_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);*/
/* PD.00(D2), PD.01(D3), PD.04(RD), PD.5(WR), PD.7(CS), PD.8(D13), PD.9(D14),
PD.10(D15), PD.11(RS) PD.14(D0) PD.15(D1) */
GPIOD-›CRL&=~(GPIO_CRL_CNF0_0|GPIO_CRL_CNF1_0|GPIO_CRL_CNF4_0 |GPIO_CRL_CNF5_0|GPIO_CRL_CNF7_0);
GPIOD-›CRL|=(GPIO_CRL_CNF0_1|GPIO_CRL_CNF1_1|GPIO_CRL_CNF 4_1|GPIO_CRL_CNF5_1|GPIO_CRL_CNF7_1);
GPIOD-›CRH&=~(GPIO_CRH_CNF8_0|GPIO_CRH_CNF9_0|GPIO_CRH_CNF10_ 0|GPIO_CRH_CNF11_0|GPIO_CRH_CNF14_0|GPIO_CRH_CNF15 _0);
GPIOD-›CRH|=GPIO_CRH_CNF8_1|GPIO_CRH_CNF9_1|GPIO_CRH_CNF1 0_1|GPIO_CRH_CNF11_1|GPIO_CRH_CNF14_1|GPIO_CRH_CNF 15_1;
GPIOD-›CRL|=GPIO_CRL_MODE0|GPIO_CRL_MODE1|GPIO_CRL_MODE4| GPIO_CRL_MODE5|GPIO_CRL_MODE7;
GPIOD-›CRH|=GPIO_CRH_MODE8|GPIO_CRH_MODE9|GPIO_CRH_MODE10 |GPIO_CRH_MODE11|GPIO_CRH_MODE14|GPIO_CRH_MODE15;
/*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 |
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);*/
}
/************************************************** *****************************
* Function Name : LCD_FSMCConfig
* Description : Configures the Parallel interface (FSMC) for LCD(Parallel mode)
* Input : None
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
static void LCD_FSMCConfig(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef FSMC_NORSRAMTimingInitStructure;
/* FSMC读速度设置 */
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupT ime = 30; /* 地址建立时间 */
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTi me = 0;
FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime = 30; /* 数据建立时间 */
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAround Duration = 0x00;
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 0x00;
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency = 0x00;
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A; /* FSMC 访问模式 */
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStru ct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* FSMC写速度设置 */
FSMC_NORSRAMTimingInitStructure.FSMC_AddressSetupT ime =10; /* 地址建立时间 */
FSMC_NORSRAMTimingInitStructure.FSMC_AddressHoldTi me =0;
FSMC_NORSRAMTimingInitStructure.FSMC_DataSetupTime = 10; /* 数据建立时间 */
FSMC_NORSRAMTimingInitStructure.FSMC_BusTurnAround Duration = 0x00;
FSMC_NORSRAMTimingInitStructure.FSMC_CLKDivision = 0x00;
FSMC_NORSRAMTimingInitStructure.FSMC_DataLatency = 0x00;
FSMC_NORSRAMTimingInitStructure.FSMC_AccessMode = FSMC_AccessMode_A; /* FSMC 访问模式 */
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &FSMC_NORSRAMTimingInitStructure;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* Enable FSMC Bank1_SRAM Bank */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
/************************************************** *****************************
* Function Name : LCD_Configuration
* Description : Configure the LCD Control pins and FSMC Parallel interface
* Input : None
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
static void LCD_Configuration(void)
{
/* Configure the LCD Control pins --------------------------------------------*/
LCD_CtrlLinesConfig();
/* Configure the FSMC Parallel interface -------------------------------------*/
LCD_FSMCConfig();
}
/************************************************** *****************************
* 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(uint8_t LCD_Reg,uint16_t LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
LCD_REG = LCD_Reg;
/* Write 16-bit Reg */
LCD_RAM = 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(uint8_t LCD_Reg)
{
/* Write 16-bit Index (then Read Reg) */
LCD_REG = LCD_Reg;
/* Read 16-bit Reg */
return (LCD_RAM);
}
/************************************************** *****************************
* Function Name : LCD_WriteRAM_Prepare
* Description : Prepare to write to the LCD RAM.
* Input : None
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
static __inline void LCD_WriteRAM_Prepare(void)
{
LCD_REG = R34;
}
/************************************************** *****************************
* Function Name : LCD_WriteRAM
* Description : Writes to the LCD RAM.
* Input : - RGB_Code: the pixel color in RGB mode (5-6-5).
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
static __inline void LCD_WriteRAM(uint16_t RGB_Code)
{
/* Write 16-bit GRAM Reg */
LCD_RAM = RGB_Code;
}
/************************************************** *****************************
* Function Name : LCD_ReadRAM
* Description : Reads the LCD RAM.
* Input : None
* Output : None
* Return : LCD RAM Value.
* Attention : None
************************************************** *****************************/
static __inline uint16_t LCD_ReadRAM(void)
{
volatile uint16_t dummy;
/* Write 16-bit Index (then Read Reg) */
LCD_REG = R34; /* Select GRAM Reg */
/* Read 16-bit Reg */
dummy = LCD_RAM;
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(DeviceCode==0x8989)
{
LCD_WriteReg(0x004e,Xpos); /* Row */
LCD_WriteReg(0x004f,Ypos); /* Line */
}
else if(DeviceCode==0x9919)
{
LCD_WriteReg(0x004e,Xpos); /* Row */
LCD_WriteReg(0x004f,Ypos); /* Line */
}
else
{
LCD_WriteReg(0x0020,Xpos); /* Row */
LCD_WriteReg(0x0021,Ypos); /* Line */
}
}
/************************************************** *****************************
* Function Name : LCD_Delay
* Description : Delay Time
* Input : - nCount: Delay Time
* Output : None
* Return : None
* Return : None
* Attention : None
************************************************** *****************************/
static void LCD_Delay(uint16_t nCount)
{
uint16_t TimingDelay;
while(nCount--)
{
for(TimingDelay=0;TimingDelay‹10000;TimingDelay++);
}
}
/************************************************** *****************************
* Function Name : LCD_Initializtion
* Description : Initialize TFT Controller.
* Input : None
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void LCD_Initializtion()
{
GPIOE-›BSRR|=GPIO_BSRR_BS1;
LCD_Delay(10);
GPIOE-›BSRR|=GPIO_BSRR_BR1;
LCD_Delay(10);
GPIOE-›BSRR|=GPIO_BSRR_BS1;
LCD_Delay(10);
LCD_Configuration();
LCD_Delay(10); /* delay 50 ms */
DeviceCode = LCD_ReadReg(0x0000); /* 读取屏ID */
//DeviceCode=0x1289;
if(DeviceCode==0x9325||DeviceCode==0x9328) /* 不同屏驱动IC 初始化不同 */
{
LCD_WriteReg(0xE5, 0x78F0); /* set SRAM internal timing */
LCD_WriteReg(0x01, 0x0100); /* set Driver Output Control */
LCD_WriteReg(0x02, 0x0700); /* set 1 line inversion */
LCD_WriteReg(0x03, 0x1030); /* set GRAM write direction and BGR=1 */
LCD_WriteReg(0x04, 0x0000); /* Resize register */
LCD_WriteReg(0x08, 0x0207); /* set the back porch and front porch */
LCD_WriteReg(0x09, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
LCD_WriteReg(0x0A, 0x0000); /* FMARK function */
LCD_WriteReg(0x0C, 0x0000); /* RGB interface setting */
LCD_WriteReg(0x0D, 0x0000); /* Frame marker Position */
LCD_WriteReg(0x0F, 0x0000); /* RGB interface polarity */
/*************Power On sequence ****************/
LCD_WriteReg(0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
LCD_WriteReg(0x11, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
LCD_WriteReg(0x12, 0x0000); /* VREG1OUT voltage */
LCD_WriteReg(0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
LCD_WriteReg(0x07, 0x0001);
LCD_Delay(200);
/* Dis-charge capacitor power voltage */
LCD_WriteReg(0x10, 0x1090); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
LCD_WriteReg(0x11, 0x0227); /* Set DC1[2:0], DC0[2:0], VC[2:0] */
LCD_Delay(50); /* Delay 50ms */
LCD_WriteReg(0x12, 0x001F);
LCD_Delay(50); /* Delay 50ms */
LCD_WriteReg(0x13, 0x1500); /* VDV[4:0] for VCOM amplitude */
LCD_WriteReg(0x29, 0x0027); /* 04 VCM[5:0] for VCOMH */
LCD_WriteReg(0x2B, 0x000D); /* Set Frame Rate */
LCD_Delay(50); /* Delay 50ms */
LCD_WriteReg(0x20, 0x0000); /* GRAM horizontal Address */
LCD_WriteReg(0x21, 0x0000); /* GRAM Vertical Address */
/* ----------- Adjust the Gamma Curve ---------- */
LCD_WriteReg(0x30, 0x0000);
LCD_WriteReg(0x31, 0x0707);
LCD_WriteReg(0x32, 0x0307);
LCD_WriteReg(0x35, 0x0200);
LCD_WriteReg(0x36, 0x0008);
LCD_WriteReg(0x37, 0x0004);
LCD_WriteReg(0x38, 0x0000);
LCD_WriteReg(0x39, 0x0707);
LCD_WriteReg(0x3C, 0x0002);
LCD_WriteReg(0x3D, 0x1D04);
/* ------------------ Set GRAM area --------------- */
LCD_WriteReg(0x50, 0x0000); /* Horizontal GRAM Start Address */
LCD_WriteReg(0x51, 0x00EF); /* Horizontal GRAM End Address */
LCD_WriteReg(0x52, 0x0000); /* Vertical GRAM Start Address */
LCD_WriteReg(0x53, 0x013F); /* Vertical GRAM Start Address */
LCD_WriteReg(0x60, 0xA700); /* Gate Scan Line */
LCD_WriteReg(0x61, 0x0001); /* NDL,VLE, REV */
LCD_WriteReg(0x6A, 0x0000); /* set scrolling line */
/* -------------- Partial Display Control --------- */
LCD_WriteReg(0x80, 0x0000);
LCD_WriteReg(0x81, 0x0000);
LCD_WriteReg(0x82, 0x0000);
LCD_WriteReg(0x83, 0x0000);
LCD_WriteReg(0x84, 0x0000);
LCD_WriteReg(0x85, 0x0000);
/* -------------- Panel Control ------------------- */
LCD_WriteReg(0x90, 0x0010);
LCD_WriteReg(0x92, 0x0600);
LCD_WriteReg(0x07, 0x0133); /* 262K color and display ON */
LCD_Delay(5); /* delay 50 ms */
}
/************************************************** ****************************
* Function Name : LCD_SetWindows
* Description : Sets Windows Area.
* Input : - StartX: Row Start Coordinate
* - StartY: Line Start Coordinate
* - xLong:
* - yLong:
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void LCD_SetWindows(uint16_t xStart,uint16_t yStart,uint16_t xLong,uint16_t yLong)
{
LCD_SetCursor(xStart,yStart);
LCD_WriteReg(0x0050,xStart); /* 水平GRAM起始位置 */
LCD_WriteReg(0x0051,xStart+xLong-1); /* 水平GRAM终止位置 */
LCD_WriteReg(0x0052,yStart); /* 垂直GRAM起始位置 */
LCD_WriteReg(0x0053,yStart+yLong-1); /* 垂直GRAM终止位置 */
}
/************************************************** *****************************
* Function Name : LCD_Clear
* Description : 将屏幕填充成指定的颜色,如清屏,则填充 0xffff
* Input : - Color: Screen Color
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void LCD_Clear2(uint16_t xStart,uint16_t yStart,uint16_t xLong,uint16_t yLong,uint16_t Color)
{
uint32_t index=0;
LCD_SetCursor(xStart,yStart);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for(index=0;index‹(xLong*yLong);index++)
{
LCD_RAM=Color;
}
}
void LCD_Clear(uint16_t Color)
{
uint32_t index=0;
LCD_SetCursor(0,0);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for(index=0;index‹76800;index++)
{
LCD_RAM=Color;
}
}
/************************************************** ****************************
* Function Name : LCD_GetPoint
* Description : 获取指定座标的颜色值
* Input : - Xpos: Row Coordinate
* - Xpos: Line Coordinate
* Output : None
* Return : Screen Color
* Attention : None
************************************************** *****************************/
uint16_t LCD_GetPoint(uint16_t Xpos,uint16_t Ypos)
{
LCD_SetCursor(Xpos,Ypos);
if( DeviceCode==0x7783 || DeviceCode==0x4531 || DeviceCode==0x8989 )
return ( LCD_ReadRAM() );
else
return ( LCD_BGR2RGB(LCD_ReadRAM()) );
}
/************************************************** ****************************
* Function Name : LCD_SetPoint
* Description : 在指定座标画点
* Input : - Xpos: Row Coordinate
* - Ypos: Line Coordinate
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void LCD_SetPoint(uint16_t Xpos,uint16_t Ypos,uint16_t point)
{
if ( ( Xpos › 239 ) ||( Ypos › 319 ) ) return;
LCD_SetCursor(Xpos,Ypos);
LCD_WriteRAM_Prepare();
LCD_WriteRAM(point);
}
/************************************************** ****************************
* Function Name : LCD_DrawPicture
* Description : 在指定坐标范围显示一副图片
* Input : - StartX: Row Start Coordinate
* - StartY: Line Start Coordinate
* - EndX: Row End Coordinate
* - EndY: Line End Coordinate
* Output : None
* Return : None
* Attention : 图片取模格式为水平扫描,16位颜色模式
************************************************** *****************************/
void LCD_DrawPicture(uint16_t StartX,uint16_t StartY,const uint8_t *pic)
{
uint32_t i;
uint32_t BMPSize;
uint32_t Post;
BMPSize=(uint32_t)(*(pic+2))+(uint32_t)((*(pic+3))‹‹8);
LCD_WriteReg(R3, 0x1008);
//LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_SetCursor(StartX,StartY);
LCD_WriteRAM_Prepare();
for (i=4;i‹BMPSize;i+=2)
{
Post=(uint16_t)(*(pic+i))+(uint16_t)((*(pic+i+1))‹‹8);
LCD_WriteRAM(Post);
}
LCD_WriteReg(R3, 0x1018);
}
void LCD_DrawPicture_Color(uint16_t StartX,uint16_t StartY,const uint8_t *pic,uint16_t bkColor)
{
uint32_t i;
uint32_t BMPSize;
uint32_t Post;
BMPSize=(uint32_t)(*(pic+2))+(uint32_t)((*(pic+3))‹‹8);
LCD_WriteReg(R3, 0x1008);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_SetCursor(StartX,StartY);
LCD_WriteRAM_Prepare();
for (i=4;i‹BMPSize;i+=2)
{
Post=(uint16_t)(*(pic+i))+(uint16_t)((*(pic+i+1))‹‹8);
if (Post!=0x7BEF)
if(Post!=0xFFFF)
Post=bkColor;
LCD_WriteRAM(Post);
}
LCD_WriteReg(R3, 0x1018);
}
void LCD_Resize_Picture(uint16_t StartX,uint16_t StartY,const uint8_t *pic,uint8_t factor)
{
/*LCD_WriteReg(0x0004,factor);
LCD_DrawPicture(StartX,StartY,pic);
LCD_WriteReg(0x0004,0X00);*/
uint32_t i;
uint32_t BMPSize;
uint32_t Post;
BMPSize=(uint32_t)(*(pic+2))+(uint32_t)((*(pic+3))‹‹8);
LCD_WriteReg(R3, 0x1008);
//LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_SetCursor(StartX,StartY);
LCD_WriteRAM_Prepare();
for (i=4;i‹BMPSize;i+=4)
{
Post=(uint16_t)(*(pic+i))+(uint16_t)((*(pic+i+1))‹‹8);
LCD_WriteRAM(Post);
if (i%160==0)
i+=160;
}
LCD_WriteReg(R3, 0x1018);
}
void LCD_DrawLogo(uint16_t StartX,uint16_t StartY,const uint8_t *pic)
{
uint32_t i;
uint32_t BMPSize;
uint32_t Post;
BMPSize=(uint32_t)(*(pic+2))+(uint32_t)((*(pic+3))‹‹8)+(uint32_t)((*(pic+4))‹‹16)+(uint32_t)((*(pic+5))‹‹24);
LCD_WriteReg(R3, 0x1008);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_SetCursor(StartX,StartY);
LCD_WriteRAM_Prepare();
for (i=6;i‹BMPSize;i+=2)
{
Post=(uint16_t)(*(pic+i))+(uint16_t)((*(pic+i+1))‹‹8);
LCD_WriteRAM(Post);
}
LCD_WriteReg(R3, 0x1018);
}
/************************************************** ****************************
* Function Name : LCD_DrawLine
* Description : 画一条直线
* Input : - x1: 行座标开始
* - y1: 列座标开始
* - x2: 行座标结束
* - y2: 列座标结束
* - bkColor: 背景颜色
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void LCD_DrawLine(int x1, int y1, int x2, int y2,uint16_t bkColor)
{
int x,y,dx,dy,Dx,Dy,e,i;
Dx=x2-x1;
Dy=y2-y1;
dx=fabs(x2-x1);
dy=fabs(y2-y1);
x=x1;
y=y1;
if(dy›dx)
{
e=-dy;
for(i=0;i‹dy;i++)
{
LCD_SetPoint(x,y,bkColor);
if(Dy›=0) y++;
else y--;
e+=2*dx;
if(e›=0)
{
if(Dx›=0) x++;
else x--;
e-=2*dy;
}
}
}
else
{
e=-dx;
for(i=0;i‹dx;i++)
{
LCD_SetPoint(x,y,bkColor);
if(Dx›=0) x++;
else x--;
e+=2*dy;
if(e›=0)
{
if(Dy›=0) y++;
else y--;
e-=2*dx;
}
}
}
}
void LCD_DrawRec(uint16_t x1,uint16_t y1, uint16_t x2, uint16_t y2,uint16_t bkColor)
{
LCD_DrawLine(x1,y1,x1,y2,bkColor);
LCD_DrawLine(x1,y2,x2,y2,bkColor);
LCD_DrawLine(x2,y2,x2,y1,bkColor);
LCD_DrawLine(x2,y1,x1,y1,bkColor);
}
void LCD_DrawRecFill(uint16_t x1,uint16_t y1, uint16_t x2, uint16_t y2,uint16_t bkColor,uint16_t bkColorFill)
{
uint16_t i;
LCD_DrawLine(x1,y1,x1,y2,bkColor);
LCD_DrawLine(x1,y2,x2,y2,bkColor);
LCD_DrawLine(x2,y2,x2,y1,bkColor);
LCD_DrawLine(x2,y1,x1,y1,bkColor);
if ((x1-x2)‹0)
{
if ((y1-y2)‹0)
{
for (i=x1+1;i‹x2;i++)
LCD_DrawLine(i,y1+1,i,y2,bkColorFill);
}
else
{
for (i=x1+1;i‹x2;i++)
LCD_DrawLine(i,y1-1,i,y2,bkColorFill);
}
}
else
{
if ((y1-y2)‹0)
{
for (i=x1-1;i›x2;i--)
LCD_DrawLine(i,y1+1,i,y2,bkColorFill);
}
else
{
for (i=x1-1;i›x2;i--)
LCD_DrawLine(i,y1-1,i,y2,bkColorFill);
}
}
}
void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius,uint16_t bkColor)
{
int32_t D;/* Decision Variable */
uint32_t CurX;/* Current X Value */
uint32_t CurY;/* Current Y Value */
D = 3 - (Radius ‹‹ 1);
CurX = 0;
CurY = Radius;
while (CurX ‹= CurY)
{
LCD_SetCursor(Xpos + CurX, Ypos + CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos + CurX, Ypos - CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos - CurX, Ypos + CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos - CurX, Ypos - CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos + CurY, Ypos + CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos + CurY, Ypos - CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos - CurY, Ypos + CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
LCD_SetCursor(Xpos - CurY, Ypos - CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
if (D ‹ 0)
{
D += (CurX ‹‹ 2) + 6;
}
else
{
D += ((CurX - CurY) ‹‹ 2) + 10;
CurY--;
}
CurX++;
}
}
void LCD_DrawLine1(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction,uint16_t bkColor)
{
uint32_t i = 0;
LCD_SetCursor(Xpos, Ypos);
if(Direction == LCD_DIR_HORIZONTAL)
{
for(i = 0; i ‹ Length; i++)
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
Ypos++;
LCD_SetCursor(Xpos, Ypos);
}
}
else
{
for(i = 0; i ‹ Length; i++)
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(bkColor);
Xpos++;
LCD_SetCursor(Xpos, Ypos);
}
}
}
void LCD_DrawFillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius, uint16_t bkColor)
{
int32_t D; /* Decision Variable */
uint32_t CurX;/* Current X Value */
uint32_t CurY;/* Current Y Value */
D = 3 - (Radius ‹‹ 1);
CurX = 0;
CurY = Radius;
while (CurX ‹= CurY)
{
if(CurY › 0)
{
LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL,bkColor);
LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL,bkColor);
}
if(CurX › 0)
{
LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL,bkColor);
LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL,bkColor);
}
if (D ‹ 0)
{
D += (CurX ‹‹ 2) + 6;
}
else
{
D += ((CurX - CurY) ‹‹ 2) + 10;
CurY--;
}
CurX++;
}
LCD_DrawCircle(Xpos, Ypos, Radius,bkColor);
}
void LCD_DrawRaw(uint16_t Xpos,uint16_t Ypos, uint16_t Xend, uint16_t Yend,uint16_t bkColor,uint8_t Pix)
{
uint16_t i;
for (i=0;i‹Pix;i++)
{
LCD_DrawLine(Xpos,Ypos-i,Xend,Yend-i,bkColor);
}
}
void LCD_DrawButton(uint16_t Xpos,uint16_t Ypos, uint16_t Xend, uint16_t Yend,uint8_t B,uint16_t BkColor,uint16_t BkColor2,uint16_t BkColor3)
{
if (B == Button_NORM)
{
LCD_DrawRecFill(Xpos,Ypos,Xend,Yend,BkColor2,BkCol or);
//--------------------------------------------------
LCD_DrawLine(Xend,Ypos,Xend,Yend,Blak_Grey2);
LCD_DrawLine(Xend+1,Ypos+1,Xend+1,Yend+1,BkColor2) ;
LCD_DrawLine(Xend,Yend,Xpos,Yend,Blak_Grey2);
LCD_DrawLine(Xend+1,Yend+1,Xpos+1,Yend+1,BkColor2) ;
//--------------------------------------------------
LCD_DrawLine(Xpos,Ypos,Xend,Ypos,White_Grey);
LCD_DrawLine(Xpos+1,Ypos+1,Xend+1,Ypos+1,BkColor3) ;
LCD_DrawLine(Xpos,Ypos,Xpos,Yend,White_Grey);
LCD_DrawLine(Xpos+1,Ypos+1,Xpos+1,Yend+1,BkColor3) ;
}
if (B == Button_PUSH)
{
LCD_DrawRecFill(Xpos,Ypos,Xend,Yend,BkColor2,BkCol or);
//---------------------------------------------
LCD_DrawLine(Xpos,Ypos,Xend,Ypos,Red);
LCD_DrawLine(Xpos+1,Ypos+1,Xend+1,Ypos+1,Red);
LCD_DrawLine(Xpos,Ypos,Xpos,Yend,Red);
LCD_DrawLine(Xpos+1,Ypos+1,Xpos+1,Yend+1,Red);
//--------------------------------------------------
LCD_DrawLine(Xend,Ypos,Xend,Yend,Red);
LCD_DrawLine(Xend+1,Ypos+1,Xend+1,Yend+1,Red);
LCD_DrawLine(Xend,Yend,Xpos,Yend,Red);
LCD_DrawLine(Xend+1,Yend+1,Xpos+1,Yend+1,Red);
}
}
void LCD_PolyLine(pPoint Points, uint16_t PointCount, uint16_t bkColor)
{
int16_t X = 0, Y = 0;
if(PointCount ‹ 2)
{
return;
}
while(--PointCount)
{
X = Points-›X;
Y = Points-›Y;
Points++;
LCD_DrawLine(X, Y, Points-›X, Points-›Y,bkColor);
}
}
#if ASCII_LIB › 0
/************************************************** ****************************
* Function Name : PutChar
* Description : 将Lcd屏上任意位置显示一个字符
* Input : - Xpos: 水平坐标
* - Ypos: 垂直坐标
* - c: 显示的字符
* - charColor: 字符颜色
* - bkColor: 背景颜色
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void PutChar(unsigned short Xpos,unsigned short Ypos,unsigned char c,unsigned short charColor,unsigned short bkColor)
{
unsigned short i=0;
unsigned short j=0;
unsigned char buffer[16];
unsigned char tmp_char=0;
GetASCIICode(buffer,c); /* 取字模数据 */
int count=0;
for (i=0;i‹32;i+=2)
{
tmp_char=buffer[count];
for (j=0;j‹8;j++)
{
if (((tmp_char ›› (7-j))&0x01)== 0x01)
{
LCD_SetPoint(Xpos+i,Ypos-j,charColor); /* 字符颜色 */
}
else
{
LCD_SetPoint(Xpos+i,Ypos-j,bkColor); /* 背景颜色 */
}
}
//
for (j=0;j‹8;j++)
{
if (((tmp_char ›› (7-j))&0x01)== 0x01)
{
LCD_SetPoint(Xpos+(i+1),Ypos-j,charColor); /* 字符颜色 */
}
else
{
LCD_SetPoint(Xpos+(i+1),Ypos-j,bkColor); /* 背景颜色 */
}
}
count++;
}
}
/************************************************** ****************************
* Function Name : GUI_Text
* Description : 在指定座标显示字符串
* Input : - Xpos: 行座标
* - Ypos: 列座标
* - str: 字符串
* - charColor: 字符颜色
* - bkColor: 背景颜色
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
void GUI_Text(uint16_t Xpos, uint16_t Ypos, uint8_t *str,uint16_t Color, uint16_t bkColor)
{
uint8_t TempChar;
do
{
TempChar=*str++;
PutChar(Xpos,Ypos,TempChar,Color,bkColor);
if (Ypos›8)
{
Ypos-=8;
}
else if (Xpos›232)
{
Xpos-=16;
Ypos=0;
}
else
{
Xpos=239;
Ypos=319;
}
}
while (*str!=0);
}
#endif
/************************************************** ****************************
* Function Name : LCD_BGR2RGB
* Description : RRRRRGGGGGGBBBBB 改为 BBBBBGGGGGGRRRRR 格式
* Input : - color: BRG 颜色值
* Output : None
* Return : RGB 颜色值
* Attention : 内部函数调用
************************************************** *****************************/
uint16_t LCD_BGR2RGB(uint16_t color)
{
uint16_t r, g, b, rgb;
b = ( color››0 ) & 0x1f;
g = ( color››5 ) & 0x3f;
r = ( color››11 ) & 0x1f;
rgb = (b‹‹11) + (g‹‹5) + (r‹‹0);
return( rgb );
}
/************************************************** ****************************
* Function Name : LCD_BackLight_Init
* Description : LCD_BackLight Initializtion
* Input : None
* Output : None
* Return : None
* Attention : None
************************************************** *****************************/
/************************************************** ****************************
* Function Name : LCD_BackLight
* Description : 调整液晶背光
* Input : - percent: 背光亮度百分比
* Output : None
* Return : 返回1成功 返回0失败
* Attention : None
************************************************** *****************************/
FunctionalState LCD_BackLight( uint8_t percent)
{
if( percent ‹= 100)
{
Channel2Pulse=percent*10;
//LCD_BackLight_Init();
return ENABLE;
}
else
return DISABLE;
}
/*void LCD_Print_INT(uint16_t X, uint16_t Y,uint8_t temp)
{
uint8_t tmp1,tmp2;
const uint8_t *BMP_temp;
tmp1=temp/100;
if (tmp1!=0)
{
BMP_temp=BMP_seo(tmp1,0);
LCD_SetWindows(X,Y-20,40,20);
LCD_DrawPicture(X,Y-17,BMP_temp);
temp=temp - tmp1*100;
}
tmp2=temp/10;
BMP_temp=BMP_seo(tmp1,0);
if ((tmp1==0) && (tmp2!=0))
{
BMP_temp=BMP_seo(tmp2,0);
LCD_SetWindows(X,Y-20,40,20);
LCD_Clear(White);
LCD_DrawPicture(X,Y-17,BMP_temp);
temp=temp - tmp2*10;
}
else
{
if (tmp1!=0)
{
BMP_temp=BMP_seo(tmp2,0);
LCD_SetWindows(X,Y-43,40,20);
LCD_DrawPicture(X,Y-40,BMP_temp);
temp=temp - tmp2*10;
}
}
BMP_temp=BMP_seo(temp,0);
if (tmp1!=0)
{
LCD_SetWindows(X,Y-66,40,20);
LCD_DrawPicture(X,Y-63,BMP_temp);
}
else
{
LCD_SetWindows(X,Y-43,40,20);
LCD_DrawPicture(X,Y-40,BMP_temp);
}
}*/
void LCD_Print_Code(uint16_t X, uint16_t Y,uint8_t temp,uint8_t sr)
{
if (sr==60)
{
LCD_SetWindows(X,Y,40,25);
LCD_DrawPicture(X,Y+3,BMP_seo(temp,sr));
}
else
if (sr==11)
{
LCD_SetWindows(X,Y,70,50);
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Black );
}
else
if (sr==12)
{
LCD_SetWindows(X,Y,70,50);
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Red);
}
else
if (sr==3)
{
LCD_SetWindows(X,Y,30,22);
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Black );
}
else
if (sr==2)
{
LCD_SetWindows(X,Y,30,22);
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Red);
}
else
if (sr==1)
{
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Green );
}
else
if (sr==4)
{
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Red);
}
else
if (sr==5)
{
LCD_DrawPicture_Color(X,Y+3,BMP_seo(temp,sr),Blue) ;
}
else
LCD_DrawPicture(X,Y+3,BMP_seo(temp,sr));
}
void LCD_Print_term_black(uint16_t X,uint16_t Y, uint16_t temp)
{
uint16_t tmp;
tmp=temp/100;
if (tmp!=0)
{
LCD_SetWindows(X,Y+46,30,22);
LCD_Print_Code(X,Y+46,tmp,3);
}
else
{
LCD_SetWindows(X,Y+46,30,22);
LCD_Clear2(X,Y+46,30,22,White);
}
temp-=tmp*100;
tmp=temp/10;
LCD_SetWindows(X,Y+23,30,22);
LCD_Print_Code(X,Y+23,tmp,3);
temp-=tmp*10;
LCD_SetWindows(X,Y,30,22);
LCD_Print_Code(X,Y,temp,3);
}
void LCD_Print_term_mini(uint16_t X,uint16_t Y, uint8_t temp)
{
uint8_t tmp;
tmp=temp/100;
if (tmp!=0)
{
LCD_SetWindows(X,Y+46,30,22);
LCD_Print_Code(X,Y+46,tmp,2);
}
else
{
LCD_SetWindows(X,Y+46,30,22);
LCD_Clear2(X,Y+46,30,22,White);
}
temp-=tmp*100;
tmp=temp/10;
LCD_SetWindows(X,Y+23,30,22);
LCD_Print_Code(X,Y+23,tmp,2);
temp-=tmp*10;
LCD_SetWindows(X,Y,30,22);
LCD_Print_Code(X,Y,temp,2);
}
void LCD_Print_term(uint16_t X,uint16_t Y, uint16_t temp,uint8_t bkColor)
{
uint16_t tmp;
tmp=temp/100;
if (tmp!=0)
{
LCD_SetWindows(X,Y+62,40,30);
LCD_Print_Code(X,Y+62,tmp,bkColor);
}
else
{
LCD_SetWindows(X,Y+62,40,30);
LCD_Clear2(X,Y+62,40,30,White);
}
temp-=tmp*100;
tmp=temp/10;
LCD_SetWindows(X,Y+31,40,30);
LCD_Print_Code(X,Y+31,tmp,bkColor);
temp-=tmp*10;
LCD_SetWindows(X,Y,40,30);
LCD_Print_Code(X,Y,temp,bkColor);
}
void LCD_Print_Code_Int(uint16_t X,uint16_t Y, uint8_t temp,uint8_t sr)
{
uint8_t tmp;
tmp=temp/10;
if (tmp!=0)
{
LCD_Print_Code(X,Y,tmp,sr);
}
else
{
LCD_SetWindows(X,Y,70,50);
LCD_Clear2(X,Y,70,50,Grey);
}
temp=temp-tmp*10;
LCD_Print_Code(X,Y-53,temp,sr);
}
void LCD_Print_Time(uint16_t X,uint16_t Y, uint8_t Hours, uint8_t Minute)
{
uint8_t tmp;
tmp=Hours/10;
LCD_Print_Code(X,Y,tmp,60);
Hours=Hours-tmp*10;
LCD_Print_Code(X,Y-28,Hours,60);
LCD_SetWindows(X,Y-56,40,25);
LCD_DrawPicture(X,Y-53,gImage_dd);
tmp=Minute/10;
LCD_Print_Code(X,Y-81,tmp,60);
Minute=Minute-tmp*10;
LCD_Print_Code(X,Y-106,Minute,60);
}
void LCD_Print_Time2(uint16_t X,uint16_t Y, uint8_t Hours, uint8_t Minute)
{
uint8_t tmp;
tmp=Hours/10;
LCD_Print_Code(X,Y,tmp,3);
Hours=Hours-tmp*10;
LCD_Print_Code(X,Y-23,Hours,3);
LCD_SetWindows(X,Y-46,30,22);
LCD_DrawPicture(X,Y-49,gImage_dote);
tmp=Minute/10;
LCD_Print_Code(X,Y-69,tmp,3);
Minute=Minute-tmp*10;
LCD_Print_Code(X,Y-92,Minute,3);
}
void LCD_Print_word(uint16_t X, uint16_t Y,uint16_t temp,uint8_t sr)
{
uint8_t tmp1,tmp2,tmp3;
// const uint8_t *BMP_temp;
tmp1=temp/1000;
if (tmp1!=0)
{
if (sr==60)
LCD_Print_Code(X,Y+28,tmp1,60);
else
LCD_Print_Code(X,Y+53,tmp1,sr);
temp=temp - tmp1*1000;
}
tmp2=temp/100;
if (sr==60)
LCD_Print_Code(X,Y,tmp2,60);
else
LCD_Print_Code(X,Y,tmp2,sr);
temp=temp - tmp2*100;
tmp3=temp/10;
if (sr==60)
LCD_Print_Code(X,Y-28,tmp3,60);
else
LCD_Print_Code(X,Y-53,tmp3,sr);
temp=temp - tmp3*10;
if (sr==60)
LCD_Print_Code(X,Y-56,temp,60);
else
LCD_Print_Code(X,Y-106,temp,sr);
}
void LCD_Print_Date(uint16_t X,uint16_t Y,uint8_t day,uint8_t months,uint16_t year)
{
uint8_t tmp;
// 蔓忸?泐溧
LCD_Print_word(X,Y,year,60);
// 蔓忸?疣玟咫栩咫钽?珥嚓? LCD_SetWindows(X,Y-84,40,25);
LCD_DrawPicture(X,Y-81,gImage_trx40);
// 蔓忸?戾?鲟
tmp=months/10;
LCD_Print_Code(X,Y-112,tmp,60);
months=months-tmp*10;
LCD_Print_Code(X,Y-140,months,60);
// 蔓忸?疣玟咫栩咫钽?珥嚓? LCD_SetWindows(X,Y-168,40,25);
LCD_DrawPicture(X,Y-165,gImage_trx40);
// 蔓忸?麒耠?戾?鲟
tmp=day/10;
LCD_Print_Code(X,Y-196,tmp,60);
day=day-tmp*10;
LCD_Print_Code(X,Y-224,day,60);
}
/************************************************** ************************************************** *****
END FILE
************************************************** ************************************************** *****/ |