📄 stm32100b_eval_lcd.c
字号:
* @retval None
*/
void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
{
*_TextColor = TextColor; *_BackColor = BackColor;
}
/**
* @brief Sets the Text color.
* @param Color: specifies the Text color code RGB(5-6-5).
* @retval None
*/
void LCD_SetTextColor(__IO uint16_t Color)
{
TextColor = Color;
}
/**
* @brief Sets the Background color.
* @param Color: specifies the Background color code RGB(5-6-5).
* @retval None
*/
void LCD_SetBackColor(__IO uint16_t Color)
{
BackColor = Color;
}
/**
* @brief Sets the Text Font.
* @param fonts: specifies the font to be used.
* @retval None
*/
void LCD_SetFont(sFONT *fonts)
{
LCD_Currentfonts = fonts;
}
/**
* @brief Gets the Text Font.
* @param None.
* @retval the used font.
*/
sFONT *LCD_GetFont(void)
{
return LCD_Currentfonts;
}
/**
* @brief Clears the selected line.
* @param Line: the Line to be cleared.
* This parameter can be one of the following values:
* @arg Linex: where x can be 0..n
* @retval None
*/
void LCD_ClearLine(uint8_t Line)
{
uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
/* Send the string character by character on lCD */
while (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width)
{
/* Display one character on LCD */
LCD_DisplayChar(Line, refcolumn, ' ');
/* Decrement the column position by 16 */
refcolumn -= LCD_Currentfonts->Width;
}
}
/**
* @brief Clears the hole LCD.
* @param Color: the color of the background.
* @retval None
*/
void LCD_Clear(uint16_t Color)
{
uint32_t index = 0;
LCD_SetCursor(0x00, 0x013F);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
}
for(index = 0; index < 76800; index++)
{
LCD_WriteRAM(Color);
}
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
}
}
/**
* @brief Sets the cursor position.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @retval None
*/
void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
{
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteReg(LCD_REG_32, Xpos);
LCD_WriteReg(LCD_REG_33, Ypos);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteReg(LCD_REG_66, Xpos);
LCD_WriteReg(LCD_REG_67, ((Ypos & 0x100)>> 8));
LCD_WriteReg(LCD_REG_68, (Ypos & 0xFF));
}
}
/**
* @brief Draws a character on LCD.
* @param Xpos: the Line where to display the character shape.
* @param Ypos: start column address.
* @param c: pointer to the character data.
* @retval None
*/
void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
{
uint32_t index = 0, i = 0;
uint8_t Xaddress = 0;
Xaddress = Xpos;
LCD_SetCursor(Xaddress, Ypos);
for(index = 0; index < LCD_Currentfonts->Height; index++)
{
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
}
for(i = 0; i < LCD_Currentfonts->Width; i++)
{
if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
(((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
{
LCD_WriteRAM(BackColor);
}
else
{
LCD_WriteRAM(TextColor);
}
}
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
}
Xaddress++;
LCD_SetCursor(Xaddress, Ypos);
}
}
/**
* @brief Displays one character (16dots width, 24dots height).
* @param Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* @arg Linex: where x can be 0..9
* @param Column: start column address.
* @param Ascii: character ascii code, must be between 0x20 and 0x7E.
* @retval None
*/
void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
{
Ascii -= 32;
LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
}
/**
* @brief Displays a maximum of 20 char on the LCD.
* @param Line: the Line where to display the character shape .
* This parameter can be one of the following values:
* @arg Linex: where x can be 0..9
* @param *ptr: pointer to string to display on LCD.
* @retval None
*/
void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
{
uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
/* Send the string character by character on lCD */
while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
{
/* Display one character on LCD */
LCD_DisplayChar(Line, refcolumn, *ptr);
/* Decrement the column position by 16 */
refcolumn -= LCD_Currentfonts->Width;
/* Point on the next character */
ptr++;
}
}
/**
* @brief Sets a display window
* @param Xpos: specifies the X buttom left position.
* @param Ypos: specifies the Y buttom left position.
* @param Height: display window height.
* @param Width: display window width.
* @retval None
*/
void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
{
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
/* Horizontal GRAM Start Address */
if(Xpos >= Height)
{
LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
}
else
{
LCD_WriteReg(LCD_REG_80, 0);
}
/* Horizontal GRAM End Address */
LCD_WriteReg(LCD_REG_81, Xpos);
/* Vertical GRAM Start Address */
if(Ypos >= Width)
{
LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
}
else
{
LCD_WriteReg(LCD_REG_82, 0);
}
/* Vertical GRAM End Address */
LCD_WriteReg(LCD_REG_83, Ypos);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteReg(LCD_REG_1, 0xD0);
LCD_WriteReg(LCD_REG_5, 0x14);
LCD_WriteReg(LCD_REG_69, (Xpos - Height + 1));
LCD_WriteReg(LCD_REG_70, Xpos);
LCD_WriteReg(LCD_REG_71, (((Ypos - Width + 1) & 0x100)>> 8));
LCD_WriteReg(LCD_REG_72, ((Ypos - Width + 1) & 0xFF));
LCD_WriteReg(LCD_REG_73, ((Ypos & 0x100)>> 8));
LCD_WriteReg(LCD_REG_74, (Ypos & 0xFF));
}
LCD_SetCursor(Xpos, Ypos);
}
/**
* @brief Disables LCD Window mode.
* @param None
* @retval None
*/
void LCD_WindowModeDisable(void)
{
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_SetDisplayWindow(239, 0x13F, 240, 320);
LCD_WriteReg(LCD_REG_3, 0x1018);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteReg(LCD_REG_1, 0x50);
LCD_WriteReg(LCD_REG_5, 0x04);
}
}
/**
* @brief Displays a line.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Length: line length.
* @param Direction: line direction.
* This parameter can be one of the following values: Vertical or Horizontal.
* @retval None
*/
void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
{
uint32_t i = 0;
LCD_SetCursor(Xpos, Ypos);
if(Direction == LCD_DIR_HORIZONTAL)
{
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
}
for(i = 0; i < Length; i++)
{
LCD_WriteRAM(TextColor);
}
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
}
}
else
{
for(i = 0; i < Length; i++)
{
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
Xpos++;
LCD_SetCursor(Xpos, Ypos);
}
}
}
/**
* @brief Displays a rectangle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Height: display rectangle height.
* @param Width: display rectangle width.
* @retval None
*/
void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
{
LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
}
/**
* @brief Displays a circle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Radius
* @retval None
*/
void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
{
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);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos + CurX, Ypos - CurY);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos - CurX, Ypos + CurY);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos - CurX, Ypos - CurY);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos + CurY, Ypos + CurX);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos + CurY, Ypos - CurX);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos - CurY, Ypos + CurX);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
LCD_SetCursor(Xpos - CurY, Ypos - CurX);
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAMWord(TextColor);
}
else if(LCDType == LCD_HX8312)
{
LCD_WriteRAM(TextColor);
}
if (D < 0)
{
D += (CurX << 2) + 6;
}
else
{
D += ((CurX - CurY) << 2) + 10;
CurY--;
}
CurX++;
}
}
/**
* @brief Displays a monocolor picture.
* @param Pict: pointer to the picture array.
* @retval None
*/
void LCD_DrawMonoPict(const uint32_t *Pict)
{
uint32_t index = 0, i = 0;
LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
{
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
}
for(index = 0; index < 2400; index++)
{
for(i = 0; i < 32; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -