📄 stm3210c_eval_lcd.c
字号:
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 */
den = deltay;
num = deltay / 2;
numadd = deltax;
numpixels = deltay; /* There are more y-values than x-values */
}
for (curpixel = 0; curpixel <= numpixels; curpixel++)
{
PutPixel(x, y); /* Draw the current pixel */
num += numadd; /* Increase the numerator by the top of the fraction */
if (num >= den) /* Check if numerator >= denominator */
{
num -= den; /* Calculate the new numerator value */
x += xinc1; /* Change the x as appropriate */
y += yinc1; /* Change the y as appropriate */
}
x += xinc2; /* Change the x as appropriate */
y += yinc2; /* Change the y as appropriate */
}
}
/**
* @brief Displays an polyline (between many points).
* @param Points: pointer to the points array.
* @param PointCount: Number of points.
* @retval None
*/
void LCD_PolyLine(pPoint Points, uint16_t PointCount)
{
int16_t X = 0, Y = 0;
if(PointCount < 2)
{
return;
}
while(--PointCount)
{
X = Points->X;
Y = Points->Y;
Points++;
LCD_DrawUniLine(X, Y, Points->X, Points->Y);
}
}
/**
* @brief Displays an relative polyline (between many points).
* @param Points: pointer to the points array.
* @param PointCount: Number of points.
* @param Closed: specifies if the draw is closed or not.
* 1: closed, 0 : not closed.
* @retval None
*/
static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
{
int16_t X = 0, Y = 0;
pPoint First = Points;
if(PointCount < 2)
{
return;
}
X = Points->X;
Y = Points->Y;
while(--PointCount)
{
Points++;
LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
X = X + Points->X;
Y = Y + Points->Y;
}
if(Closed)
{
LCD_DrawUniLine(First->X, First->Y, X, Y);
}
}
/**
* @brief Displays a closed polyline (between many points).
* @param Points: pointer to the points array.
* @param PointCount: Number of points.
* @retval None
*/
void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
{
LCD_PolyLine(Points, PointCount);
LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
}
/**
* @brief Displays a relative polyline (between many points).
* @param Points: pointer to the points array.
* @param PointCount: Number of points.
* @retval None
*/
void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
{
LCD_PolyLineRelativeClosed(Points, PointCount, 0);
}
/**
* @brief Displays a closed relative polyline (between many points).
* @param Points: pointer to the points array.
* @param PointCount: Number of points.
* @retval None
*/
void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
{
LCD_PolyLineRelativeClosed(Points, PointCount, 1);
}
/**
* @brief Displays a full polyline (between many points).
* @param Points: pointer to the points array.
* @param PointCount: Number of points.
* @retval None
*/
void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
{
/* public-domain code by Darel Rex Finley, 2007 */
uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
j = 0, swap = 0;
uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
IMAGE_LEFT = IMAGE_RIGHT = Points->X;
IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
for(i = 1; i < PointCount; i++)
{
pixelX = POLY_X(i);
if(pixelX < IMAGE_LEFT)
{
IMAGE_LEFT = pixelX;
}
if(pixelX > IMAGE_RIGHT)
{
IMAGE_RIGHT = pixelX;
}
pixelY = POLY_Y(i);
if(pixelY < IMAGE_TOP)
{
IMAGE_TOP = pixelY;
}
if(pixelY > IMAGE_BOTTOM)
{
IMAGE_BOTTOM = pixelY;
}
}
LCD_SetTextColor(BackColor);
/* Loop through the rows of the image. */
for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++)
{
/* Build a list of nodes. */
nodes = 0; j = PointCount-1;
for (i = 0; i < PointCount; i++)
{
if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY)
{
nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i)));
}
j = i;
}
/* Sort the nodes, via a simple 揃ubble?sort. */
i = 0;
while (i < nodes-1)
{
if (nodeX[i]>nodeX[i+1])
{
swap = nodeX[i];
nodeX[i] = nodeX[i+1];
nodeX[i+1] = swap;
if(i)
{
i--;
}
}
else
{
i++;
}
}
/* Fill the pixels between node pairs. */
for (i = 0; i < nodes; i+=2)
{
if(nodeX[i] >= IMAGE_RIGHT)
{
break;
}
if(nodeX[i+1] > IMAGE_LEFT)
{
if (nodeX[i] < IMAGE_LEFT)
{
nodeX[i]=IMAGE_LEFT;
}
if(nodeX[i+1] > IMAGE_RIGHT)
{
nodeX[i+1] = IMAGE_RIGHT;
}
LCD_SetTextColor(BackColor);
LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
LCD_SetTextColor(TextColor);
PutPixel(pixelY, nodeX[i+1]);
PutPixel(pixelY, nodeX[i]);
/* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
}
}
}
/* draw the edges */
LCD_SetTextColor(TextColor);
}
/**
* @brief Writes index to select the LCD register.
* @param LCD_Reg: address of the selected register.
* @retval None
*/
void LCD_WriteRegIndex(uint8_t LCD_Reg)
{
ClrCs
ClrRs
ClrWr
LCD_Write(LCD_Reg);
SetWr
SetCs
}
/**
* @brief Reads the selected LCD Register.
* @param None
* @retval LCD Register Value.
*/
uint16_t LCD_ReadReg(uint8_t LCD_Reg)
{
uint16_t data;
/* Write 16-bit Index (then Read Reg) */
ClrCs
ClrRs
ClrWr
LCD_Write(LCD_Reg);
SetWr
/* Read 16-bit Reg */
SetRs
ClrRd
SetRd
data = LCD_Read();
SetCs
return data;
}
/**
* @brief Prepare to write to the LCD RAM.
* @param None
* @retval None
*/
void LCD_WriteRAM_Prepare(void)
{
/* Write 16-bit Index, then Write Reg */
ClrCs
ClrRs
ClrWr
LCD_Write(LCD_REG_34);
SetWr
SetRs
}
/**
* @brief Writes 1 word to the LCD RAM.
* @param RGB_Code: the pixel color in RGB mode (5-6-5).
* @retval None
*/
void LCD_WriteRAMWord(uint16_t RGB_Code)
{
LCD_WriteRAM_Prepare();
LCD_WriteRAM(RGB_Code);
SetCs
}
/**
* @brief Writes to the selected LCD register.
* @param LCD_Reg: address of the selected register.
* @param LCD_RegValue: value to write to the selected register.
* @retval None
*/
void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
ClrCs
ClrRs
ClrWr
LCD_Write(LCD_Reg);
SetWr
/* Write 16-bit Reg */
SetRs
ClrWr
LCD_Write(LCD_RegValue);
SetWr
SetCs
}
/**
* @brief Writes to the LCD RAM.
* @param RGB_Code: the pixel color in RGB mode (5-6-5).
* @retval None
*/
void LCD_WriteRAM(uint16_t RGB_Code)
{
ClrWr
LCD_Write(RGB_Code);
SetWr
}
/*******************************************************************************
* Function Name : LCD_Pins_Config
* Description : Configures LCD Pins
Push-Pull mode.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Pins_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(LCD_CLK_RS | RCC_APB2Periph_GPIOE |
LCD_CLK_WR | LCD_CLK_RD |
LCD_CLK_CS, ENABLE);
// DB15--0
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//LCD_Pin_WR
GPIO_InitStructure.GPIO_Pin = LCD_Pin_WR;
GPIO_Init(LCD_PORT_WR, &GPIO_InitStructure);
//LCD_Pin_CS
GPIO_InitStructure.GPIO_Pin = LCD_Pin_CS;
GPIO_Init(LCD_PORT_CS, &GPIO_InitStructure);
//LCD_Pin_RS
GPIO_InitStructure.GPIO_Pin = LCD_Pin_RS;
GPIO_Init(LCD_PORT_RS, &GPIO_InitStructure);
//LCD_Pin_RD
GPIO_InitStructure.GPIO_Pin = LCD_Pin_RD;
GPIO_Init(LCD_PORT_RD, &GPIO_InitStructure);
SetCs
SetWr
SetRd
SetRs
}
/**
* @brief Displays a pixel.
* @param x: pixel x.
* @param y: pixel y.
* @retval None
*/
static void PutPixel(int16_t x, int16_t y)
{
if(x < 0 || x > 239 || y < 0 || y > 319)
{
return;
}
LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
}
#ifndef USE_Delay
static void delay(__IO uint32_t nCount)
{
__IO uint32_t index = 0;
for(index = (100000 * nCount); index != 0; index--)
{
}
}
#endif /* USE_Delay*/
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -