📄 mc_stm8s_lcd.c
字号:
switch (Char)
{
case ('\r'):
/* Carriage return */
CharPos++;
ptr++;
break;
case ('\n'):
CharPos = 0;
ptr++;
/* Set cursor to line 2 */
LCD_SendByte(COMMAND_TYPE, LCD_LINE2);
break;
default:
/* Display characters different from (\r, \n) */
LCD_SendByte(DATA_TYPE, Char);
CharPos++;
ptr++;
break;
}
}
}
/**
* @brief Display the Number in decimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 9 (max 1 digit)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintDec2(6);
* @endcode
*/
void LCD_PrintDec1(u8 Number)
{
u8 NbreTmp;
if (Number < (u8)10)
{
/* Display second digit of the number : 10 */
NbreTmp = (u8)(Number / (u8)10);
/* Display last digit of the number : Units */
NbreTmp = (u8)(Number - (u8)((u8)10 * NbreTmp));
LCD_PrintChar((u8)(NbreTmp + (u8)0x30));
}
}
/**
* @brief Display the Number in decimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 99 (max 2 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintDec2(60);
* @endcode
*/
void LCD_PrintDec2(u8 Number)
{
u8 NbreTmp;
if (Number < (u8)100)
{
/* Display second digit of the number : 10 */
NbreTmp = (u8)(Number / (u8)10);
LCD_PrintChar((u8)(NbreTmp + (u8)0x30));
/* Display last digit of the number : Units */
NbreTmp = (u8)(Number - (u8)((u8)10 * NbreTmp));
LCD_PrintChar((u8)(NbreTmp + (u8)0x30));
}
}
/**
* @brief Display the Number in decimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 999 (max 3 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintDec3(879);
* @endcode
*/
void LCD_PrintDec3(u16 Number)
{
u8 Nbre1Tmp;
u8 Nbre2Tmp;
if (Number < (u16)1000)
{
/* Display first digit of the number : 100 */
Nbre1Tmp = (u8)(Number / (u8)100);
LCD_PrintChar((u8)(Nbre1Tmp + (u8)0x30));
/* Display second digit of the number : 10 */
Nbre1Tmp = (u8)(Number - ((u8)100 * Nbre1Tmp));
Nbre2Tmp = (u8)(Nbre1Tmp / (u8)10);
LCD_PrintChar((u8)(Nbre2Tmp + (u8)0x30));
/* Display last digit of the number : Units */
Nbre1Tmp = ((u8)(Nbre1Tmp - (u8)((u8)10 * Nbre2Tmp)));
LCD_PrintChar((u8)(Nbre1Tmp + (u8)0x30));
}
}
/**
* @brief Display the Number in decimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 9999 (max 4 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintDec4(1600);
* @endcode
*/
void LCD_PrintDec4(u16 Number)
{
u16 Nbre1Tmp;
u16 Nbre2Tmp;
if (Number < (u16)10000)
{
/* Display first digit of the number : 1000 */
Nbre1Tmp = (u16)(Number / (u16)1000);
LCD_PrintChar((u8)(Nbre1Tmp + (u8)0x30));
/* Display second digit of the number : 100 */
Nbre1Tmp = (u16)(Number - ((u16)1000 * Nbre1Tmp));
Nbre2Tmp = (u16)(Nbre1Tmp / (u8)100);
LCD_PrintChar((u8)(Nbre2Tmp + (u8)0x30));
/* Display second digit of the number : 10 */
Nbre1Tmp = (u16)(Nbre1Tmp - ((u16)100 * Nbre2Tmp));
Nbre2Tmp = (u16)(Nbre1Tmp / (u16)10);
LCD_PrintChar((u8)(Nbre2Tmp + (u8)0x30));
/* Display last digit of the number : Units */
Nbre1Tmp = ((u16)(Nbre1Tmp - (u16)((u16)10 * Nbre2Tmp)));
LCD_PrintChar((u8)(Nbre1Tmp + (u8)0x30));
}
}
/**
* @brief Display the Number in Hexadecimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 15 (only 1 digit)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintHex1(10);
* @endcode
*/
void LCD_PrintHex1(u8 Number)
{
if (Number < (u8)0x0A)
{
LCD_PrintChar((u8)(Number + (u8)0x30));
}
else
if (Number < (u8)0x10)
{
LCD_PrintChar((u8)(Number + (u8)0x37));
}
else
{
LCD_PrintChar('-');
}
}
/**
* @brief Display the Number in Hexadecimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 255 (max 2 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintHex2(200);
* @endcode
*/
void LCD_PrintHex2(u8 Number)
{
LCD_PrintHex1((u8)(Number >> (u8)4));
LCD_PrintHex1((u8)(Number & (u8)0x0F));
}
/**
* @brief Display the Number in Hexadecimal format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 4095 (max 3 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintHex3(1C4);
* @endcode
*/
void LCD_PrintHex3(u16 Number)
{
LCD_PrintHex1((u8)(Number >> (u8)8));
LCD_PrintHex1((u8)((u8)(Number) >> (u8)4));
LCD_PrintHex1((u8)((u8)(Number) & (u8)0x0F));
}
/**
* @brief Display the Number in binary format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 3 (max 2 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintBin2(2);
* @endcode
*/
void LCD_PrintBin2(u8 Number)
{
LCD_PrintHex1((u8)((u8)(Number & (u8)0x02) >> (u8)1));
LCD_PrintHex1((u8)(Number & (u8)0x01));
}
/**
* @brief Display the Number in binary format at the current cursor position
* @param[in] Number Number to be displayed
* @note Convert only numbers between 0 and 15 (max 4 digits)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* - The cursor position must be set before calling this function
* @par Functions called:
* - LCD_PrintChar
* @par Example:
* @code
* LCD_PrintBin4(15);
* @endcode
*/
void LCD_PrintBin4(u8 Number)
{
LCD_PrintHex1((u8)((u8)(Number & (u8)0x08) >> (u8)3));
LCD_PrintHex1((u8)((u8)(Number & (u8)0x04) >> (u8)2));
LCD_PrintHex1((u8)((u8)(Number & (u8)0x02) >> (u8)1));
LCD_PrintHex1((u8)(Number & (u8)0x01));
}
/**
* @brief Display CGRAM on even address
* @param[in] address Display address
* @param[in] ptrTable Pointer a the CGRAM table to be displayed
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* @par Functions called:
* - LCD_SendByte
* @par Example:
* @code
* LCD_DisplayCGRAM0(0x80);
* @endcode
*/
void LCD_DisplayCGRAM0(u8 address, u8 *ptrTable)
{
u8 u;
/* Set CGRAM Address */
LCD_SendByte(COMMAND_TYPE, (u8)0x40);
u = 32; /* Nb byte in the table */
while (u)
{
LCD_SendByte(DATA_TYPE, ptrTable[32 - u]);
u--;
}
/* Setup Display Address */
LCD_SendByte(COMMAND_TYPE, address);
LCD_SendByte(DATA_TYPE, (u8)0x00);
LCD_SendByte(DATA_TYPE, (u8)0x00);
}
/**
* @brief Display CGRAM on odd address
* @param[in] address Display address
* @param[in] ptrTable Pointer a the CGRAM table to be displayed
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* @par Functions called:
* - LCD_SendByte
* @par Example:
* @code
* LCD_DisplayCGRAM1(0x80);
* @endcode
*/
void LCD_DisplayCGRAM1(u8 address, u8 *ptrTable)
{
u8 u;
/* Set CGRAM Address */
LCD_SendByte(COMMAND_TYPE, (u8)((u8)0x40 | (u8)0x10));
u = 32; /* Nb byte in the table */
while (u)
{
LCD_SendByte(DATA_TYPE, ptrTable[32 - u]);
u--;
}
/* Setup Display Address */
LCD_SendByte(COMMAND_TYPE, (u8)(address + 1));
LCD_SendByte(DATA_TYPE, (u8)0x00);
LCD_SendByte(DATA_TYPE, (u8)0x02);
}
/**
* @brief Display ST logo
* @param[in] address Display address (LINE1:0x80-0x87 and LINE2:0x90-0x97)
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* @par Functions called:
* - LCD_SendByte
* @par Example:
* @code
* LCD_DisplayLogo(0x80);
* @endcode
*/
void LCD_DisplayLogo(u8 address)
{
LCD_DisplayCGRAM0(address, S_CGRAM);
LCD_DisplayCGRAM1(address, T_CGRAM);
}
/**
* @brief Display a string in rolling mode
* @param[in] Line Line used for displaying the text (LCD_LINE1 or LCD_LINE2)
* @param[in] ptr Pointer to the text to display
* @param[in] speed Rolling speed
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* @par Functions called:
* - LCD_SendByte
* - LCD_ClearLine
* - LCD_Delay
* @par Example:
* @code
* u8 *pText;
* pText = "Welcome into the fabulous world of STM8...";
* LCD_RollString(LCD_LINE2, pText, 0xC000);
* @endcode
*/
void LCD_RollString(u8 Line, u8 *ptr, u16 speed)
{
u8 CharPos = 0;
u8 *ptr2;
/* Set cursor position at beginning of line */
LCD_SendByte(COMMAND_TYPE, Line);
ptr2 = ptr;
/* Display each character of the string */
while (*ptr2 != 0)
{
if (*ptr != 0)
{
LCD_SendByte(DATA_TYPE, *ptr);
ptr++;
}
else
{
LCD_SendByte(DATA_TYPE, ' ');
}
CharPos++;
if (CharPos == LCD_LINE_MAX_CHAR)
{
LCD_Delay(speed);
LCD_ClearLine(Line);
LCD_SendByte(COMMAND_TYPE, Line);
CharPos = 0;
ptr2++;
ptr = ptr2;
}
}
}
/**
* @brief Display a string from current position of the LCD cursor
* @param[in] ptr Pointer to the string to display
* @retval void None
* @par Required preconditions:
* - LCD must be enabled
* @par Functions called:
* - LCD_SendByte
* @par Example:
* @code
* LCD_Print("Hello");
* @endcode
*/
void LCD_Print(u8 *ptr) {
while (*ptr) // Display the string */
LCD_SendByte(DATA_TYPE, *ptr++);
}
/**
* @}
*/
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -