📄 lcd_hd44780.c
字号:
* Description : set display shift on/off
* Global Data : none
* Static Global Data: Lcd.movingSetup
* Returns : none
* Arguments : tUC onoff = {LCD_SHIFTON, LCD_SHIFTOFF}
* Special Issues : none
******************************************************************************/
void LcdSetDisplayShiftEnable(tUC onoff)
{
switch(onoff&0x40)
{
case LCD_SHIFTON : Lcd.movingSetup&=0x06; /* 0000 0xx0 */
Lcd.movingSetup|=0x05; /* 0000 01x1 */
break;
case LCD_SHIFTOFF : Lcd.movingSetup&=0x06; /* 0000 0xx0 */
Lcd.movingSetup|=0x04; /* 0000 01x0 */
break;
default : return;
}
LcdCommand(Lcd.movingSetup);
}
/******************************************************************************
* Module : void LcdSetDisplayOnOff(tUC onoff)
* Description : set display on/off
* Global Data : none
* Static Global Data: Lcd.onOffControl
* Returns : none
* Arguments : tUC onoff = {LCD_DISPLAYON, LCD_DISPLAYOFF}
* Special Issues : none
******************************************************************************/
void LcdSetDisplayOnOff(tUC onoff)
{
switch(onoff&0x20)
{
case LCD_DISPLAYON : Lcd.onOffControl&=0x03; /* 0000 00xx */
Lcd.onOffControl|=0x0C; /* 0000 11xx */
break;
case LCD_DISPLAYOFF : Lcd.onOffControl&=0x03; /* 0000 00xx */
Lcd.onOffControl|=0x08; /* 0000 10xx */
break;
default : return;
}
LcdCommand(Lcd.onOffControl);
}
/******************************************************************************
* Module : void LcdSetCursorOnOff(tUC onoff)
* Description : set cursor on/off
* Global Data : none
* Static Global Data: Lcd.onOffControl
* Returns : none
* Arguments : tUC onoff = {LCD_CURSORON, LCD_CURSOROFF}
* Special Issues : none
******************************************************************************/
void LcdSetCursorOnOff(tUC onoff)
{
switch(onoff&0x10)
{
case LCD_CURSORON : Lcd.onOffControl&=0x05; /* 0000 0x0x */
Lcd.onOffControl|=0x0A; /* 0000 1x1x */
break;
case LCD_CURSOROFF : Lcd.onOffControl&=0x05; /* 0000 0x0x */
Lcd.onOffControl|=0x08; /* 0000 1x0x */
break;
default : return;
}
LcdCommand(Lcd.onOffControl);
}
/******************************************************************************
* Module : void LcdSetBlinkOnOff(tUC onoff)
* Description : set cursor blink on/off
* Global Data : none
* Static Global Data: Lcd.onOffControl
* Returns : none
* Arguments : tUC onoff = {LCD_BLINKON, LCD_BLINKOFF}
* Special Issues : none
******************************************************************************/
void LcdSetBlinkOnOff(tUC onoff)
{
switch(onoff&0x08)
{
case LCD_BLINKON : Lcd.onOffControl&=0x06; /* 0000 0xx0 */
Lcd.onOffControl|=0x09; /* 0000 1xx1 */
break;
case LCD_BLINKOFF : Lcd.onOffControl&=0x06; /* 0000 0xx0 */
Lcd.onOffControl|=0x08; /* 0000 1xx0 */
break;
default : return;
}
LcdCommand(Lcd.onOffControl);
}
/******************************************************************************
* Module : static void LcdSetDataLength(tUC length)
* Description : set data length interface
* Global Data : none
* Static Global Data: Lcd.interface
* Returns : none
* Arguments : tUC length = {LCD_SETDATA8, LCD_SETDATA4}
* Special Issues : none
******************************************************************************/
static void LcdSetDataLength(tUC length)
{
switch(length&0x04)
{
case LCD_SETDATA8 : Lcd.interface&=0x0F; /* 0000 xxxx */
Lcd.interface|=0x30; /* 0011 xxxx */
break;
case LCD_SETDATA4 : Lcd.interface&=0x0F; /* 0000 xxxx */
Lcd.interface|=0x20; /* 0010 xxxx */
break;
default : return;
}
LcdCommand(Lcd.interface);
}
/******************************************************************************
* Module : static void LcdSetDisplayLines(tUC lines)
* Description : set display memory lines
* Global Data : none
* Static Global Data: Lcd.interface
* Returns : none
* Arguments : tUC length = {LCD_SETLINES1, LCD_SETLINES2}
* Special Issues : none
******************************************************************************/
static void LcdSetDisplayLines(tUC lines)
{
switch(lines&0x02)
{
case LCD_SETLINES2 : Lcd.interface&=0x17; /* 000x 0xxx */
Lcd.interface|=0x28; /* 001x 1xxx */
break;
case LCD_SETLINES1 : Lcd.interface&=0x17; /* 000x 0xxx */
Lcd.interface|=0x20; /* 001x 0xxx */
break;
default : return;
}
LcdCommand(Lcd.interface);
}
/******************************************************************************
* Module : void LcdSetDisplayFont(tUC font)
* Description : set display font
* Global Data : none
* Static Global Data: Lcd.interface
* Returns : none
* Arguments : tUC font = {LCD_LARGEFONT, LCD_SMALLFONT}
* Special Issues : none
******************************************************************************/
void LcdSetDisplayFont(tUC font)
{
switch(font&0x01)
{
case LCD_LARGEFONT: Lcd.interface&=0x1B; /* 000x x0xx */
Lcd.interface|=0x24; /* 001x x1xx */
break;
case LCD_SMALLFONT: Lcd.interface&=0x1B; /* 000x x0xx */
Lcd.interface|=0x20; /* 001x x0xx */
break;
default : return;
}
LcdCommand(Lcd.interface);
}
/******************************************************************************
* Module : void LcdShiftDisplay(tUC direction)
* Description : shift display
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC direction = {LCD_RIGHT, LCD_LEFT}
* Special Issues : none
******************************************************************************/
void LcdShiftDisplay(tUC direction)
{
switch(direction)
{
case LCD_RIGHT : direction&=0x1C; /* 0001 1100 */
break;
case LCD_LEFT : direction&=0x18; /* 0001 1000 */
break;
default : return;
}
LcdCommand(direction);
}
/******************************************************************************
* Module : void LcdMoveCursor(tUC direction)
* Description : move cursor and set position
* Global Data : none
* Static Global Data: Lcd.cursor.address, Lcd.cursor.line, Lcd.cursor.col
* Returns : none
* Arguments : tUC direction = {LCD_RIGHT, LCD_LEFT, LCD_DOWN, LCD_UP}
* Special Issues : none
******************************************************************************/
void LcdMoveCursor(tUC direction)
{
LcdGetLineCol();
switch(direction)
{
case LCD_RIGHT : Lcd.cursor.col++;
if(Lcd.cursor.col > (LCD_COLUMNS-1)) Lcd.cursor.col=0;
break;
case LCD_LEFT : Lcd.cursor.col--;
if(Lcd.cursor.col > (LCD_COLUMNS-1)) Lcd.cursor.col=19;
break;
case LCD_DOWN : Lcd.cursor.line++;
if(Lcd.cursor.line > (LCD_LINES-1)) Lcd.cursor.line=0;
break;
case LCD_UP : Lcd.cursor.line--;
if(Lcd.cursor.line > (LCD_LINES-1)) Lcd.cursor.line=3;
break;
default : return;
}
LcdSetPos(Lcd.cursor.line,Lcd.cursor.col);
}
/******************************************************************************
* Module : void LcdSetAddressCGRAM(tUC address)
* Description : set CG RAM address
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC address
* Special Issues : none
******************************************************************************/
void LcdSetAddressCGRAM(tUC address)
{
if(address > 0x3F) return; /* 0011 1111 */
address=address|0x40 ;
LcdCommand(address);
}
/******************************************************************************
* Module : void LcdSetAddressDDRAM(tUC address)
* Description : set DDRAM address
* Global Data : none
* Static Global Data: none
* Returns : none
* Arguments : tUC address
* Special Issues : none
******************************************************************************/
void LcdSetAddressDDRAM(tUC address)
{
if(address > 0x7F) return; /* 0111 1111 */
address|=0x80;
LcdCommand(address);
LcdGetLineCol();
}
/******************************************************************************
* Module : static tUC LcdReadDataPort(tUC what)
* Description : read DDRAM address counter + BUSY bit or
* DDRAM address value
* Global Data : none
* Static Global Data: none
* Returns : byte representing required value
* Arguments : tUC what={LCD_BUSY=read DDRAM addres + BUSY bit, LCD_DATA}
* Special Issues : If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
static tUC LcdReadDataPort(tUC what)
{
tUC aux;
tUC dir;
dir=LcdGetPortDirection(); /* Lcd get port direction */
LcdSetPortDirection(LCD_INPORT); /* Lcd set port direction */
if(what==LCD_BUSY)
{
LCD_RS = LCD_CTRL; /* set control on display */
LCD_RW = LCD_READ; /* set read display */
}
else
{
LCD_RS = LCD_DATA; /* set control on display */
LCD_RW = LCD_READ; /* set read display */
}
LCD_E = LCD_TRUE;
LcdDelay1us();
aux = LCD_DPORT; /* read full word (8-bit communication) or MSB */
/* nibble (4-bit comm.) */
#ifdef LCD_DATAWIDTH_4 /* */
LCD_E = LCD_FALSE;
LcdDelay1us();
#ifdef LCD_DPORTH
aux &= 0xF0; /* filter MSB nibble */
#endif
#ifdef LCD_DPORTL
aux = (aux <<4) & 0xF0; /* filter MSB nibble */
#endif
LCD_E = LCD_TRUE;
LcdDelay1us();
#ifdef LCD_DPORTH
aux |= ((LCD_DPORT>>4) & 0x0F); /* filter LSB nibble */
#endif
#ifdef LCD_DPORTL
aux |= (LCD_DPORT & 0x0F); /* filter LSB nibble */
#endif
#endif
LCD_E = LCD_FALSE;
LcdDelay1us();
LcdSetPortDirection(dir); /* Lcd set port direction */
return(aux);
}
#endif
/******************************************************************************
* Module : static tUC LcdReadBusyFlag(void)
* Description : read Busy Flag (bit 7 on DPORT)
* Global Data : none
* Static Global Data: none
* Returns : 0 (BUSY=0 or definition LCD_NO_READ_FUNCTION exists)
* 0x80 (BUSY=1)
* Arguments : none
* Special Issues : none
******************************************************************************/
#ifdef LCD_NO_READ_FUNCTION
/* the number of microseconds necessary to wait till driver is ready again */
#define LCDBUSYTIME (1 + (( 37 * 270 ) / HD44780_FOSC))
#endif
static tUC LcdReadBusyFlag(void)
{
#ifdef LCD_NO_READ_FUNCTION
tUC i=LCDBUSYTIME;
LcdDelay1us();
while(i--) LcdDelay1us();
return(0);
#else
LcdDelay1us();
return(LcdReadDataPort(LCD_BUSY)&0x80); /* test */
#endif
}
/******************************************************************************
* Module : static tUC LcdGetAddressDDRAM(void)
* Description : read DDRAM address counter
* Global Data : none
* Static Global Data: none
* Returns : DDRAM address counter content
* Arguments : none
* Special Issues : If definition LCD_NO_READ_FUNCTION exists the function is
* not accesible.
******************************************************************************/
#ifndef LCD_NO_READ_FUNCTION
static tUC LcdGetAddressDDRAM(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -