📄 lcd.c
字号:
/******************************************************************************
* Copyright (c) 2005 Zoran Corporation.
* All rights reserved.
*
*
* Author: Mark V. Dobrosielski
*
* Description: This is the source file for the UI lcd driver. The driver
* supports any LCD character modules based on the Hitachi
* HD44780 Dot Matrix LCD Controller. The following display
* configurations are supported:
*
* 1 line x 16 characters 2 x 16 4 x 16
* 1 x 20 2 x 20 4 x 20
* 1 x 24 2 x 24
* 1 x 40 2 x 40
*
* Revision History:
* Date Author Description
* ---- ------ -----------
* 8/5/02 Dobro Initial release.
* 6/29/05 JCogan Update to use ts layer.
******************************************************************************/
#include "sys.h"
#include "ts.h"
//#include "sbio.h"
#include "lcd.h"
#if defined(ZR4050)
#define LCD_DELAY_BASE 0
#else
#define LCD_DELAY_BASE 0
#endif
#ifndef LCD_TIME_MEASURE
#define LCD_TIME_MEASURE 0
#endif
#if LCD_TIME_MEASURE
#include "fireregs.h"
#include "iomacros.h"
Uint32 uRegVal;
#endif
/******************************************************************************
Constants/Macros
******************************************************************************/
/* lcd data structure */
typedef struct
{
Bool initialized; /* lcd initialized flag */
} LCD_INFO;
/******************************************************************************
Globals
******************************************************************************/
/******************************************************************************
Statics
******************************************************************************/
/******************************************************************************
Prototypes
******************************************************************************/
/******************************************************************************
Externs
******************************************************************************/
/******************************************************************************
* Name: LcdInit
*
* Description: Initialize (but do not configure) the lcd driver.
*
* 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
*
* Notes: LCD configuration requires SBIO services, which are unavailable
* outside of a task (like in Application_Initialize, where most -
* if not all - init procedures are called). So this procedure
* creates a task whose sole purpose is to configure the LCD. The
* task runs at the highest priority (0) initially, but changes
* its priority to the lowest (255) once configuration is done.
* The LCD is not 'initialized' at the end of this procedure, but
* rather upon completion of configuration in the task.
******************************************************************************/
#include "usbpanel.h"
API_RET LcdInit(void)
{
return UsbPanelInit();
}
/******************************************************************************
* Name: LcdIsInitialized
*
* Description: Reports whether the lcd is initialized or not.
*
* Parameters: None.
*
* Return: TRUE - the lcd is initialized.
* FALSE - the lcd is not initialized.
*
* Notes: This procedure should be used to determine if the lcd services
* are available before attempting to use them.
******************************************************************************/
Bool LcdIsInitialized(void)
{
return UsbPanelIsConnect();
}
/******************************************************************************
* 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 UsbPanelLCDClrLine(line);
}
/******************************************************************************
* 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 UsbPanelLCDClrDisp();
}
/******************************************************************************
* Name: LcdDefineChar
*
* Description: Defines custom characters for use on the lcd display.
*
* Parameters: id - id of the custom character to define (0..7).
* pat - pointer to an 8 byte array containing the bit pattern
* of the custom character.
*
* Return: API_OK - command succeeded.
* API_FAIL - command failed.
* - lcd not initialized
* - invalid id
* - NULL pointer
* - unable to get or release the semaphore
*
* Notes: None.
******************************************************************************/
API_RET LcdDefineChar(Uint8 id, Uint8 *pPattern)
{
int i;
/* set the address of the character generator RAM */
UsbPanelLCDToCGRamPos(id << 3);
/* write the bit pattern to the character generator RAM */
for( i = 0; i < 8; i++ )
{
UsbPanelLCDWriteData(*pPattern++);
}
/* not initialized, trouble getting/releasing the semaphore */
return(API_OK);
}
/******************************************************************************
* Name: LcdChar
*
* Description: Displays a single character on the lcd display at the specified
* location.
*
* Parameters: row - row in which to print the character,
* (0..LCD_NUM_ROWS - 1).
* col - column in which to print the character,
* (0..LCD_NUM_COLS - 1).
* c - the character 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 LcdChar(Uint8 row, Uint8 col, char c)
{
Uint8 rowCnt, colCnt;
if(UsbPanelLCDDim(&rowCnt, &colCnt))
{
if(row < rowCnt)
{
UsbPanelLCDToDDRamPos(row, col);
UsbPanelLCDWriteData(c);
}
}
return(API_OK);
}
/******************************************************************************
* 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)
{
Uint32 len;
Uint8 rowCnt, colCnt;
if(UsbPanelLCDDim(&rowCnt, &colCnt) == API_OK)
{
if(row < rowCnt)
{
UsbPanelLCDToDDRamPos(row, col);
len = strlen(s);
UsbPanelLCDWriteMultiData((Uint8*)s, len);
}
}
return(API_OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -