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

📄 lcd.c

📁 官方的UCOSii的移植文件
💻 C
📖 第 1 页 / 共 2 页
字号:
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                            DUMMY FUNCTION
*
* Description : This function doesn't do anything.  It is used to act like a NOP (i.e. No Operation) to
*               waste a few CPU cycles and thus, act as a short delay.
* Arguments   : none
* Returns     : none
*********************************************************************************************************
*/

void  DispDummy (void)
{
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       DISPLAY A HORIZONTAL BAR
*
* Description : This function allows you to display horizontal bars (bar graphs) on the LCD module.
* Arguments   : 'row'   is the row    position of the cursor in the LCD Display
*                       'row' can be a value from 0 to 'DispMaxRows - 1'
*               'val'   is the value of the horizontal bar.  This value cannot exceed:
*                           DispMaxCols * 5
* Returns     : none
* Notes       : To use this function, you must first call DispHorBarInit()
*********************************************************************************************************
*/

void  DispHorBar (CPU_INT08U row, CPU_INT08U col, CPU_INT08U val)
{
    CPU_INT08U i;
    CPU_INT08U full;
    CPU_INT08U fract;


    full  = val / 5;                        /* Find out how many 'full' blocks to turn ON              */
    fract = val % 5;                        /* Compute portion of block                                */
    if (row < DispMaxRows && (col + full - 1) < DispMaxCols) {
        DispLock();
        i = 0;                              /* Set counter to limit column to maximum allowable column */
        DispCursorSet(row, col);            /* Position cursor at beginning of the bar graph           */
        DispSel(DISP_SEL_DATA_REG);
        while (full > 0) {                  /* Write all 'full' blocks                                 */
            DispDataWr(5);                  /* Send custom character #5 which is full block            */
            i++;                            /* Increment limit counter                                 */
            full--;
        }
        if (fract > 0) {
            DispDataWr(fract);              /* Send custom character # 'fract' (i.e. portion of block) */
        }
        DispUnlock();
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      INITIALIZE HORIZONTAL BAR
*
* Description : This function is used to initialize the bar graph capability of this module.  You must
*               call this function prior to calling DispHorBar().
* Arguments   : none
* Returns     : none
*********************************************************************************************************
*/

void  DispHorBarInit (void)
{
    DispDefChar(1, &DispHorBar1[0]);
    DispDefChar(2, &DispHorBar2[0]);
    DispDefChar(3, &DispHorBar3[0]);
    DispDefChar(4, &DispHorBar4[0]);
    DispDefChar(5, &DispHorBar5[0]);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       DISPLAY A VERTICAL BAR
*
* Description : This function allows you to display vertical bars (bar graphs) on the LCD module.
* Arguments   : 'row'   is the row    position of the cursor in the LCD Display
*                       'row' can be a value from 0 to 'DispMaxRows - 1'
*               'val'   is the value of the vertical bar.  This value cannot exceed 8 (i.e. 8 bars per character)
*
* Returns     : none
* Notes       : To use this function, you must first call DispVerBarInit()
*********************************************************************************************************
*/

void  DispVertBar (CPU_INT08U row, CPU_INT08U col, CPU_INT08U val)
{
    if (row < DispMaxRows && col < DispMaxCols) {
        DispLock();
        DispCursorSet(row, col);            /* Position cursor at beginning of the bar graph           */
        DispSel(DISP_SEL_DATA_REG);
        switch (val) {
            case 0:
                 DispDataWr(' ');           /* Display NO bars                                         */
                 break;

            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                 DispDataWr(val - 1);       /* Display between 1 and 8 bars                            */
                 break;

            default:
                 DispDataWr(7);             /* Always display 8 bars                                   */
                 break;
        }
        DispUnlock();
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      INITIALIZE VERTICAL BAR
*
* Description : This function is used to initialize the bar graph capability of this module.  You must
*               call this function prior to calling DispVerBar().
* Arguments   : none
* Returns     : none
*********************************************************************************************************
*/

void  DispVertBarInit (void)
{
    DispDefChar(0, &DispVertBar1[0]);
    DispDefChar(1, &DispVertBar2[0]);
    DispDefChar(2, &DispVertBar3[0]);
    DispDefChar(3, &DispVertBar4[0]);
    DispDefChar(4, &DispVertBar5[0]);
    DispDefChar(5, &DispVertBar6[0]);
    DispDefChar(6, &DispVertBar7[0]);
    DispDefChar(7, &DispVertBar8[0]);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      DISPLAY DRIVER INITIALIZATION
*
* Description : This function initializes the display driver.
* Arguments   : maxrows      specifies the number of lines on the display (1 to 4)
*               maxcols      specified the number of characters per line
* Returns     : None.
* Notes       : - DispInit() MUST be called only when multitasking has started.  This is because
*                 DispInit() requires time delay services from the operating system.
*               - DispInit() MUST only be called once during initialization.
*********************************************************************************************************
*/

void  DispInit (CPU_INT08U maxrows, CPU_INT08U maxcols)
{
    DispInitOS();                      /* Initialize the RTOS services                                 */

    DispInitPort();                    /* Initialize I/O ports used in display driver                  */

    DispMaxRows = maxrows;
    DispMaxCols = maxcols;

                                       /* INITIALIZE THE DISPLAY MODULE                                */
    DispSel(DISP_SEL_CMD_REG);         /* Select command register.                                     */
    DispDly_uS(50000);                 /* Delay more than 15 mS after power up                         */

#if DISP_BUS_WIDTH == 4
    DispDataWrOneNibble(DISP_CMD_FNCT_INIT8);/* Function Set: 8 bit, Only writes upper nibble          */
    DispDly_uS(5000);                  /* Busy flag cannot be checked yet!  5 FNCT writes recommended! */

    DispDataWrOneNibble(DISP_CMD_FNCT_INIT8);/* Function Set: 8 bit, Only writes upper nibble          */
    DispDly_uS(5000);                        /* Busy flag cannot be checked yet!                       */

    DispDataWrOneNibble(DISP_CMD_FNCT_INIT8);/* Function Set: 8 bit, Only writes upper nibble          */
    DispDly_uS(5000);                        /* Busy flag cannot be checked yet!                       */

    DispDataWrOneNibble(DISP_CMD_FNCT_INIT4);/* Function Set: 4 bit, Only writes upper nibble          */
    DispDly_uS(5000);                        /* Busy flag cannot be checked yet!                       */
#else
   DispDataWr(DISP_CMD_FNCT_INIT8);    /* Two lines, 1/16 duty cycle, 5x8 dots, 8 bit operation        */
   DispDly_uS(2000);                   /* 4 FNCT writes recommended in Hitachi datasheet!              */

   DispDataWr(DISP_CMD_FNCT_INIT8);    /* Two lines, 1/16 duty cycle, 5x8 dots, 8 bit operation        */
   DispDly_uS(2000);                   /* Busy flag cannot be checked yet!                             */

   DispDataWr(DISP_CMD_FNCT_INIT8);    /* Two lines, 1/16 duty cycle, 5x8 dots, 8 bit operation        */
   DispDly_uS(2000);                   /* Busy flag cannot be checked yet!                             */
#endif

    DispDataWr(DISP_CMD_FNCT);         /* Two lines, 1/16 duty cycle, 5x8 dots, Operation Mode         */
    DispDly_uS(2000);                  /* Optional: Busy flag can now be checked yet                   */

    DispDataWr(DISP_CMD_ON_OFF);       /* Disp ON/OFF: Display ON, cursor OFF and no BLINK character   */
    DispDly_uS(2000);                  /* Delay at least  2 mS                                         */

    DispDataWr(DISP_CMD_CLS);          /* Send command to LCD display to clear the display             */
    DispDly_uS(2000);                  /* Delay at least  2 mS                                         */

    DispDataWr(DISP_CMD_MODE);         /* Entry mode: Inc. display data address when writing           */
    DispDly_uS(2000);                  /* Delay at least  2 mS                                         */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                         DISPLAY AN ASCII STRING
*
* Description : This function is used to display an ASCII string on a line of the LCD display
* Arguments   : 'row'   is the row    position of the cursor in the LCD Display
*                       'row' can be a value from 0 to 'DispMaxRows - 1'
*               'col'   is the column position of the cursor in the LCD Display
*                       'col' can be a value from 0 to 'DispMaxCols - 1'
*               's'     is a pointer to the string to write to the display at
*                       the desired row/col.
* Returns     : none
*********************************************************************************************************
*/

void  DispStr (CPU_INT08U row, CPU_INT08U col, CPU_INT08U *s)
{
    CPU_INT08U i;


    if (row < DispMaxRows && col < DispMaxCols) {
        DispLock();
        DispCursorSet(row, col);            /* Position cursor at ROW/COL                              */
        DispSel(DISP_SEL_DATA_REG);
        i = col;                            /* Set counter to limit column to maximum allowable column */
        while (i < DispMaxCols && *s) {     /* Write all chars within str + limit to DispMaxCols       */
            DispDataWr(*s++);               /* Send character to LCD display                           */
            i++;                            /* Increment limit counter                                 */
        }
        DispUnlock();
    }
}

⌨️ 快捷键说明

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