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

📄 bsp.c

📁 基于 Philips 公司的 ARM-7 使用之 uC/OS-II 作业系统,此例程是移植于 LPC-2888 上的应用,不同于一般的 Porting 其最主要是加入了支援 OS_View 观察器功能
💻 C
📖 第 1 页 / 共 4 页
字号:
******************************************************************************************************************************
*                                           LCD FUNCTIONS
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                     WRITE LINE TO DISPLAY
*
* Description: This function displays on the LCD display at a specified line position.
*
* Argument(s): s        is an array of ASCII-encoded characters.
*              line     is the character line number between 0 and 7.
*
* Returns    : None
*
* Note(s)    : (1) The pixel-representation of each character is stored in the array
*                  BSP_LCD_Charset.  Representations of characters with codes 0x20 through 0x7E are
*                  provided.
*********************************************************************************************************
*/

void  LCD_DispStr (CPU_INT08U line, CPU_INT08U col, CPU_INT08U *s)
{
    CPU_INT08U  i;
    CPU_INT08U  c;


    LCD_SetPosition(line, col);                                 /* Set position at which string will be displayed           */
    while (*s != 0) {
        c = *s;                                                 /* Store the current character                              */
        for (i = 0; i < 8; i++) {                               /* For each of the eight columns in the character           */
            LCD_WrData(BSP_LCD_Charset[c-32][i]);               /* Write the pixel data to the LCD                          */
        }
        s++;                                                    /* Increment the pointer                                    */
    }
}


/*
*********************************************************************************************************
*                                  WRITE CHARACTER TO DISPLAY
*
* Description: This function displays a character at the specified position of the LCD display.
*
* Argument(s): c        is an ASCII-encoded character.
*              line     is the character line number between 0 and 7.
*              col      is the character column number between 0 and 15.
*
* Returns    : None
*
* Note(s)    : See note (1) for LCD_DispChar
*********************************************************************************************************
*/

void  LCD_DispChar (CPU_INT08U line, CPU_INT08U col, CPU_INT08U c)
{
    CPU_INT08U  i;


    LCD_SetPosition(line, col);                                 /* Set position at which character will be displayed        */
    for (i = 0; i < 8; i++) {                                   /* For each of the eight columns in the character           */
        LCD_WrData(BSP_LCD_Charset[c-32][i]);                   /* Write the pixel data to the LCD                          */
    }
}


/*
*********************************************************************************************************
*                                   CLEAR LINE ON DISPLAY
*
* Description: This function clears one line of the display.
*
* Argument(s): line     is the character line number between 0 and 7.
*
* Returns    : None
*********************************************************************************************************
*/

void  LCD_DispClrLine (CPU_INT08U line)
{
    CPU_INT08U  c_pos;
    CPU_INT08U  i;


    if (line < BSP_LCD_NUMBER_OF_LINES) {                       /* If line is a valid line number                           */
        LCD_SetPosition(line, 0);                               /* Set postion to first character in line to clear          */
        for (c_pos = 0; c_pos < BSP_LCD_CHARACTERS_PER_LINE; c_pos++) {
            for (i = 0; i < 8; i++) {                           /* For each of the eight columns in a character             */
                LCD_WrData(BSP_LCD_Charset[0][i]);              /* Write the pixel data for a space to the LCD              */
            }
        }
    }
}



/*
*********************************************************************************************************
*                                         CLEAR DISPLAY
*
* Description: This function clears the display.
*
* Argument(s): None
*
* Returns    : None
*
* Note(s)    : (1)  The screen includes a 9th "page", which is a row a single pixel tall at the very
*                   bottom of the screen.
*********************************************************************************************************
*/

void  LCD_ClrScr (void)
{
    CPU_INT08U  page;
    CPU_INT16U  column;


    for (page = 0; page < BSP_LCD_NUMBER_OF_PAGES; page++) {
        LCD_SetPosition(page, 0);
        for (column = 0; column < BSP_LCD_COLUMNS_PER_PAGE; column++) {
            LCD_WrData(0x00);
        }
    }
}


/*
*********************************************************************************************************
*                                         SET START LINE
*
* Description: This function sets the line from the LCD controller's RAM which will appear at the top of
*              the display.
*
* Argument(s): line     the line, between 0 and 63 (inclusive), which will appear at the top of the
*                       display
*
* Returns    : None
*********************************************************************************************************
*/

void  LCD_SetStartLine (CPU_INT08U line)
{
    LCD_WrCmd(LCD_START_LINE_SET + (line & 0x3F));
}


/*
*********************************************************************************************************
*                                         SET BRIGHTNESS
*
* Description: This function sets the brightness of the display.
*
* Argument(s): brightness   the brightness, between 0 and 63.
*
* Returns    : None
*********************************************************************************************************
*/

void  LCD_SetBrightness (CPU_INT08U brightness)
{
    LCD_WrCmd(LCD_ELECTRONIC_VOLUME_SET );
    LCD_WrCmd(brightness & 0x3F);
}


/*
*********************************************************************************************************
*                                     WRITE COMMAND TO LCD DISPLAY
*
* Description: This function writes a command to the LCD display.
*
* Argument(s): cmd      is the byte command to be written to the display.
*
* Returns    : None
*********************************************************************************************************
*/

static  void  LCD_WrCmd (CPU_INT08U cmd)
{
    CPU_INT32U  status;


    status = (LCDSTAT >> 5) & 0x1F;                             /* Determine number of bytes in output FIFO                 */
    while (status >= 0x0E) {                                    /* Wait if number of bytes exceeds 14                       */
        status = (LCDSTAT >> 5) & 0x1F;                         /* Determine number of bytes in output FIFO                 */
    }

    LCDIBYTE = cmd;                                             /* Write outgoing byte to register                          */
}


/*
*********************************************************************************************************
*                                  WRITE BYTE OF DATA TO LCD DISPLAY
*
* Description: This function writes a byte of data to the LCD display.
*
* Argument(s): data     is the byte of data to be written to the display.
*
* Returns    : None
*********************************************************************************************************
*/

static  void  LCD_WrData (CPU_INT08U data)
{
    CPU_INT32U  status;


    status = (LCDSTAT >> 5) & 0x1F;                             /* Determine number of bytes in output FIFO                 */
    while (status >= 0x0E) {                                    /* Wait if number of bytes exceeds 14                       */
        status = (LCDSTAT >> 5) & 0x1F;                         /* Determine number of bytes in output FIFO                 */
    }

    LCDDBYTE = data;                                            /* Write outgoing byte to register                          */
}


/*
*********************************************************************************************************
*                                  INITIALIZE THE LCD DISPLAY
*
* Description: This function initializes the LCD display.
*
* Argument(s): None
*
* Returns    : None
*********************************************************************************************************
*/

static  void  LCD_Init (void)
{
    LCDCTRL    = 0x4000;                                        /* Select clock behavior for LCD                            */

    LCD_WrCmd(LCD_RESET_DISPLAY         );
    LCD_WrCmd(LCD_BIAS_SET_1_9          );
    LCD_WrCmd(LCD_ADC_SELECT_REVERSE    );
    LCD_WrCmd(LCD_COMMON_OUTPUT_NORMAL  );
    LCD_WrCmd(LCD_V5_RESISTOR_RATIO     );
    LCD_WrCmd(LCD_ELECTRONIC_VOLUME_SET );
    LCD_WrCmd(LCD_ELECTRONIC_VOLUME_INIT);
    LCD_WrCmd(LCD_POWER_CONTROL_SET |
              LCD_VOLTAGE_REGULATOR |
              LCD_VOLTAGE_FOLLOWER  |
              LCD_BOOSTER_CIRCUIT       );
    LCD_WrCmd(LCD_DISPLAY_REVERSE       );
    LCD_WrCmd(LCD_DISPLAY_ON            );
}


/*
*********************************************************************************************************
*                                SET CURRENT DISPLAY POSITION
*
* Description: This function sets the current position of the LCD display.
*
* Argument(s): line     is the character line number between 0 and 7.
*              col      is the character column number between 0 and 15.
*
* Returns    : None
*
* Note(s)    : (1)  The character column must be multiplied by 8 (or shifted left by 3 bits) to
*                   calculate the pixel column.  This calculation is integrated into the operations
*                   for extracting the upper and lower nibbles of the pixel column position.
*********************************************************************************************************
*/

static  void  LCD_SetPosition (CPU_INT08U line, CPU_INT08U col)
{
    CPU_INT08U  nibble_upper;
    CPU_INT08U  nibble_lower;


    nibble_upper = (col & 0x1E) >> 1;                           /* Extract four bits of col: 000****0                       */
    nibble_lower = (col & 0x01) << 3;                           /* Extract lowest bit of col.                               */

    LCD_WrCmd(LCD_PAGE_ADDRESS_SET + line                    );
    LCD_WrCmd(LCD_COLUMN_ADDRESS_UPPER_BIT_SET | nibble_upper);
    LCD_WrCmd(LCD_COLUMN_ADDRESS_LOWER_BIT_SET | nibble_lower);
}


/*
******************************************************************************************************************************
*                                           LED SERVICES
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                         TOGGLE THE LED
*
* Description: This function toggles the LED.
*
* Argument(s): led      The id of the LED to toggle.  For this board, the only valid value is 1.
*
* Returns    : None
*
*********************************************************************************************************
*/

void  LED_Toggle (CPU_INT08U led)
{
    if (led == 1) {
        if ((MODE1_2 & BSP_LED) != 0 && (MODE0_2 & BSP_LED) ==0) {      /* LED is on                                        */
            MODE1S_2 = BSP_LED;
            MODE0S_2 = BSP_LED;
        } else {                                                        /* LED is off                                       */
            MODE1S_2 = BSP_LED;
            MODE0C_2 = BSP_LED;
        }
    }
}

/*
*********************************************************************************************************
*                                         TURN ON THE LED
*
* Description: This function turns ON the LED.
*
* Argument(s): led      The id of the LED to turn ON.  For this board, the only valid value is 1.
*
* Returns    : None
*
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    if (led == 1) {
        MODE1S_2 = BSP_LED;
        MODE0C_2 = BSP_LED;
    }
}

/*
*********************************************************************************************************
*                                         TURN OFF THE LED
*
* Description: This function turns OFF the LED.

⌨️ 快捷键说明

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