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

📄 lcd.c

📁 MCS-51的一个Free小型操作系统,在KeilC中下编译工作
💻 C
📖 第 1 页 / 共 4 页
字号:
*                  - Column: start column address.
*                  - Width: the number of column (dots) of a character width.
*                  - Bmp: the pointer of the dot matrix data.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DrawChar(u8 Line, u8 Column, u8 Width, u8 *Bmp)
{
  u8 X = 0, ActualColumn = 0, Window = 0, i = 0;

  /* Draw the character column by column: width times */
  for(X = Column; X<(Column+Width); X++)
  {
    if(X > 121)
    {
      /* Return if column exceeded 121 */
      return;
    }
    if (X > 60) 	
    {
      /* To be displayed on slave LCD (Window = 1) */
      Window = 1;
      /* Get the Slave relative start column */
//      ActualColumn = X%61;
	  ActualColumn = X - 61;
    }
    else
    {	
      /* To be displayed on master LCD (Window = 0) */
      ActualColumn = X;
    }

    /* Switch window, display the character upper part */
    if (Window)
    {
      /* Display it on slave LCD */
      LCD_SetSlavePage(Line);
      LCD_SetSlaveColumn(ActualColumn);
      LCD_SendSlaveData(Bmp[i]);
    }
    else
    {
      /* Display it on master LCD */
      LCD_SetMasterPage(Line);
      LCD_SetMasterColumn(ActualColumn);
      LCD_SendMasterData(Bmp[i]);
    }
    /* Switch window, diplay the character lower part  */
    if (Window)
    {
      /* Display it on slave LCD */
      LCD_SetSlavePage(Line+1);
      LCD_SetSlaveColumn(ActualColumn);
      LCD_SendSlaveData(Bmp[i+1]);
    }
    else
    {
      /* Display it on master LCD */
      LCD_SetMasterPage(Line+1);
      LCD_SetMasterColumn(ActualColumn);
      LCD_SendMasterData(Bmp[i+1]);
    }
    /* Increment by 2 the character table index */
    i+=2;
  }
}

/*******************************************************************************
* Function Name  : LCD_DisplayChar
* Description    : Display one character (7dots large, 16dots high).
*                  Note:
*                  the LCD can only display two line character,so page 0 and 1
*                  is to display the first line, page2 and page 3 is to display
*                  the second line.
* Input          : - Line: the Line where to display the character.
*                      - Line1 (Page0&1): display character on the first line
*                      - Line2 (Page2&3): display character on the second line
*                  - Column: start column address.
*                  - Ascii: character ascii code.
*                  - CharMode: BlackText: character on black, bottom on white.
*                              WhiteText: character on white, bottom on black.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DisplayChar(u8 Line, u8 Column, u8 Ascii, TextColorMode_TypeDef CharMode)
{
  u8  DotBuffer[14], i = 0;

  /* Display the character lower and upper 8bit parts (2*7columns) */
  for (i=0;i<14;i++)
  {
    /* Character displayed as white Text on black buttom  */
    if(CharMode)
    {
	  if( i & 0x01 )
	  {
	  	DotBuffer[i] = ~AsciiDotsTable[Ascii*14+i-1];	
	  }
	  else
	  {
        DotBuffer[i] = ~AsciiDotsTable[Ascii*14+i+1];	  
	  }
    }
    /* Character displayed as black Text on white buttom  */
    else
    {
	  if( ( u8 ) i & 0x01 )
      {
        DotBuffer[i] = AsciiDotsTable[Ascii*14+i-1];		  
      }
      else
      {
        DotBuffer[i] = AsciiDotsTable[Ascii*14+i+1];				  
      }
    }
  }
  /* Display the asc code after conversion */
  LCD_DrawChar(Line, Column, 7, DotBuffer);
}

/*******************************************************************************
* Function Name  : LCD_HexToAsciiLow
* Description    : This function is used to convert the low nibble of an
*                  unsigned byte (0-F hex) to ASCII.
* Input          : - byte: byte to convert to ASCII.
* Output         : None
* Return         : ASCII value result of the conversion.
*******************************************************************************/
char LCD_HexToAsciiLow(u8 byte)
{
  /* Keep lower nibble only */
  byte = byte & 0x0F;
  /* If the ascii is a number */	
  if (byte <= 0x09)
  {
    /* Add 0x30 to its ascii */
    return(byte + 0x30);
  }
  else
  {
    /* Add 0x37 to its ascii */
    return (byte + 0x37);
  }
}

/*******************************************************************************
* Function Name  : LCD_HexToAsciiHigh
* Description    : This function is used to convert the high nibble of an
*                  unsigned byte (0-F hex) to ASCII.
* Input          : - byte: byte to convert to ASCII.
* Output         : None
* Return         : ASCII value result of the conversion.
*******************************************************************************/
char LCD_HexToAsciiHigh(u8 byte)
{
  /* Keep upper nibble only */
  byte = byte & 0xF0;	
  byte = byte >> 4;
  /* If the ascii is a number */
  if (byte <= 0x09)
  {
    /* Add 0x30 to display its ascii */
    return(byte + 0x30);
  }
  else
  {
    /* Add 0x37 to display its ascii */
    return (byte + 0x37);
  }
}

/*******************************************************************************
* Function Name  : LCD_DisplayString
* Description    : This function is used to display a 17char max string of
*                  characters on the LCD display on the selected line.
*                  Note:
*                  this function is the user interface to use the LCD driver.
* Input          : - *ptr: pointer to string to display on LCD.
*                  - Line: the Line where to display the character.
*                      - Line1 (Page0&1): display character on the first line
*                      - Line2 (Page2&3): display character on the second line
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DisplayString(u8 Line, u8 *ptr, TextColorMode_TypeDef CharMode)
{
  u8 RefColumn = 0, i = 0;

  /* Send the string character by character on lCD */
  while ((*ptr!=0)&(i<17))
  {
	if( *ptr == ' ' )
	{
		if( ptr[1] == ' ')
		{
			vTaskDelay( 3 );
		}
		else
		{
			vTaskDelay( 16 );
		}
	}
	
	if( *ptr == '.' )
	{
		vTaskDelay( 16 );
	}
  
  /* Display one character on LCD */
    LCD_DisplayChar(Line, RefColumn, *ptr, CharMode);

    /* Increment the column position by 7 */
    RefColumn+=7;
    /* Point on the next character */
    ptr++;
    /* Increment the character counter */
    i++;
    /* If we reach the maximum Line character */
    if(i==17)
    {
      LCD_DisplayChar(Line, RefColumn-1, 0x1f, CharMode); /* Add missed columns */
    }
  }
}

/*******************************************************************************
* Function Name  : LCD_Printf
* Description    : This function is used to display a string of characters
*                  on the LCD display.
*                  Note:
*                  this function is the user interface to use the LCD driver.
* Input          : - *ptr: pointer to string to display on LCD.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_Printf(u8 *ptr, ...)
{
  u8 RefColumn = 0, RefPage = 0, i = 0, c1 = 0;
  u16  var = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0;
  u32 WordVar = 0;

  /* Store pointer on LCD_Printf second parameter (String) */
  u8 *var_ptr=(u8 *)(&ptr+1);

  /* Send String */
  while (*ptr != 0)
  {
    c1 = *ptr;
    /* Limited to AsciiDotsTable code table */
    if(c1 <= 128)
    {
      /* Carriage return */
      if ( *ptr == '\r')
      {
        ptr++;
        RefColumn = 0;
      }
      /* Jump to Line2 */
      else if( *ptr == '\n')
      {
        /* Point on the string to display */
        ptr++;
        /* Clear Line2 */
        LCD_ClearLine(Line2);
        /* Point on first Line2 column */
        RefColumn = 0;
        /* Increment RefPage by 2 */
        RefPage+=2;
      }
      /* Display value on the passed format */
      else if( *ptr == '%')
      {
        ptr++;
        /* Display decimal value */
	if (*ptr == 'd')
	{
	  ptr++;
          /* Get the word value to display */
          WordVar = ((*var_ptr)|(*(var_ptr+1)<<8)|(*(var_ptr+2)<<16));
          c1=WordVar/10000;
          c2=(WordVar%10000)/1000;
          c3=(WordVar%1000)/100;
          c4=(WordVar%100)/10;
          c5=(WordVar%10);
          /* Display the ten miles digit */
          if (c1!=0)
          {
            LCD_DisplayChar(RefPage, RefColumn, c1+0x30, TextMode);
	    RefColumn+=7;
          }
          /* Display the miles digit */
          if (!((c1==0)&(c2==0)))
          {
          LCD_DisplayChar(RefPage, RefColumn, c2+0x30, TextMode);
	  RefColumn+=7;
          }
          /* Display the hundred digit */
          if (!((c1==0)&(c2==0)&(c3==0)))
          {
          LCD_DisplayChar(RefPage, RefColumn, c3+0x30, TextMode);
	  RefColumn+=7;
          }
          /* Display the tens digit */
          if (!((c1==0)&(c2==0)&(c3==0)&(c4==0)))
          {
          LCD_DisplayChar(RefPage, RefColumn, c4+0x30, TextMode);
	  RefColumn+=7;
          }
          /* Display the rest */
          LCD_DisplayChar(RefPage, RefColumn, c5+0x30, TextMode);
	  RefColumn+=7;
        }
        /* Display 16bits Hex value */
        else if (*ptr == 'x')
        {
          ptr++;
          /* Display 8bits MSB */
          var_ptr = var_ptr +1;
          var = *var_ptr;
          c1 = LCD_HexToAsciiHigh(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
          c1 = LCD_HexToAsciiLow(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
          /* Display 8bits LSB */
          var_ptr = var_ptr -1;
          var = *var_ptr;
          var_ptr = var_ptr +4;
          c1 = LCD_HexToAsciiHigh(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
          c1 = LCD_HexToAsciiLow(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
        }
        /* Display 32bits Hex value */
        else if (*ptr == 'w')
        {
          ptr++;
          /* Display 16bits MSB */
          var_ptr = var_ptr +3;
          var = *var_ptr;
          c1 = LCD_HexToAsciiHigh(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
          c1 = LCD_HexToAsciiLow(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
          var_ptr = var_ptr -1;
          var = *var_ptr;
          c1 = LCD_HexToAsciiHigh(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;
          c1 = LCD_HexToAsciiLow(var);
          LCD_DisplayChar(RefPage, RefColumn, c1, TextMode);
          RefColumn+=7;

⌨️ 快捷键说明

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