📄 stm32l152_eval_glass_lcd.c
字号:
/**
******************************************************************************
* @file stm32l152_eval_glass_lcd.c
* @author MCD Application Team
* @version V4.5.0
* @date 07-March-2011
* @brief This file includes the LCD Glass driver for Pacific Display
* (LCD_PD878, PD878-DP-FH-W-LV-6-RH) Module of STM32L152-EVAL board RevB.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE 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 FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32l152_eval_glass_lcd.h"
/** @addtogroup Utilities
* @{
*/
/** @addtogroup STM32_EVAL
* @{
*/
/** @addtogroup STM32L152_EVAL
* @{
*/
/** @defgroup STM32L152_EVAL_GLASS_LCD
* @brief This file includes the LCD Glass driver for Pacific Display
* (LCD_PD878, PD878-DP-FH-W-LV-6-RH) Module of STM32L152-EVAL board.
* @{
*/
/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Types
* @{
*/
/**
* @}
*/
/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup STM32L152_EVAL_GLASS_LCD_Private_Variables
* @{
*/
/**
@verbatim
================================================================================
GLASS LCD MAPPING
================================================================================
A
-- ----------
X \/ |\ |I /|
F| H | J |B
| \ | / |
--G-- --K--
| /| \ |
E | L | N |C
| / |M \| _
----------- | |DP
D -
A LCD character coding is based on the following matrix:
{ X , F , E , D }
{ I , J , K , N }
{ A , B , C , DP }
{ H , G , L , M }
The character A for example is:
-------------------------------
{ 0 , 1 , 1 , 0 }
{ 0 , 0 , 1 , 0 }
{ 1 , 1 , 1 , 0 }
{ 0 , 1 , 0 , 0 }
-------------------
= 4 D 7 0 hex
=> 'A' = 0x4D70
@endverbatim
*/
/**
* @brief LETTERS AND NUMBERS MAPPING DEFINITION
*/
uint8_t digit[4]; /* Digit LCD RAM buffer */
__I uint16_t mask[4] = {0xF000, 0x0F00, 0x00F0, 0x000F};
__I uint8_t shift[4] = {0x0C, 0x08, 0x04, 0x00};
/* Letters and number map of PD_878 LCD */
__I uint16_t LetterMap[26]=
{
/* A B C D E F G H I */
0x4D70, 0x6469, 0x4111, 0x6449, 0x4911, 0x4910, 0x4171, 0x0D70, 0x6009,
/* J K L M N O P Q R */
0x0451, 0x0B12, 0x0111, 0x8750, 0x8552, 0x4551, 0x4D30, 0x4553, 0x4D32,
/* S T U V W X Y Z */
0x4961, 0x6008, 0x0551, 0x0390, 0x05D2, 0x8282, 0x8208, 0x4281
};
__I uint16_t NumberMap[10]=
{
/* 0 1 2 3 4 5 6 7 8 9 */
0x47D1, 0x0640, 0x4C31, 0x4C61, 0x0D60, 0x4961, 0x4971, 0x4440, 0x4D71, 0x4D61
};
/**
* @}
*/
/** @defgroup STM32L152_EVAL_LCD_Private_Function_Prototypes
* @{
*/
static void Convert(uint8_t* c, Point_Typedef point, Apostrophe_Typedef apostrophe);
static void delay(__IO uint32_t nCount);
static void LCD_GPIOConfig(void);
/**
* @}
*/
/** @defgroup STM32L152_EVAL_LCD_Private_Functions
* @{
*/
/**
* @brief Configures the LCD GLASS relative GPIO port IOs and LCD peripheral.
* @param None
* @retval None
*/
void LCD_GLASS_Init(void)
{
LCD_InitTypeDef LCD_InitStructure;
LCD_GPIOConfig(); /*!< Configure the LCD Glass GPIO pins */
/*!< Configure the LCD interface -------------------------------------------*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_LCD, ENABLE); /*!< Enable LCD APB1 Clock */
LCD_InitStructure.LCD_Prescaler = LCD_Prescaler_8;
LCD_InitStructure.LCD_Divider = LCD_Divider_16;
LCD_InitStructure.LCD_Duty = LCD_Duty_1_4;
LCD_InitStructure.LCD_Bias = LCD_Bias_1_3;
LCD_InitStructure.LCD_VoltageSource = LCD_VoltageSource_Internal;
LCD_Init(&LCD_InitStructure);
/*!< Configure the Pulse On Duration */
LCD_PulseOnDurationConfig(LCD_PulseOnDuration_2);
/*!< Configure the LCD Contrast (3.51V) */
LCD_ContrastConfig(LCD_Contrast_Level_7);
/*!< Wait Until the LCD FCR register is synchronized */
LCD_WaitForSynchro();
/*!< Enable LCD peripheral */
LCD_Cmd(ENABLE);
/*!< Wait Until the LCD is enabled */
while(LCD_GetFlagStatus(LCD_FLAG_ENS) == RESET)
{
}
/*!< Wait Until the LCD Booster is ready */
while(LCD_GetFlagStatus(LCD_FLAG_RDY) == RESET)
{
}
}
/**
* @brief This function writes a char in the LCD RAM.
* @param ch: The character to dispaly.
* @param point: A point to add in front of char.
* This parameter can be one of the following values:
* @arg POINT_OFF: No point to add in front of char.
* @arg POINT_ON: Add a point in front of char.
* @param apostrophe: Flag indicating if a apostrophe has to be add in front
* of displayed character.
* This parameter can be one of the following values:
* @arg APOSTROPHE_OFF: No apostrophe to add in back of char.
* @arg APOSTROPHE_ON: Add an apostrophe in back of char.
* @param position: Position in the LCD of the caracter to write.
* This parameter can be any value in range [0:7].
* @retval None
*/
void LCD_GLASS_DisplayChar(uint8_t* ch, Point_Typedef point, Apostrophe_Typedef apostrophe, uint8_t position)
{
/*!< Wait Until the last LCD RAM update finish */
while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
{
}
/*!< LCD Write Char */
LCD_GLASS_WriteChar(ch, point, apostrophe, position);
/*!< Requesy LCD RAM update */
LCD_UpdateDisplayRequest();
}
/**
* @brief This function writes a char in the LCD RAM.
* @param ptr: Pointer to string to display on the LCD Glass.
* @retval None
*/
void LCD_GLASS_DisplayString(uint8_t* ptr)
{
uint32_t i = 0x00;
/*!< Wait Until the last LCD RAM update finish */
while(LCD_GetFlagStatus(LCD_FLAG_UDR) != RESET)
{
}
/*!< Send the string character by character on lCD */
while ((*ptr != 0) & (i < 8))
{
/*!< Display one character on LCD */
LCD_GLASS_WriteChar(ptr, POINT_OFF, APOSTROPHE_OFF, i);
/*!< Point on the next character */
ptr++;
/*!< Increment the character counter */
i++;
}
/*!< Requesy LCD RAM update */
LCD_UpdateDisplayRequest();
}
/**
* @brief This function writes a char in the LCD RAM.
* @param ch: The character to dispaly.
* @param point: A point to add in front of char.
* This parameter can be one of the following values:
* @arg POINT_OFF : No point to add in front of char.
* @arg POINT_ON : Add a point in front of char.
* @param apostrophe: Flag indicating if a apostrophe has to be add in front
* of displayed character.
* This parameter can be one of the following values:
* @arg APOSTROPHE_OFF : No apostrophe to add in back of char.
* @arg APOSTROPHE_ON : Add an apostrophe in back of char.
* @param position: Position in the LCD of the caracter to write.
* This parameter can be any value in range [0:7].
* @retval None
*/
void LCD_GLASS_WriteChar(uint8_t* ch, Point_Typedef point, Apostrophe_Typedef apostrophe, uint8_t position)
{
uint32_t tmp = 0x00;
Convert(ch, point, apostrophe); /*!< Convert the corresponding character */
switch (position)
{
case 7:
/*!< Clear the corresponding segments (SEG0, SEG1, SEG2, SEG3) */
LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFFFFFF0);
LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFFFFFF0);
LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFFFFFF0);
LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFFFFFF0);
/*!< Write the corresponding segments (SEG0, SEG1, SEG2, SEG3) */
LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(digit[0]);
LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(digit[1]);
LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(digit[2]);
LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(digit[3]);
break;
case 6:
/*!< Clear the corresponding segments (SEG4, SEG5, SEG6, SEG10) */
LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFFFFB8F);
LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFFFFB8F);
LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFFFFB8F);
LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFFFFB8F);
/*!< Write the corresponding segments (SEG4, SEG5, SEG6, SEG10) */
tmp = (((digit[0] & 0x8) << 7) | ((digit[0]& 0x7) << 4));
LCD->RAM[LCD_RAMRegister_0] |= (uint32_t) tmp;
tmp = (((digit[1] & 0x8) << 7) | ((digit[1]& 0x7) << 4));
LCD->RAM[LCD_RAMRegister_2] |= (uint32_t) tmp;
tmp = (((digit[2] & 0x8) << 7) | ((digit[2]& 0x7) << 4));
LCD->RAM[LCD_RAMRegister_4] |= (uint32_t) tmp;
tmp = (((digit[3] & 0x8) << 7) | ((digit[3]& 0x7) << 4));
LCD->RAM[LCD_RAMRegister_6] |= (uint32_t) tmp;
break;
case 5:
/*!< Clear the corresponding segments (SEG11, SEG16, SEG18, SEG19) */
LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFFF2F7FF);
LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFFF2F7FF);
LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFFF2F7FF);
LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFFF2F7FF);
/*!< Write the corresponding segments (SEG11, SEG16, SEG18, SEG19) */
tmp = (((digit[0] & 0x1) << 11) | ((digit[0]& 0x2) << 15) | ((digit[0]& 0xC) << 16));
LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(tmp);
tmp = (((digit[1] & 0x1) << 11) | ((digit[1]& 0x2) << 15) | ((digit[1]& 0xC) << 16));
LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(tmp);
tmp = (((digit[2] & 0x1) << 11) | ((digit[2]& 0x2) << 15) | ((digit[2]& 0xC) << 16));
LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(tmp);
tmp = (((digit[3] & 0x1) << 11) | ((digit[3]& 0x2) << 15) | ((digit[3]& 0xC) << 16));
LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(tmp);
break;
case 4:
/*!< Clear the corresponding segments (SEG20, SEG21, SEG22, SEG23) */
LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0xFF0FFFFF);
LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0xFF0FFFFF);
LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0xFF0FFFFF);
LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0xFF0FFFFF);
/*!< Write the corresponding segments (SEG20, SEG21, SEG22, SEG23) */
LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(digit[0] << 20);
LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(digit[1] << 20);
LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(digit[2] << 20);
LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(digit[3] << 20);
break;
case 3:
/*!< Clear the corresponding segments (SEG28, SEG29, SEG30, SEG31) */
LCD->RAM[LCD_RAMRegister_0] &= (uint32_t)(0x0FFFFFFF);
LCD->RAM[LCD_RAMRegister_2] &= (uint32_t)(0x0FFFFFFF);
LCD->RAM[LCD_RAMRegister_4] &= (uint32_t)(0x0FFFFFFF);
LCD->RAM[LCD_RAMRegister_6] &= (uint32_t)(0x0FFFFFFF);
/*!< Write the corresponding segments (SEG28, SEG29, SEG30, SEG31) */
LCD->RAM[LCD_RAMRegister_0] |= (uint32_t)(digit[0] << 28);
LCD->RAM[LCD_RAMRegister_2] |= (uint32_t)(digit[1] << 28);
LCD->RAM[LCD_RAMRegister_4] |= (uint32_t)(digit[2] << 28);
LCD->RAM[LCD_RAMRegister_6] |= (uint32_t)(digit[3] << 28);
break;
case 2:
/*!< Clear the corresponding segments (SEG32, SEG33, SEG34, SEG35) */
LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFFFF0);
LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFFFF0);
LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFFFF0);
LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFFFF0);
/*!< Write the corresponding segments (SEG32, SEG33, SEG34, SEG35) */
LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)(digit[0] << 0);
LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)(digit[1] << 0);
LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)(digit[2] << 0);
LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)(digit[3] << 0);
break;
case 1:
/*!< Clear the corresponding segments (SEG36, SEG37, SEG38, SEG39) */
LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFFF0F);
LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFFF0F);
LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFFF0F);
LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFFF0F);
/*!< Write the corresponding segments (SEG36, SEG37, SEG38, SEG39) */
LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)(digit[0] << 4);
LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)(digit[1] << 4);
LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)(digit[2] << 4);
LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)(digit[3] << 4);
break;
case 0:
/*!< Clear the corresponding segments (SEG40, SEG41, SEG42, SEG43) */
LCD->RAM[LCD_RAMRegister_1] &= (uint32_t)(0xFFFFF0FF);
LCD->RAM[LCD_RAMRegister_3] &= (uint32_t)(0xFFFFF0FF);
LCD->RAM[LCD_RAMRegister_5] &= (uint32_t)(0xFFFFF0FF);
LCD->RAM[LCD_RAMRegister_7] &= (uint32_t)(0xFFFFF0FF);
/*!< Write the corresponding segments (SEG40, SEG41, SEG42, SEG43) */
LCD->RAM[LCD_RAMRegister_1] |= (uint32_t)(digit[0] << 8);
LCD->RAM[LCD_RAMRegister_3] |= (uint32_t)(digit[1] << 8);
LCD->RAM[LCD_RAMRegister_5] |= (uint32_t)(digit[2] << 8);
LCD->RAM[LCD_RAMRegister_7] |= (uint32_t)(digit[3] << 8);
break;
}
}
/**
* @brief Display a string in scrolling mode
* @note The LCD should be cleared before to start the write operation.
* @param ptr: Pointer to string to display on the LCD Glass.
* @param nScroll: Specifies how many time the message will be scrolled
* @param ScrollSpeed: Speciifes the speed of the scroll.
* Low value gives higher speed.
* @retval None
*/
void LCD_GLASS_ScrollString(uint8_t* ptr, uint16_t nScroll, uint16_t ScrollSpeed)
{
uint8_t Repetition = 0;
uint8_t* ptr1;
uint8_t str[8] = "";
ptr1 = ptr;
LCD_GLASS_DisplayString(ptr1);
delay(ScrollSpeed);
for (Repetition = 0; Repetition < nScroll; Repetition++)
{
*(str + 1) = *ptr1;
*(str + 2) = *(ptr1 + 1);
*(str + 3) = *(ptr1 + 2);
*(str + 4) = *(ptr1 + 3);
*(str + 5) = *(ptr1 + 4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -