📄 91x_lcd.c
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name : 91x_lcd.c
* Author : MCD Application Team
* Date First Issued : 05/18/2006 : Version 1.0
* Description : This file provides all the LCD software functions.
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Standard includes ---------------------------------------------------------*/
#include "91x_lcd.h"
#include "91x_lib.h"
/* Include of other module interface headers ---------------------------------*/
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
vu16 LCDDelay = 0;
extern GPIO_InitTypeDef GPIO_InitStructure;
WDG_InitTypeDef WDG_InitStructure;
/* Private function prototypes -----------------------------------------------*/
/* Interface functions -------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : LCD_Init
* Description : Initializes the LCD driver.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Init(void)
{
/* GPIO8 Clock Enable */
SCU_APBPeriphClockConfig(__GPIO8 ,ENABLE);
GPIO_DeInit(GPIO8);
/* GPIO8 Configuration */
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
GPIO_Init (GPIO8, &GPIO_InitStructure);
/* GPIO9 Clock Enable */
SCU_APBPeriphClockConfig(__GPIO9 ,ENABLE);
GPIO_DeInit(GPIO9);
/* GPIO9 Configuration */
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
GPIO_Init (GPIO9, &GPIO_InitStructure);
GPIO_WriteBit(GPIO9, GPIO_Pin_5, Bit_SET);
/* WDG Clock Enable */
SCU_APBPeriphClockConfig(__WDG, ENABLE);
WDG_DeInit();
// wait 16.12 ms
LCD_Wait(16128);
LCD_Send_Command_8bit(0x38);
// wait 16.12 ms
LCD_Wait(16128);
LCD_Send_Command_8bit(0x38);
// wait 16.12 ms
LCD_Wait(16128);
LCD_Send_Command_8bit(0x38);
// wait 16.12 ms
LCD_Wait(16128);
LCD_Send_Command_8bit(0x0C);
// wait 16.12 ms
LCD_Wait(16128);
LCD_Send_Command_8bit(0x01);
// wait 16.12 ms
LCD_Wait(16128);
}
/*******************************************************************************
* Function name : LCD_Send_Command_8bit
* Description : Sends a command to the LCD.
* Input param : Cmd: command to be sent.
* Output param : None
* Return : None
*******************************************************************************/
void LCD_Send_Command_8bit(u8 Cmd)
{
// Reset RW bit
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_RESET);
// Reset RS bit
GPIO_WriteBit(GPIO9, GPIO_Pin_7, Bit_RESET);
// Set E bit
GPIO_WriteBit(GPIO9, GPIO_Pin_4, Bit_SET);
// Send the command
GPIO_Write(GPIO8, Cmd );
// Reset E bit
GPIO_WriteBit(GPIO9, GPIO_Pin_4, Bit_RESET);
// Set RS bit
GPIO_WriteBit(GPIO9, GPIO_Pin_7, Bit_SET);
// Set RW bit
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_SET);
}
/*******************************************************************************
* Function Name : LCD_SendData_8bit
* Description : Sends data to the LCD.
* Input : Data: data to be displayed.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SendData_8bit(u8 Data)
{
// Set RS bit
GPIO_WriteBit(GPIO9, GPIO_Pin_7, Bit_SET);
// Reset RW bit
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_RESET);
// Set E bit
GPIO_WriteBit(GPIO9, GPIO_Pin_4, Bit_SET);
// Send the data
GPIO_Write(GPIO8,Data);
// Reset E bit
GPIO_WriteBit(GPIO9, GPIO_Pin_4, Bit_RESET);
// Set RS bit
GPIO_WriteBit(GPIO9, GPIO_Pin_7, Bit_RESET);
// Set RW bit
GPIO_WriteBit(GPIO9, GPIO_Pin_6, Bit_SET);
}
/*******************************************************************************
* Function Name : LCD_SendString
* Description : Displays a string on the LCD.
* Input : - pBuffer: pointer to the buffer containing the data to be
* displayed on the LCD.
* - Line: specifies the line where the string will be displayed.
* - Column: specifies the start column from where the string will
* be displayed.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SendString(u8 *pBuffer, u8 Line, u8 Column)
{
u8 len = 0, count = 0;
len = strlen(( const char *)pBuffer);
if((len < (LCD_HALF_LENGTH + 2 - Column)))
{
LCD_SetPosCur(Line, Column);
for(count =0; count < len; count++)
{
LCD_SendData_8bit(pBuffer[count]);
}
}
else
{
LCD_SetPosCur(Line, Column);
for(count = 0; count <= (LCD_HALF_LENGTH-Column); count++)
{
LCD_SendData_8bit(pBuffer[count]);
}
LCD_SetPosCur(2, 1);
for(count = (LCD_HALF_LENGTH-Column+1); count < len; count++)
{
LCD_SendData_8bit(pBuffer[count]);
}
}
}
/*******************************************************************************
* Function Name : LCD_SendStringByStep
* Description : Displays a string on the LCD by step.
* Input : - pBuffer: pointer to the buffer containing the data to be
* displayed on the LCD.
* - Line: specifies the line where the string will be displayed.
* - Column: specifies the start column from where the string will
* be displayed.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SendStringByStep(u8 *pBuffer, u8 Line, u8 Column)
{
u8 len = 0, count = 0;
len = strlen(( const char *)pBuffer);
if(len < ( LCD_HALF_LENGTH + 2 - Column))
{
LCD_SetPosCur(Line, Column);
for(count =0; count < len; count++)
{
// wait 16.12 ms
LCD_Wait(16128);
LCD_SendData_8bit(pBuffer[count]);
}
}
else
{
LCD_SetPosCur(1, Column);
for(count = 0; count <= (LCD_HALF_LENGTH-Column); count++)
{
// wait 16.12 ms
LCD_Wait(16128);
LCD_SendData_8bit(pBuffer[count]);
}
LCD_SetPosCur(2, 1);
for(count = (LCD_HALF_LENGTH-Column+1); count < len; count++)
{
// wait 16.12 ms
LCD_Wait(16128);
LCD_SendData_8bit(pBuffer[count]);
}
}
}
/*******************************************************************************
* Function Name : LCD_SendStringPinPong
* Description : Displays a string on the LCD as ping pong.
* Input : - pBuffer: pointer to the buffer containing the data to be
* displayed on the LCD.
* - Line: specifies the line where the string will be displayed.
* - nTime: number of ping pong.
* Output :
* Return : None
*******************************************************************************/
void LCD_SendStringPinPong(u8 *pBuffer, u8 Line, u32 nTime)
{
u8 len = 0, index = 1;
bool Direction = TRUE;
len = strlen(( const char *)pBuffer);
while(nTime--)
{
if(Direction)
{
LCD_SendString(pBuffer, Line, index);
// wait 16.12 ms
LCD_Wait(16128);
index++;
LCD_LineClear(Line);
if(index == (LCD_HALF_LENGTH - len) + 1)
{
Direction = FALSE;
}
}
else
{
LCD_SendString(pBuffer, Line, index);
// wait 16.12 ms
LCD_Wait(16128);
index--;
LCD_LineClear(Line);
if(index == 1)
{
Direction = TRUE;
}
}
}
}
/*******************************************************************************
* Function Name : LCD_SetPosCur
* Description : Sets the line and column position of the LCD cursor.
* Input : - Line: specifies the cursor's line position.
* - Column: specifies cursor's column position.
* Output : None
* Return : None
*******************************************************************************/
void LCD_SetPosCur(u8 Line, u8 Column)
{
if(Line == 1)
{
Column = Column - 1;
}
else
{
Column = Column -1 + 64;
}
LCD_Send_Command_8bit(Column | 0x80);
}
/*******************************************************************************
* Function Name : LCD_Clear
* Description : Clears the LCD display.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Clear(void)
{
/* reset RS bit */
GPIO_WriteBit(GPIO9, GPIO_Pin_7, Bit_RESET);
/* send "DISPLAY CLEAR COMMAND" command */
LCD_Send_Command_8bit(LCD_CMD_CLR_DISP);
// wait 0.629 s
LCD_Wait(629760);
}
/*******************************************************************************
* Function Name : LCD_LineClear
* Description : Clears the LCD specified line.
* Input : Line: line to be cleared.
* Output : None
* Return : None
*******************************************************************************/
void LCD_LineClear(u8 Line)
{
LCD_SetPosCur(Line, 1);
LCD_SendStringByStep(" ", Line, 1);
}
/*******************************************************************************
* Function Name : LCD_DigitDisplay
* Description : Displays a digit on the LCD.
* Input : - Digit: digit to be displayed.
* - Line: specifies the line where the digit will be displayed.
* - Column: specifies the start column from where the digit will
* be displayed.
* Output : None
* Return : None
*******************************************************************************/
void LCD_DigitDisplay(u8 Digit, u8 Line, u8 Column)
{
LCD_SetPosCur(Line, Column);
LCD_SendData_8bit(Digit + 48);
}
/*******************************************************************************
* Function Name : LCD_Wait
* Description : Inserts a time in 祍 .
* Input : nTime: specifies the time-out value.
* Output : None
* Return : None
*******************************************************************************/
void LCD_Wait( u32 nTime)
{
WDG_InitStructure.WDG_Mode = WDG_Mode_Timer;
WDG_InitStructure.WDG_Prescaler = 0xFF;
WDG_InitStructure.WDG_Preload = 3*nTime/10 ;
WDG_InitStructure.WDG_ClockSource = WDG_ClockSource_Apb;
WDG_Init(&WDG_InitStructure);
/* Enable the WDG */
WDG_Cmd(ENABLE);
while (WDG_GetCounter()!=0xFF);
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -