#include "lcd.h"
#include "fonts.h"
static vu16 TextColor = 0x0000, BackColor = 0xFFFF;
/****************************************************************************** *
* Function Name : Delay_LCD
* Description : Inserts a delay time.
* Input : nCount: specifies the delay time length.
* Output : None
* Return : None
******************************************************************************* /
void Delay_LCD(u16 n)
{
u16 i,j;
for (i = 0;i= Height)
{
LCD_WriteReg(R80, (Xpos - Height + 1));
}
else
{
LCD_WriteReg(R80, 0);
}
LCD_WriteReg(R81, Xpos);
if(Ypos >= Width)
{
LCD_WriteReg(R82, (Ypos - Width + 1));
}
else
{
LCD_WriteReg(R82, 0);
}
/* Vertical GRAM End Address */
LCD_WriteReg(R83, Ypos);
LCD_SetCursor(Xpos, Ypos);
}
/****************************************************************************** *
* Function Name : LCD_WindowModeDisable
* Description : Disables LCD Window mode.
* Input : None
* Output : None
* Return : None
******************************************************************************* /
void LCD_WindowModeDisable(void)
{
LCD_SetDisplayWindow(239, 0x13F, 240, 320);
LCD_WriteReg(R3, 0x1018);
}
/****************************************************************************** *
* Function Name : LCD_DrawLine
* Description : Displays a line.
* Input : - Xpos: specifies the X position.
* - Ypos: specifies the Y position.
* - Length: line length.
* - Direction: line direction.
* This parameter can be one of the following values: Vertical
* or Horizontal.
* Output : None
* Return : None
******************************************************************************* /
void LCD_DrawLine(u8 Xpos, u16 Ypos, u16 Length, u8 Direction)
{
u32 i = 0;
LCD_SetCursor(Xpos, Ypos);
if(Direction == Horizontal)
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for(i = 0; i < Length; i++)
{
LCD_WriteRAM(TextColor);
}
}
else
{
for(i = 0; i < Length; i++)
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM(TextColor);
Xpos++;
LCD_SetCursor(Xpos, Ypos);
}
}
}
/****************************************************************************** *
* Function Name : LCD_DrawRect
* Description : Displays a rectangle.
* Input : - Xpos: specifies the X position.
* - Ypos: specifies the Y position.
* - Height: display rectangle height.
* - Width: display rectangle width.
* Output : None
* Return : None
******************************************************************************* /
void LCD_DrawRect(u8 Xpos, u16 Ypos, u8 Height, u16 Width)
{
LCD_DrawLine(Xpos, Ypos, Width, Horizontal);
LCD_DrawLine((Xpos + Height), Ypos, Width, Horizontal);
LCD_DrawLine(Xpos, Ypos, Height, V ertical);
LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, Vertical);
}
/****************************************************************************** *
* Function Name : LCD_DrawCircle
* Description : Displays a circle.
* Input : - Xpos: specifies the X position.
* - Ypos: specifies the Y position.
* - Height: display rectangle height.
* - Width: display rectangle width.
* Output : None
* Return : None
******************************************************************************* /
void LCD_DrawCircle(u8 Xpos, u16 Ypos, u16 Radius)
{
s32 D;
u32 CurX;
u32 CurY;
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(TextColor);
LCD_SetCursor(Xpos + CurX, Ypos - CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
LCD_SetCursor(Xpos - CurX, Ypos + CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
LCD_SetCursor(Xpos - CurX, Ypos - CurY);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
LCD_SetCursor(Xpos + CurY, Ypos + CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
LCD_SetCursor(Xpos + CurY, Ypos - CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
LCD_SetCursor(Xpos - CurY, Ypos + CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
LCD_SetCursor(Xpos - CurY, Ypos - CurX);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ LCD_WriteRAM(TextColor);
if (D < 0)
{
D += (CurX << 2) + 6;
}
else
{
D += ((CurX - CurY) << 2) + 10;
CurY--;
}
CurX++;
}
}
/****************************************************************************** *
* Function Name : LCD_DrawMonoPict
* Description : Displays a monocolor picture.
* Input : - Pict: pointer to the picture array.
* Output : None
* Return : None
******************************************************************************* /
void LCD_DrawMonoPict(uc32 *Pict)
{
u32 index = 0, i = 0;
LCD_SetCursor(0, 319);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for(index = 0; index < 2400; index++)
{
for(i = 0; i < 32; i++)
{
if((Pict[index] & (1 << i)) == 0x00)
{
LCD_WriteRAM(BackColor);
}
else
{
LCD_WriteRAM(TextColor);
}
}
}
}
/****************************************************************************** *
* Function Name : LCD_WriteBMP
* Description : Displays a bitmap picture loaded in the internal Flash.
* Input : - BmpAddress: Bmp picture address in the internal Flash.
* Output : None
* Return : None
******************************************************************************* /
void LCD_WriteBMP(u32 BmpAddress)
{
u32 index = 0, size = 0;
size = *(vu16 *) (BmpAddress + 2);
size |= (*(vu16 *) (BmpAddress + 4)) << 16;
index = *(vu16 *) (BmpAddress + 10);
index |= (*(vu16 *) (BmpAddress + 12)) << 16;
size = (size - index)/2;
BmpAddress += index;
LCD_WriteReg(R3, 0x1008);
LCD_WriteRAM_Prepare();
for(index = 0; index < size; index++)
{
LCD_WriteRAM(*(vu16 *)BmpAddress);
BmpAddress += 2;
}
LCD_WriteReg(R3, 0x1018);
}
/****************************************************************************** *
* 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
******************************************************************************* /
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
{
GPIOB->BRR = 0x0200; //LCD_NCS_LOW();
GPIOB->BRR = 0x0100; //LCD_RS_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOC->ODR = LCD_Reg; //GPIO_Write(LCD_DataPort,LCD_Reg);
GPIOB->BRR = 0x0020; //LCD_NWR_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
GPIOC->ODR = LCD_RegValue; //GPIO_Write(LCD_DataPort,LCD_RegValue);
GPIOB->BRR = 0x0020; //LCD_NWR_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
}
/****************************************************************************** *
* Function Name : LCD_ReadReg
* Description : Reads the selected LCD Register.
* Input : None
* Output : None
* Return : LCD Register Value.
******************************************************************************* /
u16 LCD_ReadReg(u8 LCD_Reg)
{
u16 temp;
GPIOB->BRR = 0x0200; //LCD_NCS_LOW();
GPIOB->BRR = 0x0100; //LCD_RS_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOC->ODR = LCD_Reg; //GPIO_Write(LCD_DataPort,LCD_Reg);
GPIOB->BRR = 0x0020; //LCD_NWR_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
LCD_BusIn();
GPIOB->BRR = 0x0400; //LCD_NRD_LOW();
temp = GPIOC->IDR; //temp=GPIO_ReadInputData(LCD_DataPort);
GPIOB->BSRR = 0x0400; //LCD_NRD_HIGH();
LCD_BusOut();
GPIOB->BSRR = 0x0200; //LCD_NCS_HIGH();
return temp;
}
/****************************************************************************** *
* Function Name : LCD_WriteRAM_Prepare
* Description : Prepare to write to the LCD RAM.
* Input : None
* Return : None
******************************************************************************* /
void LCD_WriteRAM_Prepare(void)
{
GPIOB->BRR = 0x0200; //LCD_NCS_LOW();
GPIOB->BRR = 0x0100; //LCD_RS_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOC->ODR = R34; //GPIO_Write(LCD_DataPort,R34);
GPIOB->BRR = 0x0020; //LCD_NWR_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
GPIOB->BSRR = 0x0200; //LCD_NCS_HIGH();
}
/****************************************************************************** *
* 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
******************************************************************************* /
void LCD_WriteRAM(u16 RGB_Code)
{
GPIOB->BRR = 0x0200; //LCD_NCS_LOW();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOC->ODR = RGB_Code; //GPIO_Write(LCD_DataPort,RGB_Code);
GPIOB->BRR = 0x0020; //LCD_NWR_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
GPIOB->BSRR = 0x0200; //LCD_NCS_HIGH();
}
/****************************************************************************** *
* Function Name : LCD_ReadRAM
* Description : Reads the LCD RAM.
* Input : None
* Return : LCD RAM Value.
******************************************************************************* /
u16 LCD_ReadRAM(void)
{
u16 temp;
GPIOB->BRR = 0x0200; //LCD_NCS_LOW();
GPIOB->BRR = 0x0100; //LCD_RS_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOC->ODR = R34; //GPIO_Write(LCD_DataPort,R34);
GPIOB->BRR = 0x0020; //LCD_NWR_LOW();
GPIOB->BSRR = 0x0020; //LCD_NWR_HIGH();
GPIOB->BSRR = 0x0100; //LCD_RS_HIGH();
LCD_BusIn();
GPIOB->BRR = 0x0400; //LCD_NRD_LOW();
temp = GPIOC->IDR; //temp=GPIO_ReadInputData(LCD_DataPort);
GPIOB->BSRR = 0x0400; //LCD_NRD_HIGH();
LCD_BusOut();
GPIOB->BSRR = 0x0200; //LCD_NCS_HIGH();
return temp;
}
/****************************************************************************** *
* Function Name : LCD_PowerOn
* Description : Power on the LCD.
* Input : None
* Output : None
* Return : None
******************************************************************************* /
void LCD_PowerOn(void)
{
LCD_WriteReg(R16, 0x0000);
LCD_WriteReg(R17, 0x0000);
LCD_WriteReg(R18, 0x0000);
LCD_WriteReg(R19, 0x0000);
Delay_LCD(20);
LCD_WriteReg(R16, 0x17B0);
LCD_WriteReg(R17, 0x0137);
Delay_LCD(5);
LCD_WriteReg(R18, 0x0139);
Delay_LCD(5);
LCD_WriteReg(R19, 0x1d00);
LCD_WriteReg(R41, 0x0013);
Delay_LCD(5);
LCD_WriteReg(R7, 0x0173);
}
/****************************************************************************** *
* Function Name : LCD_DisplayOn
* Description : Enables the Display.
* Input : None
* Output : None
* Return : None
******************************************************************************* /
void LCD_DisplayOn(void)
{
LCD_WriteReg(R7, 0x0173);
}
/****************************************************************************** *
* Function Name : LCD_DisplayOff
* Description : Disables the Display.
* Input : None
* Output : None
* Return : None
******************************************************************************* /
void LCD_DisplayOff(void)
{
LCD_WriteReg(R7, 0x0);
}
/****************************************************************************** *
* Function Name : LCD_CtrlLinesConfig
* Description : Configures LCD Control lines.
Push-Pull mode.
* Input : None
* Output : None
* Return : None
*******************************************************************************
void LCD_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
LCD_BusOut();
GPIOB->BSRR |= 0x0620;
}
/****************************************************************************** *
* Function Name : LCD_BusIn
* Description : Configures the Parallel interface for LCD(PortC)
* Input : None
* Output : None
* Return : None
******************************************************************************* /
void LCD_BusIn(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/****************************************************************************** *
* Function Name : LCD_BusOut
* Description : Configures the Parallel interface for LCD(PortC)
* Input : None
* Output : None
* Return : None
******************************************************************************* /
void LCD_BusOut(void)
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/****************************************************************************** *
* Function Name : LCD_DrawPicture
* Description : Displays a 16 color picture.
* Input : - picture: pointer to the picture array.
* Output : None
* Return : None
******************************************************************************* /
void LCD_DrawPicture(const u8* picture)
{
int index;
LCD_SetCursor(0x00, 0x0000);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for(index = 0; index < 76800; index++)
{
LCD_WriteRAM(picture[2*index+1]<<8|picture[2*index]);
}
}
本文档为【液晶驱动C语言.】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。