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

📄 lcd_hd44780.c

📁 freescale最新的16位单片机
💻 C
📖 第 1 页 / 共 5 页
字号:
 return(LcdReadDataPort(LCD_BUSY) & 0x7F);
}
#endif
/******************************************************************************
* Module            : static void LcdGetLineCol(void)
* Description       : read display line, column, 
*                     DDRAM addres counter and put them into LCD structure
* Global Data       : none
* Static Global Data: Lcd.cursor.address, Lcd.cursor.line, Lcd.cursor.col
* Returns           : none
* Arguments         : none
* Special Issues    : If definition LCD_NO_READ_FUNCTION exists the function is
*                     not accesible.
******************************************************************************/
#ifndef  LCD_NO_READ_FUNCTION

static void LcdGetLineCol(void)
{
 Lcd.cursor.address=LcdGetAddressDDRAM();

 if(Lcd.cursor.address>=LCD_LINE3ADDR && 
    Lcd.cursor.address<=(LCD_LINE3ADDR+LCD_COLUMNS-1))   
   {
	 Lcd.cursor.line=3;
    Lcd.cursor.col  = Lcd.cursor.address - LCD_LINE3ADDR;
	} 
 if(Lcd.cursor.address>=LCD_LINE2ADDR &&
    Lcd.cursor.address<=(LCD_LINE2ADDR+LCD_COLUMNS-1))   
   {
	 Lcd.cursor.line=2;
    Lcd.cursor.col  = Lcd.cursor.address - LCD_LINE2ADDR;
	} 
 if(Lcd.cursor.address>=LCD_LINE1ADDR &&
    Lcd.cursor.address<=(LCD_LINE1ADDR+LCD_COLUMNS-1))   
   {
	 Lcd.cursor.line=1;
    Lcd.cursor.col  = Lcd.cursor.address - LCD_LINE1ADDR;
	} 
 if(Lcd.cursor.address<=(LCD_LINE0ADDR+LCD_COLUMNS-1))
   {
	 Lcd.cursor.line=0;
    Lcd.cursor.col  = Lcd.cursor.address - LCD_LINE0ADDR;
	} 
}
#endif
/******************************************************************************
* Module            : tUC LcdGetColPos(void)
* Description       : read display column position
* Global Data       : none
* Static Global Data: Lcd.cursor.address, Lcd.cursor.line, Lcd.cursor.col
* Returns           : diplay column
* Arguments         : none
* Special Issues    : If definition LCD_NO_READ_FUNCTION exists the function is
*                     not accesible.
******************************************************************************/
#ifndef  LCD_NO_READ_FUNCTION

tUC LcdGetColPos(void)
{
 LcdGetLineCol();
 return(Lcd.cursor.col);
}
#endif
/******************************************************************************
* Module            : tUC LcdGetLinePos(void)
* Description       : read display line position
* Global Data       : none
* Static Global Data: Lcd.cursor.address, Lcd.cursor.line, Lcd.cursor.col
* Returns           : diplay line
* Arguments         : none
* Special Issues    : If definition LCD_NO_READ_FUNCTION exists the function is
*                     not accesible.
******************************************************************************/
#ifndef  LCD_NO_READ_FUNCTION

tUC LcdGetLinePos(void)
{
 LcdGetLineCol();
 return(Lcd.cursor.line);
}
#endif
/******************************************************************************
* Module            : tUC LcdGetDDRAMPos(void)
* Description       : read display DDRAM addres pointer
* Global Data       : none
* Static Global Data: Lcd.cursor.address, Lcd.cursor.line, Lcd.cursor.col
* Returns           : DDRAM address
* Arguments         : none
* Special Issues    : If definition LCD_NO_READ_FUNCTION exists the function is
*                     not accesible.
******************************************************************************/
#ifndef  LCD_NO_READ_FUNCTION

tUC LcdGetDDRAMPos(void)
{
 LcdGetLineCol();
 return(Lcd.cursor.address);
}
#endif
/******************************************************************************
* Module            : static tUC LcdGetPortDirection(void)
* Description       : Get data port direction (content of DDR register)
* 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
static tUC LcdGetPortDirection(void)
{
   return(LCD_DPORTDIR);
}
#endif
/******************************************************************************
* Module            : static void LcdSetPortDirection(tUC dir)
* Description       : set data port direction (content of DDR register)
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC dir = {LCD_OUTPORT, LCD_INPORT}
* Special Issues    : none
******************************************************************************/
static void LcdSetPortDirection(tUC dir)
{
   if(dir == LCD_OUTPORT)           /* data port is an output port */
      {
#ifdef LCD_DATAWIDTH_8
 #if LCD_DIR_OUT==1
         LCD_DPORTDIR  =  0xFF;
 #else
         LCD_DPORTDIR  =  0x00;
 #endif        
#endif 

#ifdef LCD_DATAWIDTH_4
 #ifdef LCD_DPORTH
  #if LCD_DIR_OUT==1
         LCD_DPORTDIR  |=  0xF0;
  #else
         LCD_DPORTDIR  &=  0x0F;
  #endif
 #endif 

 #ifdef LCD_DPORTL
  #if LCD_DIR_OUT==1
         LCD_DPORTDIR  |=  0x0F;
  #else
         LCD_DPORTDIR  &=  0xF0;
  #endif 
 #endif 
#endif 
      }
   else                             /* data port is an input port */
      {
#ifdef LCD_DATAWIDTH_8
 #if LCD_DIR_IN==0
         LCD_DPORTDIR  =  0x00;
 #else
         LCD_DPORTDIR  =  0xFF;
 #endif        
#endif 

#ifdef LCD_DATAWIDTH_4
 #ifdef LCD_DPORTH
  #if LCD_DIR_IN==0
         LCD_DPORTDIR  &=  0x0F;
  #else
         LCD_DPORTDIR  |=  0xF0;
  #endif       
 #endif 

 #ifdef LCD_DPORTL
  #if LCD_DIR_IN==0
         LCD_DPORTDIR  &=  0xF0;
  #else
         LCD_DPORTDIR  |=  0x0F;
  #endif       
 #endif 
#endif 
      }
}
/******************************************************************************
* Module            : static void LcdCommand(tUC Command)
* Description       : Write Command to display
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC  Command
* Special Issues    : none
******************************************************************************/
static void LcdCommand(tUC Command)
{
 LcdSetPortDirection(LCD_OUTPORT);                       /* Lcd set port direction  */
 LcdPutNumberOnPort(Command, LCD_CTRL, LCD_WRITE);
 while(LcdReadBusyFlag());
}
/******************************************************************************
* Module            : tUC LcdGetChar(void)
* Description       : Read character from display from actual DDRAM address
* Global Data       : none
* Static Global Data: none
* Returns           : tUC read character
* Arguments         : none
* Special Issues    : If definition LCD_NO_READ_FUNCTION exists the function is
*                     not accesible.
******************************************************************************/
#ifndef  LCD_NO_READ_FUNCTION
tUC LcdGetChar(void)
{
 tSC c;
 c=LcdReadDataPort(LCD_DATA);
 while(LcdReadBusyFlag());               
 return(c);
}
#endif
/******************************************************************************
* Module            : tUC LcdGetCharLC(tUC line, tUC col)
* Description       : Read character from position line,col.
*                     Current cursor (DDRAM address) remains unchanged
* Global Data       : none
* Static Global Data: none
* Returns           : tUC read character
* Arguments         : tUC line = <0,LCD_LINES), tUC column = <0,LCD_COLUMNS)
* Special Issues    : If definition LCD_NO_READ_FUNCTION exists the function is
*                     not accesible.
******************************************************************************/
#ifndef  LCD_NO_READ_FUNCTION
tUC LcdGetCharLC(tUC line, tUC col)
{
 tUC address;
 tUC c;

 address = LcdGetAddressDDRAM();	  /* get current DDRAM address  */
 LcdSetPos(line,col);               /* set new position           */
 c=LcdGetChar();                    /* get char from new position */
 LcdSetAddressDDRAM(address);       /* set original DDRAM address */
 return(c);
}
#endif
/******************************************************************************
* Module            : void LcdSetLine(tUC line)
* Description       : set DDRAM address at the first char of line x
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC line = <0,LCD_LINES)
* Special Issues    : none
******************************************************************************/
void LcdSetLine(tUC line)
{
 if(line>(LCD_LINES-1)) return;

 switch(line)
    {
        case 0 : Lcd.cursor.address =  LCD_LINE0ADDR; break;
        case 1 : Lcd.cursor.address =  LCD_LINE1ADDR; break;
        case 2 : Lcd.cursor.address =  LCD_LINE2ADDR; break;
        case 3 : Lcd.cursor.address =  LCD_LINE3ADDR; break;
	}
 LcdSetAddressDDRAM(Lcd.cursor.address); 
}
/******************************************************************************
* Module            : void LcdSetPos(tUC line, tUC col)
* Description       : set DDRAM address at position Line,Column
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC line = <0,LCD_LINES), tUC column = <0,LCD_COLUMNS)
* Special Issues    : none
******************************************************************************/
void LcdSetPos(tUC line, tUC col)
{
 if(col >(LCD_COLUMNS-1)) return;
 if(line>(LCD_LINES  -1)) return;

 switch(line)
    {
        case 0 : Lcd.cursor.address = (LCD_LINE0ADDR) + col; break;
        case 1 : Lcd.cursor.address = (LCD_LINE1ADDR) + col; break;
        case 2 : Lcd.cursor.address = (LCD_LINE2ADDR) + col; break;
        case 3 : Lcd.cursor.address = (LCD_LINE3ADDR) + col; break;
    }
 LcdSetAddressDDRAM(Lcd.cursor.address); 
}
/******************************************************************************
* Module            : void LcdClearLine(tUC line)
* Description       : clear line on display
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC line = <0,LCD_LINES)
* Special Issues    : none
******************************************************************************/
void LcdClearLine(tUC line)
{	
 tUC i;
 i=LCD_COLUMNS;
 while(i--)
  {
    LcdWriteCharLC(line,i,' '); 
  }
 LcdSetLine(line);
}
/******************************************************************************
* Module            : void LcdWriteChar(tUC chr)
* Description       : Write character to display on current position,
*                     cursor moves by autoincrement setup
*                     It doesn't check end of line.
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC character
* Special Issues    : none
******************************************************************************/
void LcdWriteChar(tUC chr)
{
 LcdPutNumberOnPort(chr, LCD_DATA, LCD_WRITE);
 while(LcdReadBusyFlag());
 LcdGetLineCol();
}
/******************************************************************************
* Module            : void LcdWriteCharLC(tUC line,tUC col,tUC chr)
* Description       : Write character to display on position Line,Column.
*                     Cursor moves by autoincrement setup but if it is on the
*                     last column then cursor stays on this position.
* Global Data       : none
* Static Global Data: none
* Returns           : none
* Arguments         : tUC line = <0,LCD_LINES),
*                     tUC column = <0,LCD_COLUMNS),
*                     tUC character
* Special Issues    : none
******************************************************************************/
void LcdWriteCharLC(tUC line,tUC col,tUC chr)
{
// address = LcdGetAddressDDRAM();
 LcdSetPos(line,col);
 LcdWriteChar(chr);
 if(col == (LCD_COLUMNS-1))   LcdSetPos(line,col);
// LcdSetAddressDDRAM(address);
 LcdGetLineCol();                   /* read current position into structure  */
}
/******************************************************************************
* Module            : void LcdGetLineL(tUC line, tSC *str)
* Description       : Read line x and put it into string. Current cursor
*                     position remains unchanged.
* Global Data       : none
* Static Global Data: none
* Returns           : none

⌨️ 快捷键说明

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