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

📄 textlcd.c

📁 这个是单片机4200的ui程序
💻 C
字号:
/*
 *  Start of Zoran Standard Header
 *  Copyright (c) 2005 Zoran Corporation
 *  
 *  
 *  All rights reserved.  Proprietary and confidential.
 *  
 *  DESCRIPTION for textlcd.c
 *      Combo-board LCD interface to support the text-only user interface.
 *  
 *  NEW HISTORY COMMENT (description must be followed by a blank line)
 *  <Enter change description here>

 *  ===== HISTORY of changes in //depot/imgeng/sw/se_gw/ui/fs/comboui/textlcd.c
 *  
 *  19/Aug/05 #2  dstrauss  Fill out LcdStr() and add an init routine.
 *  5/Aug/05 #1  dstrauss  Created.  Stub routines for now.
 *  
 *  End of Zoran Standard Header
 */
#include "univ.gh"
#include "arch.h"
#include "pile.h"
#include "dbg.h"
#include "standard.h"
#include "ts.h"

#include "uimisc.h"
#include "uilcd.h"
#include "textlcd.h"
#include "hwaccess.h"

/***************************************************************
   HD44780 Commands
   ----------------
   Entry Mode:       I/D = 1  Cursor increments on data write
                       S = 0  No display shift on data write
   Display Control:    D = 1  Display on
                       C = 0  Cursor off
                       B = 0  Blinking off
   Shift Control:    S/C = 0  Don't shift display
                     R/L = 0  Don't shift cursor
   Function Mode:     DL = 1  Data Length = 8 bits
                       N = 1  Number of lines = 2
                       F = 0  5x8 font
***************************************************************/
#define LCD_CMD_CLS     0x01  /* Clear display     */
#define LCD_CMD_ENTRY   0x06  /* Entry Mode Set    */
#define LCD_CMD_DISPLAY 0x0C  /* Display Control   */
#define LCD_CMD_SHIFT   0x10  /* Shift Control     */
#define LCD_CMD_FNCT    0x38  /* Function Mode Set */


#define LCD_NUM_ROWS   2
#define LCD_NUM_COLS   16

static tsSemaphore lcdSem;      /* lcd semaphore  */


/******************************************************************************
* Name:        LcdCmdWrite
*
* Description: Writes a byte to the command register of the lcd display.
*
* Parameters:  cmd   - the command byte to write to the display.
*
* Return:      None.
*
******************************************************************************/
static void LcdCmdWrite(Uint8 cmd)
{
  hwAccessLock(TRUE);
  *(volatile unsigned char *)0xec000700 = cmd;
  TASKSLEEP_MILLISECONDS(4);
  hwAccessUnlock(TRUE);
}

/******************************************************************************
* Name:        LcdDataWrite
*
* Description: Writes a byte to the data register of the lcd display.
*
* Parameters:  data  - the data byte to write to the display.
*
* Return:      None.
*
******************************************************************************/
LOCAL void LcdDataWrite(Uint8 data)
{
  hwAccessLock(TRUE);
  *(volatile unsigned char *)0xec000f00 = data;
  TASKSLEEP_MILLISECONDS(4);
  hwAccessUnlock(TRUE);
}

/******************************************************************************
* Name:        LcdCursorSet
*
* Description: Positions the cursor on the lcd display.
*
* Parameters:  row   - row in which to place the cursor,
*                       (0..LCD_NUM_ROWS - 1).
*              col   - column in which to place the cursor,
*                       (0..LCD_NUM_COLS - 1).
*
* Return:      None.
*
* Notes:       This procedure assumes that the row & column parameters have
*              already been validated.
*              This procedure accesses the lcd, and should only be called if
*              the lcd semaphore has already been acquired.
******************************************************************************/
static void LcdCursorSet(Uint8 row, Uint8 col)
{
  if (row == 0) {
    LcdCmdWrite(0x80 + col);    /* Select LCD line 1 */
  } else {
    LcdCmdWrite(0xC0 + col);    /* Select LCD line 2 */
  }
}

/******************************************************************************
* Name:        LcdStr
*
* Description: Displays a character string on the lcd display starting at the
*              specified location.
*
* Parameters:  row   - row in which to start printing the character string,
*                       (0..LCD_NUM_ROWS - 1).
*              col   - column in which to start printing the character string,
*                       (0..LCD_NUM_COLS - 1).
*              s     - pointer to the string to print.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - lcd not initialized
*                          - invalid row
*                          - invalid column
*                          - unable to get or release the semaphore
*
* Notes:       None.
******************************************************************************/
API_RET LcdStr(Uint8 row, Uint8 col, char *s)
{
  int i;

  /* validate parameters */
  if ((row < LCD_NUM_ROWS) && (col < LCD_NUM_COLS)) {

    TASKSEMWAIT(lcdSem);        /* wait for the semaphore */

    /* position the cursor */
    LcdCursorSet(row, col);

    /* write the string to the display, but don't wrap to next line */
    for( i = col; (i < LCD_NUM_COLS) && *s; i++ ) {
      LcdDataWrite(*s++);	/* write the character to the display */
    }

    TASKSEMSIGNAL(lcdSem);      /* release the semaphore */

    return(API_OK);
  }
  return API_FAIL;
}

/******************************************************************************
* Name:        LcdClrScreen
*
* Description: Clears all lines of the LCD display and positions the cursor at
*              the beginning of line 0.
*
* Parameters:  None.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - lcd not initialized
*                          - unable to get or release the semaphore
*
* Notes:       None.
******************************************************************************/
API_RET LcdClrScreen(void)
{
  return API_OK;
}

/******************************************************************************
* Name:        LcdClrLine
*
* Description: Clears one line of the LCD display and positions the cursor at
*              the beginning of the line.
*
* Parameters:  line  - the line to clear (0..LCD_NUM_ROWS - 1).
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - lcd not initialized
*                          - invalid line number
*                          - unable to get or release the semaphore
*
* Notes:       None.
******************************************************************************/
API_RET LcdClrLine(Uint8 line)
{
  return API_OK;
}

/******************************************************************************
* Name:        TextLCDInit
*
* Description: Initialize the text-only lcd interface
*
* Parameters:  None.
*
* Return:      API_OK   - command succeeded.
*              API_FAIL - command failed.
*                          - SBIOs not initialized
*                          - unable to create the lcd semaphore
*                          - unable to create the lcd configuration task
*
******************************************************************************/
void TextLCDInit(void)
{
  /*****************************/
  /* Initialize the LCD module */
  /*****************************/
  lcdSem = TaskSemCreate(1);
  ASSERT(lcdSem > INVALIDSEM);

  /* Delay 50 msec after power up */
  TASKSLEEP_MILLISECONDS(50);

  /* Function Set (sent 4 times) */
  LcdCmdWrite(LCD_CMD_FNCT);
  TASKSLEEP_MILLISECONDS(4);
  LcdCmdWrite(LCD_CMD_FNCT);
  TASKSLEEP_MILLISECONDS(4);
  LcdCmdWrite(LCD_CMD_FNCT);
  TASKSLEEP_MILLISECONDS(4);
  LcdCmdWrite(LCD_CMD_FNCT);
  TASKSLEEP_MILLISECONDS(4);

  /* Display On/Off Control */
  LcdCmdWrite(LCD_CMD_DISPLAY);

  /* Entry Mode Set */
  LcdCmdWrite(LCD_CMD_ENTRY);

  /* Cursor & Display Shift */
  LcdCmdWrite(LCD_CMD_SHIFT);

  /* Clear the display (takes at least 2msec) */
  LcdCmdWrite(LCD_CMD_CLS);
  TASKSLEEP_MILLISECONDS(4);

}

⌨️ 快捷键说明

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