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

📄 lcd.c

📁 TDK 6521 SOC 芯片 DEMO程序
💻 C
字号:
/***************************************************************************
 * This code and information is provided "as is" without warranty of any   *
 * kind, either expressed or implied, including but not limited to the     *
 * implied warranties of merchantability and/or fitness for a particular   *
 * purpose.                                                                *
 *                                                                         *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 ***************************************************************************/
//**************************************************************************
//  DESCRIPTION: 71M652x POWER METER - LCD Routines.
// 
//  AUTHOR:  MTF
//
//  History: See end of file.
//**************************************************************************
// File: LCD.C
//               
#include "options.h"
#include "defaults.h"
#include "library.h"
#include "lcd.h"

#define  LCD_SEG_COM0 BIT0              // LCD Segment Data COM0.
#define  LCD_SEG_COM1 BIT1              // LCD Segment Data COM1.
#define  LCD_SEG_COM2 BIT2              // LCD Segment Data COM2.
#define  LCD_SEG_COM3 BIT3              // LCD Segment Data COM3.

/*     
 +-----a-----+           +-----a-----+  Mapping of character to digit/elements.
 |\    |    /|           |           |        Bitmapped  Mask 
 | \   g   / |           |           |                                       
 f  n  |  h  b           f           b    '0'  -,-,f,e, d,c,b,a     
 |   \ | /   |           |           |    '1'  -,-,-,-, -,c,b,-    
 |    \ /    |           |           |    '2'  -,g,-,e, d,-,b,a    
 +--m--.--i--+     OR    +-----g-----+    '3'  -,g,-,-, d,c,b,a    
 |    / \    |           |           |    '4'  -,g,f,-, -,c,b,-    
 |   / | \   |           |           |    '5'  -,g,f,-, d,c,-,a    
 e  l  |  j  c           e           c    '6'  -,g,f,e, d,c,-,-    
 | /   k   \ |           |           |    '7'  -,-,-,-, -,c,b,a
 |/    |    \|           |           |    '8'  -,g,f,e, d,c,b,a    
 +-----d-----+           +-----d-----+    '9'  -,g,f,-, -,c,b,a    
*/

/*** External variables used within this module ***/
extern uint16r_t * code icons[];        // Defined by user application.
extern uint8r_t num_segs[];             //

//***************************************************************************
// LCD_Command (LCD_CLEAR);       Clear display.
// LCD_Command (LCD_DISPLAY_ON);  Display ON.
// LCD_Command (LCD_DISPLAY_OFF); Display OFF.
//***************************************************************************

#define LCD_CLEAR       0x01   // Clears Entire LCD.
#define LCD_DISPLAY_ON  0x0C   // Display ON.
#define LCD_DISPLAY_OFF 0x08   // Display OFF.

/*** Public variables declared within this module ***/
uint16r_t idx2bit[] = { BIT0,  BIT1,  BIT2,  BIT3,  BIT4,  BIT5,  BIT6,  BIT7,
                        BIT8,  BIT9,  BIT10, BIT11, BIT12, BIT13, BIT14, BIT15 };

uint16r_t Digit_Mask[] =         // Mask for 7-segment digits.
{ // '0',  '1', '2',  '3',   '4',  '5', '6',  '7',   '8',  '9'
    ZERO,  ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE
};

/*** Private functions declared within this module ***/

/*** Private variables used within this module ***/
#define SEGMENT_MASK  0xFF              // Number of SEGMENT drivers.
#define COM_MASK      ~SEGMENT_MASK     // Number of COMMONs.
#define COM_ALIGN     8

static uint8r_t com2bit[] = {
    LCD_SEG_COM0, LCD_SEG_COM1, LCD_SEG_COM2, LCD_SEG_COM3 };

//===========================================================================//
void LCD_Init (void)
{
    // LCD set up from a central table in main\defaults.c
    memcpy_xr (
        (uint8x_t *) IO_LCD,   
        &ri_defaults[ IO_LCD_IDX ],   
        IO_LCD_SIZE);
    #if M6520
    memcpy_xr (
        (uint8x_t *) IO_BLINK, 
        &ri_defaults[ IO_BLINK_IDX ], 
        IO_BLINK_SIZE);
    #endif

    LCD_Command (LCD_DISPLAY_ON );      // Display ON.
}

void LCD_Command (uint8_t LcdCmd)
{
    if (LcdCmd == LCD_CLEAR)
       memset_x (LCD, 0, sizeof (LCD));
    else if (LcdCmd == LCD_DISPLAY_ON)
       LCDY |=  LCD_EN;
    else
       LCDY &= ~LCD_EN;
}

#if VIM808
uint16_t LCD_Data_Read (uint8_t Icon)
{                                       // Handle upto 16 segments per icon.
    uint8_t i;
    uint16_t code *seg;
    uint16_t Value = 0;                 // Assume no active seqments.

    seg = icons[ Icon ];

    for (i = 0; i < num_segs[ Icon ]; i++)
    {
       if (LCD_Seg_Get (*seg))
          Value |= idx2bit[ i ];        // Segment is active.
                    
       seg++;                           // Point to next icon segment.
    }

    return (Value);
}

bool LCD_Seg_Get (uint16_t seg)
{
    uint8_t common;

    common = com2bit[ seg >> COM_ALIGN ];  
    seg &= SEGMENT_MASK;

    if (LCD[ seg ] & common)
       return (ON);             // Segment is active.
    else
       return (OFF);            // Segment is inactive.
}
#endif

void LCD_Data_Write (uint8_t Icon, uint16_t Mask)
{                               // Handle upto 16 segments per icon.
    uint16_t code *seg;
    uint8_t i;

    seg = icons[ Icon ];

    for (i = 0; i < num_segs[ Icon ]; i++)
    {
        if (Mask & 1)
            LCD_Seg_Set (*seg);
        else
            LCD_Seg_Clr (*seg);
                    
        seg++;
        Mask >>= 1;
    }
}

void LCD_Seg_Set (uint16_t seg)
{                                          
    uint8_t common;

    common = com2bit[ seg >> COM_ALIGN ];
    seg &= SEGMENT_MASK;
    
    LCD[ seg ] |=  common;
}

void LCD_Seg_Clr (uint16_t seg)
{                                          
    uint8_t common;

    common = com2bit[ seg >> COM_ALIGN ];
    seg &= SEGMENT_MASK;

    LCD[ seg ] &= ~common;
}

//===========================================================================
// Display a number on the LCD
// d is a signed 32-bit number
// c is the number of digits
// p is the number of mandatory zeros (usually) for the decimal point.
static uint8x_t digit[ MAX_DIGITS ];
void LCD_Number (int32_t lI, int8_t cI, int8_t pI)
{
    uint8_t non_zero = FALSE;           // Suppress leading zeros.
    int8_t ich;

    LCD_Command (LCD_CLEAR);            // Clear display between changes.

    if (lI < 0)
    {
       LCD_Data_Write (--cI, MINUS);     // Minus sign, make room for sign.
       lI = -lI;
    }

    for (ich = 1; ich <= cI; ++ich)
    {                                   // Display upto 'c' digits.
       digit[ cI - ich ] = lI % 10;
       lI /= 10;
    }

    if (0 == lI)
    {
       pI = cI - pI - 1;

       for (ich = 0; ich < cI; ++ich)
       {
          if ((ich >= pI) || (0 != digit[ ich ]) || (TRUE == non_zero) )
          {
             LCD_Data_Write (cI - ich - 1, Digit_Mask[ digit[ ich ]]);
             non_zero = TRUE;
          }
          else
          {
             LCD_Data_Write (cI - ich - 1, BLANK);
          }
       }
    }
    else  // Number overflows display.
    {
       for (ich = 0; ich < cI; ++ich)
          LCD_Data_Write (ich, OVERFLOW);
    }
}

/****************************************************************************
 * History:
 * $Log: lcd.c,v $
 * Revision 1.31  2006/10/13 00:47:29  tvander
 * Removed compile options for 6530, 6515;
 * renamed 6511 and 6513 to trace11 and trace13;
 * Binary verified unchanged from previous version.
 *
 * Revision 1.30  2006/09/29 09:40:58  tvander
 * Build errors
 *
 * Revision 1.29  2006/09/14 00:35:46  tvander
 * substitute spaces for tabs
 *
 * Revision 1.28  2006/09/13 21:37:26  gmikef
 * *** empty log message ***
 *
 * Revision 1.22  2006/08/16 01:44:12  tvander
 * Pretty-printed
 *
 * Revision 1.21  2006/08/09 00:56:35  tvander
 * *** empty log message ***
 *
 * Revision 1.20  2006/07/07 22:50:03  tvander
 * Speed up the initialization a bit for brownout mode.
 *
 * Revision 1.19  2006/06/29 00:55:48  tvander
 * Marked NOAREGS on reentrant routines that needed it.
 *
 * Revision 1.18  2006/06/24 04:41:21  tvander
 * Added hardware initialization, so it can stand alone in brownout mode.
 *
 * Revision 1.17  2006/06/14 02:50:31  tvander
 * Changes to speed up LCD display:
 * The clear was made integral with the main display routine.
 * e.g. LCD_Number() clears the display, then places the number.
 * This means that the decimal points, mode, etc. have to be written after
 * the main display item.
 *
 * Revision 1.16  2006/04/15 01:06:49  tvander
 * It wouldn't display all zeros; fixed.
 *
 * Revision 1.15  2006/03/08 03:06:37  gmikef
 * *** empty log message ***
 *
 * Revision 1.14  2006/03/03 11:26:11  Michael T. Fischer
 * Prep for 6530 LCD, etc.
 *
 * Revision 1.12  2005/11/10 22:51:32  tvander
 * 6520 has battery mode commands.
 * Brownout always has decimal point 7.
 * LCD Mode always has decimal points 7 and 6.
 * Sag detection is disabled.
 *
 * Revision 1.11  2005/11/09 02:21:15  tvander
 * Added code to display watt hours from brownout mode.
 * Added code to clear EEPROM (lapie command "EEE")
 *
 * Revision 1.10  2005/10/12 23:00:01  tvander
 * Includes demonstratable mission mode, brownout, LCD and sleep modes
 *
 * Revision 1.9  2005/09/22 23:45:05  tvander
 * Clean build all models and unit tests, updated copyright to be fore Teridian
 *
 * Revision 1.8  2005/09/11 00:33:58  tvander
 * Clean compiles
 *
 * Revision 1.7  2005/08/31 22:35:08  tvander
 * Removed CE_off from 6521B
 *
 * Revision 1.6  2005/08/28 02:14:07  gmikef
 * *** empty log message ***
 *
 * Revision 1.5  2005/07/14 20:15:48  tvander
 * ce code concentrated in ce.c
 * ce interface concentrated in ce652x.c, .h
 * Fixed 0-length read or write using flag protocol.
 * display.c is out of the build
 * kwh_initialize now reads the LRC.
 *
 * Revision 1.4  2005/05/06 16:40:31  tvander
 * Build errors fixed
 *
 * Revision 1.3  2005/04/30 02:10:23  gmikef
 * *** empty log message ***
 *
 * Revision 1.7  2005/04/29 00:01:55  gmikef
 * *** empty log message ***
 *
 * Revision 1.6  2005/04/25 21:26:02  gmikef
 * *** empty log message ***
 *
 * Revision 1.1  2005/04/21 02:02:38  gmikef
 * *** empty log message ***
 *
 * Revision 1.5  2005/04/21 00:48:26  gmikef
 * *** empty log message ***
 *
 * Revision 1.4  2005/04/13 01:33:39  gmikef
 * *** empty log message ***
 *
 * Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved.    *
 * this program is fully protected by the United States copyright          *
 * laws and is the property of Teridian Semiconductor Corporation.         *
 ***************************************************************************/

⌨️ 快捷键说明

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