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

📄 hal_lcd.c

📁 Zigbee2006入门(源代码+文档讲解+系统推荐)
💻 C
📖 第 1 页 / 共 2 页
字号:
 * @fn      HalLcdWriteValue
 *
 * @brief   Write a value to the LCD
 *
 * @param   value  - value that will be displayed
 *          radix  - 8, 10, 16
 *          option - display options
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteValue ( uint32 value, const uint8 radix, uint8 option)
{
#if (HAL_LCD == TRUE)
  uint8 buf[LCD_MAX_BUF];

  _ltoa( value, &buf[0], radix );
  HalLcdWriteString( (char*)buf, option );
#endif /* HAL_LCD */
}

/**************************************************************************************************
 * @fn      HalLcdWriteScreen
 *
 * @brief   Write a value to the LCD
 *
 * @param   line1  - string that will be displayed on line 1
 *          line2  - string that will be displayed on line 2
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteScreen( char *line1, char *line2 )
{
#if (HAL_LCD == TRUE)
  HalLcdWriteString( line1, HAL_LCD_LINE_1 );
  HalLcdWriteString( line2, HAL_LCD_LINE_2 );
#endif /* HAL_LCD */
}

/**************************************************************************************************
 * @fn      HalLcdWriteStringValue
 *
 * @brief   Write a string followed by a value to the LCD
 *
 * @param   title  -
 *          value  -
 *          format -
 *          line   -
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteStringValue( char *title, uint16 value, uint8 format, uint8 line )
{
#if (HAL_LCD == TRUE)
  uint8 tmpLen;
  uint8 buf[LCD_MAX_BUF];
  uint32 err;

  tmpLen = (uint8)osal_strlen( (char*)title );
  osal_memcpy( buf, title, tmpLen );
  buf[tmpLen] = ' ';
  err = (uint32)(value);
  _ltoa( err, &buf[tmpLen+1], format );
  HalLcdWriteString( (char*)buf, line );		
#endif /* HAL_LCD */
}

/**************************************************************************************************
 * @fn      HalLcdWriteStringValue
 *
 * @brief   Write a string followed by a value to the LCD
 *
 * @param   title   -
 *          value1  -
 *          format1 -
 *          value2  -
 *          format2 -
 *          line    -
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteStringValueValue( char *title, uint16 value1, uint8 format1,
                                  uint16 value2, byte format2, uint8 line )
{
#if (HAL_LCD == TRUE)
  uint8 tmpLen;
  uint8 buf[LCD_MAX_BUF];
  uint32 err;

  tmpLen = (uint8)osal_strlen( (char*)title );
  if ( tmpLen )
  {
    osal_memcpy( buf, title, tmpLen );
    buf[tmpLen++] = ' ';
  }

  err = (uint32)(value1);
  _ltoa( err, &buf[tmpLen], format1 );
  tmpLen = (uint8)osal_strlen( (char*)buf );

  buf[tmpLen++] = ',';
  buf[tmpLen++] = ' ';
  err = (uint32)(value2);
  _ltoa( err, &buf[tmpLen], format2 );

  HalLcdWriteString( (char *)buf, line );		
#endif /* HAL_LCD */
}

/**************************************************************************************************
 * @fn      HalLcdDisplayPercentBar
 *
 * @brief   Display percentage bar on the LCD
 *
 * @param   title   -
 *          value   -
 *
 * @return  None
 **************************************************************************************************/
void HalLcdDisplayPercentBar( char *title, uint8 value )
{
#if (HAL_LCD == TRUE)
  uint8 percent;
  uint8 leftOver;
  uint8 buf[17];
  uint32 err;
  uint8 x;

  /* Write the title: */
  HalLcdWriteString( title, HAL_LCD_LINE_1 );

  if ( value > 100 )
    value = 100;

  /* convert to blocks */
  percent = (byte)(value / 10);
  leftOver = (byte)(value % 10);

  /* Make window */
  osal_memcpy( buf, "[          ]  ", 15 );

  for ( x = 0; x < percent; x ++ )
  {
    buf[1+x] = '>';
  }

  if ( leftOver >= 5 )
    buf[1+x] = '+';

  err = (uint32)value;
  _ltoa( err, (uint8*)&buf[13], 10 );

  HalLcdWriteString( (char*)buf, HAL_LCD_LINE_2 );
#endif /* HAL_LCD */
}

#if (defined LCD_HW) && (HAL_LCD == TRUE)
/*********************************************************************
 * @fn      initLcd
 * @brief   Initializes LCD I/O bus and LCD device
 * @param   void
 * @return  void
 */
static void initLcd( void )
{
  uint8 buffer[8];

  // Initialize the serial I/O bus
  initSmb();

  // Load LCD initialization message
  buffer[0] = LCD_ADDR;
  buffer[1] = LCD_RS_0;  // Instruction Register
  buffer[2] = 0x0C;      // Display control         D =  1:      Display On
  //                                                C =  0:      Cursor Off
  //                                                B =  0:      Cursor character blink off
  buffer[3] = 0x21;      // Function set            H =  1:      Use extended instruction set
  buffer[4] = 0xA0;      // Set DDRAM address       ADD = 0x20
  buffer[5] = 0x07;      // Display configuration   P =  1:      Column data right to left
  //                                                Q =  1:      Row data, bottom to top
  buffer[6] = 0x34;      // Function set            DL=  0:      4 bits
  //                                                M =  1:      2-line by 16 display
  //                                                SL=  0:      MUX1:18
  //                                                H =  0:      Use basic instruction set
  buffer[7] = 0x01;      // Clearing display

  // Send message to LCD device
  smbSend( buffer, 8 );

}

/*********************************************************************
 * @fn      lcdUpdateLine
 * @brief   Updates one line of the LCD display
 * @param   line - LCD line numberptr to string going to LCD line 1
 * @param   p2 - ptr to string going to LCD line 2
 * @return  void
 */
static void lcdUpdateLine( uint8 line, uint8 *pLine )
{
  uint8 i;
  uint8 chr;
  uint8 addr;
  uint8 *buffer;

  if ( line == HAL_LCD_LINE_1 )
    addr = LCD_LINE1_ADDR;
  else
    addr = LCD_LINE2_ADDR;

  // Get a buffer to work with
  buffer = osal_mem_alloc( 2+HAL_LCD_MAX_CHARS );
  if ( buffer != NULL )
  {
    // Build and send control string
    buffer[0] = LCD_ADDR;
    buffer[1] = LCD_RS_0;
    buffer[2] = addr;
    smbSend( buffer, 3 );

    // Build and send message string
    buffer[0] = LCD_ADDR;
    buffer[1] = LCD_RS_1;
    // Convert and save message bytes
    for( i = 2; i < 2+HAL_LCD_MAX_CHARS; i++ )
    {
      chr = *pLine++;
      if ( chr == '\0' )
      {
        chr = lcdConvertChar( ' ' );
        break;
      }
      else
        buffer[i] = lcdConvertChar( chr );
    }

    // Fill remainder of line with blanks
    for( ; i < 2+HAL_LCD_MAX_CHARS; i++ )
      buffer[i] = chr;

    // Put it on the display
    smbSend( buffer, 2+HAL_LCD_MAX_CHARS );

    // Give back buffer memory
    osal_mem_free( buffer );
  }
}

/*********************************************************************
 * @fn      lcdConvertChar
 * @brief   Converts an ASCII character to an LCD character (R sheet)
 * @param   aChar - ASCII character
 * @return  lChar - LCD character
 */
static byte lcdConvertChar( byte aChar )
{
  uint8 lChar;

  if ((aChar >= 'a') && (aChar <= 'z'))
    // Lower case
    lChar = aChar + ('a' - 0xE1);
  else if ((aChar >= 'A') && (aChar <= 'Z'))
    // Upper case
    lChar = aChar + ('A' - 0xC1);
  else if (((aChar >= ' ') && (aChar <= '#')) ||
           ((aChar >= '%') && (aChar <= '?')))
    // Sonme symbols
    lChar = aChar + (' ' - 0xA0);
  else
  {
    switch ( aChar )
    {
      case '$':
         lChar = 0x82;
         break;
      case '

⌨️ 快捷键说明

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