📄 lcd_hd44780.c
字号:
* Arguments : tUC line = <0,LCD_LINES), tSC *string
* Special Issues : String should have length 1 byte (for termination string
* character '\0') longer than LCD_COLUMNS.
* If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
void LcdGetLineL(tUC line, tSC *str)
{
tUC col;
if(line>(LCD_LINES-1)) return;
col=0;
while(col<LCD_COLUMNS)
{
*str=LcdGetCharLC(line,col);
str++;
col++;
}
*str='\0';
}
#endif
/******************************************************************************
* Module : void LcdGetLineLC(tUC line,tUC col, tSC *str)
* Description : Read text from position Line,Column till the end of
* the line and put it into string.
* Cursor position remains unchanged.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC line = <0,LCD_LINES),
tUC column = <0,LCD_COLUMNS),
tSC *string
* Special Issues : String should have length 1 byte (for termination string
* character '\0') longer than LCD_COLUMNS.
* If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
void LcdGetLineLC(tUC line,tUC col, tSC *str)
{
if(line>(LCD_LINES-1)) return;
if(col >(LCD_COLUMNS-1)) return;
while(col<LCD_COLUMNS)
{
*str=LcdGetCharLC(line,col);
str++;
col++;
}
*str='\0';
}
#endif
/******************************************************************************
* Module : void LcdGetLineLCn(tUC line,tUC col,tUC n, tSC *str)
* Description : Read text from position Line,
* Column till the end of the line or n character were read
* and put it into string.
* Cursor position remains unchanged.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC line = <0,LCD_LINES),
* tUC column = <0,LCD_COLUMNS),
* tUC number of characters,
* tSC *string
* Special Issues : String should have length 1 byte (for termination string
* character '\0') longer than LCD_COLUMNS.
* If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
void LcdGetLineLCn(tUC line,tUC col,tUC n, tSC *str)
{
tUC i;
if(line>(LCD_LINES-1)) return;
if(col >(LCD_COLUMNS-1)) return;
i=0;
while(col<LCD_COLUMNS && i<n)
{
*str=LcdGetCharLC(line,col);
str++;
col++;
i++;
}
*str='\0';
}
#endif
/******************************************************************************
* Module : void LcdGetWordLC(tUC line,tUC col, tSC *str)
* Description : Read text but one word only from position xy
* Cursor position remains unchanged.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC line = <0,LCD_LINES),
* tUC column = <0,LCD_COLUMNS),
* tSC *string
* Special Issues : String should have length 1 byte (for termination string
* character '\0') longer than LCD_COLUMNS.
* If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
void LcdGetWordLC(tUC line,tUC col, tSC *str)
{
tUC chr;
if(line>(LCD_LINES-1)) return;
if(col >(LCD_COLUMNS-1)) return;
while(col<LCD_COLUMNS)
{
chr=LcdGetCharLC(line,col);
if(chr==' ') col=LCD_COLUMNS;
else
{
*str=chr;
str++;
col++;
}
}
*str='\0';
}
#endif
/******************************************************************************
* Module : void LcdOutText(tSC *str)
* Description : Write string to current position. String must be finished
* by '\0'. Maximal LCD_COLUMNS characters is written.
* Autoincrement setup has influence.
* Cursor will be placed behind the last written character.
* It doesn't check end of line.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tSC *string
* Special Issues : none
******************************************************************************/
void LcdOutText(tSC *str)
{
while(*str != '\0')
{
LcdWriteChar(*str);
str++;
}
LcdGetLineCol();
}
/******************************************************************************
* Module : void LcdOutTextL(tUC line, tSC *str)
* Description : Write string to line x. String must be finished by '\0'.
* Maximal LCD_COLUMNS characters is written.
* Autoincrement setup has no influence.
* Cursor will be placed behind the last written character
* or at the end of the line if string overlaps line
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC line = <0,LCD_LINES), tSC *string
* Special Issues : none
* Special Issues : none
******************************************************************************/
void LcdOutTextL(tUC line, tSC *str)
{
tUC col;
if(line>(LCD_LINES-1)) return;
col=0;
while(*str != '\0' && col<LCD_COLUMNS)
{
LcdSetPos(line,col);
LcdWriteChar(*str);
str++;
col++;
}
if(col == LCD_COLUMNS) col--;
LcdSetPos(line,col);
}
/******************************************************************************
* Module : void LcdOutTextLC(tUC line,tUC col, tSC *str)
* Description : Write string to position Line,column.
* String must be finished by '\0'. String is written to
* display till the end of the line or '\0' is reached.
* Autoincrement setup has no influence.
* Cursor will be placed behind the last written character
* or at the end of the line if string overlaps line
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC line = <0,LCD_LINES),
* tUC column = <0,LCD_COLUMNS),
* tSC *string
* Special Issues : none
******************************************************************************/
void LcdOutTextLC(tUC line,tUC col, tSC *str)
{
if(line>(LCD_LINES-1)) return;
if(col >(LCD_COLUMNS-1)) return;
while(*str != '\0' && col<LCD_COLUMNS)
{
LcdSetPos(line,col);
LcdWriteChar(*str);
str++;
col++;
}
if(col == LCD_COLUMNS) col--;
LcdSetPos(line,col);
}
/******************************************************************************
* Module : void LcdOutTextLCn(tUC line,tUC col,tUC n,tSC *str)
* Description : Write string to position Line,Column.
* String must be finished by '\0'.
* String is written to display till given number of
* characters or the end of the line or '\0' is reached.
* Autoincrement setup has no influence.
* Cursor will be placed behind the last written character
* or at the end of the line if string overlaps line
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC line = <0,LCD_LINES),
* tUC column = <0,LCD_COLUMNS),
* tUC number of characters,
* tSC *string
* Special Issues : none
******************************************************************************/
void LcdOutTextLCn(tUC line,tUC col,tUC n,tSC *str)
{
tUC i;
if(line>(LCD_LINES-1)) return;
if(col >(LCD_COLUMNS-1)) return;
i=0;
while(*str != '\0' && col<LCD_COLUMNS && i<n)
{
LcdSetPos(line,col);
LcdWriteChar(*str);
str++;
col++;
i++;
}
if(col == LCD_COLUMNS) col--;
LcdSetPos(line,col);
}
/******************************************************************************
* Module : void LcdRollUp(void)
* Description : Roll display up and set first position on the last line.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : none
* Special Issues : If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
void LcdRollUp(void)
{
tSC line,col;
for(line=1;line<LCD_LINES;line++)
{
for(col=0;col<LCD_COLUMNS;col++)
{
LcdWriteCharLC(line-1,col,LcdGetCharLC(line,col));
}
}
LcdClearLine(LCD_LINES-1);
}
#endif
/******************************************************************************
* Module : void LcdRollDown(void)
* Description : Roll display down and set first posit. on the first line.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : none
* Special Issues : none
* Special Issues : If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
void LcdRollDown(void)
{
tSC line,col;
for(line=LCD_LINES-2;line>=0;line--)
{
for(col=0;col<LCD_COLUMNS;col++)
{
LcdWriteCharLC(line+1,col,LcdGetCharLC(line,col));
}
}
LcdClearLine(0);
}
#endif
/******************************************************************************
* Module : static void LcdClock(void)
* Description : flip/flop E.
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : none
* Special Issues : none
******************************************************************************/
static void LcdClock(void)
{
LCD_E=LCD_TRUE;
LcdDelay1us();
LCD_E=LCD_FALSE;
LcdDelay1us();
}
/******************************************************************************
* Module : static void LcdPutNumberOnIIC(tUC data)
* Description : Put data on IIC data port
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC data,
* Special Issues : none
* Special Issues : none
******************************************************************************/
#ifdef IIC_LCD_TRANSMIT
static void LcdPutNumberOnIIC(tUC data)
{
unsigned char fault=0;
LcdSetUpIIC(); /*setup IIC*/
IIC(IIC_STATUS, STATUS_CLEAR); /*Clear data send flag, IBIF = 1*/
IIC(IIC_CONDITION,IIC_START);
IIC(IIC_CONDITION,IIC_STOP);
IIC(IIC_CONDITION,IIC_START);
IIC(IIC_STATUS, STATUS_CLEAR);
IIC(IIC_DATA_SEND,IIC_SLAVE_ADRESS); /*Send adress*/
while(IIC_STATUS==0){ /*wait for transfer complete flag, ACK flag*/
fault++;
if (fault ==100) return;
}
while(IIC_ACK==1){
fault++;
if (fault ==100) return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -