⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdd.txt

📁 LCD驱动显示模块实例源码
💻 TXT
📖 第 1 页 / 共 3 页
字号:
}

/**********************************************************************//**
 * @brief  Displays the string to the LCD starting at (x,y) location. 
 * 
 * Writes all the data to LCD_MEM first, then updates all corresponding 
 * LCD CGRAM locations at once, in a continuous fashion.
 * 
 * @param  String[]  String to be displayed on LCD
 * 
 * @param  x         x-coordinate of the write location on the LCD 
 * 
 * @param  y         y-coordinate of the write location on the LCD
 * 
 * @param  TextStyle Value that specifies whether the string is to be 
 *                   inverted or overwritten. 
 *                   - Invert    = 0x01 
 *                   - Overwrite = 0x04 
 *************************************************************************/
void halLcdPrintXY( char String[], int x, int y, unsigned char TextStyle)  
{
  //Each line increments by 0x20
  halLcdSetAddress( (y << 5) + (x >> 3)) ;  //Narrow down to 8 possible pixels    
  halLcdPrint(String,  TextStyle);
}

/**********************************************************************//**
 * @brief  Displays a string on the LCD on the specified line.  
 * 
 * @param  String[]  The string to be displayed on LCD.
 * 
 * @param  Line      The line on the LCD on which to print the string.
 * 
 * @param  TextStyle Value that specifies whether the string is to be 
 *                   inverted or overwritten. 
 *                   - Invert    = 0x01 
 *                   - Overwrite = 0x04 
 * 
 * @return none
 *************************************************************************/
void halLcdPrintLine(char String[], unsigned char Line, unsigned char TextStyle)  
{
  int temp; 
  temp = Line * FONT_HEIGHT ;
  halLcdSetAddress( temp << 5 ) ;           // 0x20 = 2^5  
  halLcdPrint(String, TextStyle);
}

/**********************************************************************//**
 * @brief  Prints a string beginning on a given line and column.  
 * 
 * @param  String[]  The string to be displayed on LCD.
 * 
 * @param  Line      The line on which to print the string of text
 * 
 * @param  Col       The column on which to print the string of text
 * 
 * @param  TextStyle Value that specifies whether the string is to be 
 *                   inverted or overwritten. 
 *                   - Invert    = 0x01 
 *                   - Overwrite = 0x04 
 * 
 * @return none
 *************************************************************************/
void halLcdPrintLineCol(char String[], unsigned char Line, unsigned char Col,
                        unsigned char TextStyle)  
{
  int temp; 
  
  temp = Line * FONT_HEIGHT;
  temp <<= 5;
  temp += Col;
  
  halLcdSetAddress( temp ) ;                // 0x20 = 2^5                     
  halLcdPrint(String, TextStyle);
}


/**********************************************************************//**
 * @brief  Draws a horizontral line from (x1,y) to (x2,y) of GrayScale level
 * 
 * @param  x1        x-coordinate of the first point 
 * 
 * @param  x2        x-coordinate of the second point
 * 
 * @param  y         y-coordinate of both points
 * 
 * @param  GrayScale Grayscale level of the horizontal line
 * 
 * @return none
 *************************************************************************/
void halLcdHLine( int x1, int x2, int y, unsigned char GrayScale)
{
  int x_dir, x;
  if ( x1 < x2 )
    x_dir = 1;
  else 
    x_dir = -1;
  x = x1;    
  while (x != x2)
  {
    halLcdPixel( x,y, GrayScale); 
    x += x_dir;
  }
}

/**********************************************************************//**
 * @brief  Draws a vertical line from (x,y1) to (x,y2) of GrayScale level
 * 
 * @param  x         x-coordinate of both points
 * 
 * @param  y1        y-coordinate of the first point 
 * 
 * @param  y2        y-coordinate of the second point
 * 
 * @param  GrayScale GrayScale level of the vertical line
 * 
 * @return none
 *************************************************************************/
void halLcdVLine( int x, int y1, int y2, unsigned char GrayScale)
{
  int y_dir, y;
  if ( y1 < y2 )
    y_dir = 1;
  else 
    y_dir = -1;
  y = y1;    
  while (y != y2)
  {
    halLcdPixel( x,y, GrayScale); 
    y += y_dir;
  }
}

/**********************************************************************//**
 * @brief  Draws a line from (x1,y1) to (x2,y2) of GrayScale level.
 *         
 * Uses Bresenham's line algorithm.
 * 
 * @param  x1         x-coordinate of the first point        
 *  
 * @param  y1         y-coordinate of the first point
 * 
 * @param  x2         x-coordinate of the second point
 * 
 * @param  y2         y-coordinate of the second point
 * 
 * @param  GrayScale  Grayscale level of the line 
 * 
 * @return none
 *************************************************************************/
void halLcdLine( int x1, int y1, int x2, int y2, unsigned char GrayScale) 
{
  int x, y, deltay, deltax, d;  
  int x_dir, y_dir;

  if ( x1 == x2 )
    halLcdVLine( x1, y1, y2, GrayScale );
  else
  {
    if ( y1 == y2 )
      halLcdHLine( x1, x2, y1, GrayScale );
    else                                    // a diagonal line
    {
      if (x1 > x2)
        x_dir = -1;
      else x_dir = 1;
      if (y1 > y2)
        y_dir = -1;
      else y_dir = 1;
      
      x = x1;
      y = y1;
      deltay = ABS(y2 - y1);
      deltax = ABS(x2 - x1);

      if (deltax >= deltay)
      {
        d = (deltay << 1) - deltax;
        while (x != x2)
        {
          halLcdPixel(x, y,  GrayScale);
          if ( d < 0 )
            d += (deltay << 1);
          else
          {
            d += ((deltay - deltax) << 1);
            y += y_dir;
          }
          x += x_dir;
        }                
      }
      else
      {
        d = (deltax << 1) - deltay;
        while (y != y2)
        {
          halLcdPixel(x, y, GrayScale);
          if ( d < 0 )
            d += (deltax << 1);
          else
          {
            d += ((deltax - deltay) << 1);
            x += x_dir;
          }
          y += y_dir;
        }        
      }
    }  
  }
}


/**********************************************************************//**
 * @brief  Draw a circle of Radius with center at (x,y) of GrayScale level.
 *         
 * Uses Bresenham's circle algorithm
 * 
 * @param  x         x-coordinate of the circle's center point
 * 
 * @param  y         y-coordinate of the circle's center point
 * 
 * @param  Radius    Radius of the circle
 * 
 * @param  GrayScale Grayscale level of the circle 
 *************************************************************************/
void halLcdCircle(int x, int y, int Radius, int GrayScale)
{
  int xx, yy, ddF_x, ddF_y, f;
  
  ddF_x = 0;
  ddF_y = -(2 * Radius);
  f = 1 - Radius;

  xx = 0;
  yy = Radius;
  halLcdPixel(x + xx, y + yy, GrayScale);
  halLcdPixel(x + xx, y - yy, GrayScale);
  halLcdPixel(x - xx, y + yy, GrayScale);
  halLcdPixel(x - xx, y - yy, GrayScale);
  halLcdPixel(x + yy, y + xx, GrayScale);
  halLcdPixel(x + yy, y - xx, GrayScale);
  halLcdPixel(x - yy, y + xx, GrayScale);
  halLcdPixel(x - yy, y - xx, GrayScale);
  while (xx < yy)
  {
    if (f >= 0)
    {
      yy--;
      ddF_y += 2;
      f += ddF_y;
    }
    xx++;
    ddF_x += 2;
    f += ddF_x + 1;
    halLcdPixel(x + xx, y + yy, GrayScale);
    halLcdPixel(x + xx, y - yy, GrayScale);
    halLcdPixel(x - xx, y + yy, GrayScale);
    halLcdPixel(x - xx, y - yy, GrayScale);
    halLcdPixel(x + yy, y + xx, GrayScale);
    halLcdPixel(x + yy, y - xx, GrayScale);
    halLcdPixel(x - yy, y + xx, GrayScale);
    halLcdPixel(x - yy, y - xx, GrayScale);
  }
}

/**********************************************************************//**
 * @brief  Scrolls a single row of pixels one column to the left. 
 * 
 * The column that is scrolled out of the left side of the LCD will be 
 * displayed the right side of the LCD. 
 * 
 * @param  y    The row of pixels to scroll. y = 0 is at the top-left
 *              corner of the LCD. 
 * 
 * @return none
 *************************************************************************/
void halLcdScrollRow(int y)
{
  int i, Address, LcdTableAddressTemp;
  unsigned int temp;
  
  Address = y << 5;
  
  halLcdSetAddress( Address );
  
  //Multiplied by (1+16) and added by the offset
  LcdTableAddressTemp = y + (y << 4);       
  temp = ((LCD_MEM[LcdTableAddressTemp] & 0x0003) <<14);
  
  for (i = 0; i < 0x10; i++)      
    halLcdDrawCurrentBlock( ( (LCD_MEM[LcdTableAddressTemp+i] & 0xFFFC ) >> 2 ) \
    + ((LCD_MEM[LcdTableAddressTemp+i+1] & 0x0003) << 14 ));
    
  halLcdDrawCurrentBlock( (( LCD_MEM[LcdTableAddressTemp + 0x10] & 0xFFFC ) >> 2) + temp);    
}

/**********************************************************************//**
 * @brief  Scrolls multiple rows of pixels, yStart to yEnd, 
 *         one column to the left. 
 * 
 * The column that is scrolled out of the left side of the LCD will be 
 * displayed the right side of the LCD. y = 0 is at the top-left of the 
 * LCD screen.
 * 
 * @param  yStart The beginning row to be scrolled
 * 
 * @param  yEnd   The last row to be scrolled 
 * 
 * @return none
 *************************************************************************/
void halLcdHScroll(int yStart, int yEnd)
{
  int i ;  
  
  for (i = yStart; i < yEnd+1; i++)
    halLcdScrollRow(i);
}

/**********************************************************************//**
 * @brief  Scrolls a line of text one column to the left. 
 * 
 * @param  Line The line of text to be scrolled.  
 * 
 * @return none
 *************************************************************************/
void halLcdScrollLine(int Line)
{
  int i, Row ;
  
  Row = Line * FONT_HEIGHT;
  
  for (i = Row; i < Row + FONT_HEIGHT ; i++)
    halLcdScrollRow(i);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -