📄 stm32100e_eval_lcd.c
字号:
{
/* 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);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
for(index = 0; index < 76800; index++)
{
LCD->LCD_RAM = Color;
}
}
/**
* @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)
{
LCD_WriteReg(LCD_REG_32, Xpos);
LCD_WriteReg(LCD_REG_33, Ypos);
}
/**
* @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++)
{
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);
}
}
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)
{
/* 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);
LCD_SetCursor(Xpos, Ypos);
}
/**
* @brief Disables LCD Window mode.
* @param None
* @retval None
*/
void LCD_WindowModeDisable(void)
{
LCD_SetDisplayWindow(239, 0x13F, 240, 320);
LCD_WriteReg(LCD_REG_3, 0x1018);
}
/**
* @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)
{
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);
}
}
}
/**
* @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);
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++;
}
}
/**
* @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));
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);
}
}
}
}
/**
* @brief Displays a bitmap picture loaded in the internal Flash.
* @param BmpAddress: Bmp picture address in the internal Flash.
* @retval None
*/
void LCD_WriteBMP(uint32_t BmpAddress)
{
uint32_t index = 0, size = 0;
/* Read bitmap size */
size = *(__IO uint16_t *) (BmpAddress + 2);
size |= (*(__IO uint16_t *) (BmpAddress + 4)) << 16;
/* Get bitmap data address offset */
index = *(__IO uint16_t *) (BmpAddress + 10);
index |= (*(__IO uint16_t *) (BmpAddress + 12)) << 16;
size = (size - index)/2;
BmpAddress += index;
/* Set GRAM write direction and BGR = 1 */
/* I/D=00 (Horizontal : decrement, Vertical : decrement) */
/* AM=1 (address is updated in vertical writing direction) */
LCD_WriteReg(LCD_REG_3, 0x1008);
LCD_WriteRAM_Prepare();
for(index = 0; index < size; index++)
{
LCD_WriteRAM(*(__IO uint16_t *)BmpAddress);
BmpAddress += 2;
}
/* Set GRAM write direction and BGR = 1 */
/* I/D = 01 (Horizontal : increment, Vertical : decrement) */
/* AM = 1 (address is updated in vertical writing direction) */
LCD_WriteReg(LCD_REG_3, 0x1018);
}
/**
* @brief Displays a full rectangle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Height: rectangle height.
* @param Width: rectangle width.
* @retval None
*/
void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
{
LCD_SetTextColor(TextColor);
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);
Width -= 2;
Height--;
Ypos--;
LCD_SetTextColor(BackColor);
while(Height--)
{
LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
}
LCD_SetTextColor(TextColor);
}
/**
* @brief Displays a full circle.
* @param Xpos: specifies the X position.
* @param Ypos: specifies the Y position.
* @param Radius
* @retval None
*/
void LCD_DrawFullCircle(uint16_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;
LCD_SetTextColor(BackColor);
while (CurX <= CurY)
{
if(CurY > 0)
{
LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
}
if(CurX > 0)
{
LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
}
if (D < 0)
{
D += (CurX << 2) + 6;
}
else
{
D += ((CurX - CurY) << 2) + 10;
CurY--;
}
CurX++;
}
LCD_SetTextColor(TextColor);
LCD_DrawCircle(Xpos, Ypos, Radius);
}
/**
* @brief Displays an uni line (between two points).
* @param x1: specifies the point 1 x position.
* @param y1: specifies the point 1 y position.
* @param x2: specifies the point 2 x position.
* @param y2: specifies the point 2 y position.
* @retval None
*/
void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
curpixel = 0;
deltax = ABS(x2 - x1); /* The difference between the x's */
deltay = ABS(y2 - y1); /* The difference between the y's */
x = x1; /* Start x off at the first pixel */
y = y1; /* Start y off at the first pixel */
if (x2 >= x1) /* The x-values are increasing */
{
xinc1 = 1;
xinc2 = 1;
}
else /* The x-values are decreasing */
{
xinc1 = -1;
xinc2 = -1;
}
if (y2 >= y1) /* The y-values are increasing */
{
yinc1 = 1;
yinc2 = 1;
}
else /* The y-values are decreasing */
{
yinc1 = -1;
yinc2 = -1;
}
if (deltax >= deltay) /* There is at least one x-value for every y-value */
{
xinc1 = 0; /* Don't change the x when numerator >= denominator */
yinc2 = 0; /* Don't change the y for every iteration */
den = deltax;
num = deltax / 2;
numadd = deltay;
numpixels = deltax; /* There are more x-values than y-values */
}
else /* There is at least one y-value for every x-value */
{
xinc2 = 0; /* Don't change the x for every iteration */
yinc1 = 0; /* Don't change the y when numerator >= denominator */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -