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

📄 rd_uselcdsp027.c

📁 LCD1602键盘显示模块实例
💻 C
字号:
/***********************************************************
*   函数库说明:SP-027液晶段码显示器驱动函数库             *
*   版本:      v1.00                                      *
*   作者:      王卓然                                     *
*   创建日期:  2006年5月11日                              *
* -------------------------------------------------------- *
*  [支 持 库]                                              *
*   支持库名称:RD_UseLCDPS027.h                           *
*   需要版本:  v1.00                                      *
*   支持库说明:SP-027液晶段码显示器驱动函数库             *
* -------------------------------------------------------- *
*  [版本更新]                                              *
*   修改:                                                 *
*   修改日期:                                             *
*   版本:                                                 *
* -------------------------------------------------------- *
*  [版本历史]                                              *
* -------------------------------------------------------- *
*  [说    明]                                              *
***********************************************************/

/********************
* 头 文 件 配 置 区 *
********************/
# include "RD_UseLCDSP027.h"

/********************
*   系 统 宏 定 义  *
********************/

/*------------------*
* 硬 件 连 接 定 义 *
*------------------*/
#ifndef SP027_DI
    #error None defined SP027 PIN: DI
#endif
#ifndef SP027_CLK
    #error None defined SP027 PIN: CLK  
#endif
# define SP027_NO_ICON      17
# define SP027_MID_LINE     18
# define SP027_CIRCLE       19
/********************
*   模块变量声明区  *
********************/
static unsigned char LCDSP027_DispBuff[5] = {0,0,0,0,0};
static unsigned char LCDSP027_DISPCODE[] = {0x09,0xcf,0x91,0x85,0x47,0x25,0x21,0x8f,0x01,0x05,
                            0x03,0x61,0x39,0xc1,0x31,0x33,0x29,0xff,0xf7,0x17};

/********************
*   函 数 声 明 区  *
********************/                            
void Set_DISP_BUFF_SP027(char a,char b,char c,char d,char e);
void LCDSP027_refresh_DISP_BUFF(void);
void LCDSP027_Clear(void);
void LCDSP027_PrintN(int16 nNumber);
void LCDSP027_PrintU(uint16 nNumber);

/********************
*   模块函数声明区  *
********************/

static void LCDSP027_Send_Data(char Data);

void LCDSP027_PrintU(uint16 nNumber)
{
    uint16 wAbsNUM = nNumber;
    uint8 NumberA = 0;
    uint8 NumberB = 0;
    uint8 NumberC = 0;
    uint8 NumberD = 0;
    
    NumberD = wAbsNUM % 10;
    wAbsNUM = wAbsNUM * 0.1;
    NumberC = wAbsNUM % 10;
    wAbsNUM = wAbsNUM * 0.1;
    NumberB = wAbsNUM % 10;
    wAbsNUM = wAbsNUM * 0.1;
    NumberA = wAbsNUM % 10;
    
    Set_DISP_BUFF_SP027
        (
            NumberA,
            NumberB,
            NumberC,
            NumberD,
            SP027_NO_ICON
        );
}

void LCDSP027_PrintN(int16 nNumber)
{
    uint16 wAbsNUM = ABS(nNumber);
    uint8 NumberA = 0;
    uint8 NumberB = 0;
    uint8 NumberC = 0;
    
    NumberC = wAbsNUM % 10;
    wAbsNUM = wAbsNUM * 0.1;
    NumberB = wAbsNUM % 10;
    wAbsNUM = wAbsNUM * 0.1;
    NumberA = wAbsNUM % 10;
    
    if (nNumber < 0)
    {
        Set_DISP_BUFF_SP027
        (
            SP027_MID_LINE,                                             
            NumberA,
            NumberB,
            NumberC,
            SP027_CIRCLE
        );
    }
    else
    {
        Set_DISP_BUFF_SP027
        (
            SP027_NO_ICON,                                             
            NumberA,
            NumberB,
            NumberC,
            SP027_CIRCLE
        );
    }
}

/***********************************************************
*   函数说明:显示缓冲区设置函数                           *
*   输入:    要显示的5个数字量(BCD)                       *
*   输出:    无                                           *
*   调用函数:LCDSP027_refresh_DISP_BUFF()                 *
***********************************************************/
void Set_DISP_BUFF_SP027(char a,char b,char c,char d,char e)
{
    LCDSP027_DispBuff[0] = a;
    LCDSP027_DispBuff[1] = b;
    LCDSP027_DispBuff[2] = c;
    LCDSP027_DispBuff[3] = d;
    LCDSP027_DispBuff[4] = e;
		
    //LCDSP027_refresh_DISP_BUFF();
}

/***********************************************************
*   函数说明:刷新显示缓冲区函数                           *
*   输入:    无                                           *
*   输出:    无                                           *
*   调用函数:LCDSP027_Send_Data()                         *
***********************************************************/
void LCDSP027_refresh_DISP_BUFF(void)
{
    char n = 0;
    //LCDSP027_Clear();
    for (n = 0;n<5;n++)
    {
        if (n == 2)
        {
            LCDSP027_Send_Data
                (
                    LCDSP027_DISPCODE[LCDSP027_DispBuff[n]] & ~BIT(0)
                );
        }
        else
        {
            LCDSP027_Send_Data(LCDSP027_DISPCODE[LCDSP027_DispBuff[n]]);
        }
        
    }
    SP027_CLK = LOW;
    SP027_CLK = HIGH;
}

/***********************************************************
*   函数说明:清屏函数                                     *
*   输入:    无                                           *
*   输出:    无                                           *
*   调用函数:无                                           *
***********************************************************/
void LCDSP027_Clear(void)
{
    /*
    char n = 0;
    for (n = 0;n<40;n++)
    {
        SP027_CLK = LOW;
        SP027_DI = HIGH;
        SP027_CLK = HIGH;
    }
    */
    Set_DISP_BUFF_SP027
        (
            SP027_NO_ICON,
            SP027_NO_ICON,
            SP027_NO_ICON,
            SP027_NO_ICON,
            SP027_NO_ICON
        );
}

/***********************************************************
*   函数说明:发送数据函数                                 *
*   输入:    无                                           *
*   输出:    无                                           *
*   调用函数:无                                           *
***********************************************************/
static void LCDSP027_Send_Data(char Data)
{
    char n = 0;
    
    for (n = 0;n<8;n++)
    {
        SP027_CLK = LOW;
        if (Data<<n>>7)
        {
            SP027_DI = HIGH;
        }
        else
        {
            SP027_DI = LOW;
        }
        SP027_CLK = HIGH;
    }
}


⌨️ 快捷键说明

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