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

📄 lcd.c

📁 CAN总线传输及液晶显示文章
💻 C
字号:
//****************************************************************************
// @Module        LCD
// @Filename      LCD.C
// @Project       Hands On Training
//----------------------------------------------------------------------------
// @Controller    Siemens C167CR
//
// @Compiler      Tasking C166 V5.0
//                Keil C166 V3.00
//
// @Author        Michael Knese
//
// @Description   This file contains all functions that use the LCD Display
//                
//
//----------------------------------------------------------------------------
// @Date          11/16/98 12:44:55 PM
//
//****************************************************************************

//****************************************************************************
// @Project Includes
//****************************************************************************

#include "MAIN.H"
#include <ctype.h>
#include <string.h>

// USER CODE BEGIN (LCD_General,1)

// USER CODE END


//***************************************************************************
// @Global Variables
//***************************************************************************

// USER CODE BEGIN (LCD_General,2)

// USER CODE END


//***************************************************************************
// @Define user-defined character dot patterns
//***************************************************************************


//****************************************************************************
// @Function      void LCD_vInit(void)
//
//----------------------------------------------------------------------------
// @Description   This function initializes the LCD component. It effects all
//                necessary configurations of the LCD-Register, depending on 
//                the selected operating mode. 
//----------------------------------------------------------------------------
// @Returnvalue   none
//
//----------------------------------------------------------------------------
// @Parameters    none
//
//----------------------------------------------------------------------------
// @Date          11/16/98 12:44:55 PM
//
//****************************************************************************

void LCD_vInit(void)
{
  unsigned long i;

  for(i=0x01D0;i>0;i--);   	/* wait more than 15ms  (10h => 580us)			*/
  Befehle = 0x30;		/* init							*/


  for(i=0x0089;i>0;i--);	/* wait more than 4.1ms	  (4.2ms)	     		*/
  Befehle = 0x30;		/* init							*/


  for(i=0x0003;i>0;i--);	/* wait more than 0.1ms	  (140us)		 	*/
  Befehle = 0x30;		/* init							*/

  while (LCD_bBusyFlag()==1);      	/* wait till LCD ready  */
         	

  Befehle = 0x38;		/* 8 bit bus, 2 lines, 5x7 dots				*/
  
  while (LCD_bBusyFlag()==1);      	/* wait till LCD ready  */
             

  Befehle = 0x08;		/* display off						*/

  while (LCD_bBusyFlag()==1);   
       

  Befehle = 0x01;		/* display clear					*/

  while (LCD_bBusyFlag()==1);         
               
  Befehle = 0x06;		/* entry mode set,  cursor move direction: increase	*/


  while (LCD_bBusyFlag()==1);       

  Befehle = 0x0C;         	/* display on						*/


   // USER CODE BEGIN (LCD_Init,1)

  // USER CODE END

}



/********************************************************************************/
/* 	wait till Busy Flag = 0		     					*/
/********************************************************************************/
bit LCD_bBusyFlag (void)

{ 

   if ((READ_BusyF_and_Adress & 0x80) == 0x80)      	/* test busy flag               */
       return (1);                                      /* LCD is busy                  */
   else                                    		
       return (0);                                      /* LCD is ready                 */

}


/********************************************************************************/
/*	Clears display and returns cursor to home position (DD RAM address = 0)	*/
/********************************************************************************/
void LCD_vClear (void)

{

   while (LCD_bBusyFlag()==1);
   Befehle = 0x01;		/* display clear 		*/


}

 

/********************************************************************************/
/*	Set CURSOR-POSITION						        */
/*      Author :   Michael Knese						*/
/*										*/
/*	parameter: X: X-Position (00..27h)                                      */ 
/*                 Y: Y-Position (0 = 1.line ;   1 = 2.line)                    */
/*                 ==> DD RAM address (00..27h => 1.line;    40..67h => 2.line   */
/********************************************************************************/

void LCD_vGotoXY (unsigned char X, unsigned char Y)

{
     while (LCD_bBusyFlag()==1);  
     Befehle = 0x80 | ( Y ? (X+0x40) : X );
}



/*
** LCD_Cursor: Position the LCD cursor at "row", "column".
*/
void LCD_vCursorPos (char row, char column)
{
	while (LCD_bBusyFlag()==1);
	switch (row) {
		case 1: Befehle = (0x80 + column - 1); break;
		case 2: Befehle = (0xc0 + column - 1); break;
		//case 3: Befehle = (0x94 + column - 1); break;
		//case 4: Befehle = (0xd4 + column - 1); break;
		default: break;
	}
}


//////////////////////////////////////////////////////////////////////////////////
//	Write a unsined byte on the display             		        //
//      Author :   Michael Knese						//
//										//
//	parameter: X: X-Position (00..27h)                                      // 
//                 Y: Y-Position (0 = 1.line ;   1 = 2.line)                    //
//                 ==> DD RAM address (00..27h => 1.line;    40..67h => 2.line   //
//                 Data: 							//
//////////////////////////////////////////////////////////////////////////////////

void LCD_vWrite_ubyteXY(ubyte x, ubyte y, ubyte Data)
{

    LCD_vGotoXY(x,y);	                                //go to position (x,y)

    while (LCD_bBusyFlag()==1);                        	// wait till LCD ready          
    WRITE_Data = (Data/100) + '0' ;    Data %= 100;
    while (LCD_bBusyFlag()==1);                        	// wait till LCD ready          
    WRITE_Data = (Data/ 10) + '0' ;    Data %=  10;
    while (LCD_bBusyFlag()==1);                        	// wait till LCD ready          
    WRITE_Data = (Data    ) + '0' ; 

}




/*
** LCD_DisplayString: Display a string at the specified row and column.
*/
void LCD_vDisplayStringPos (char row, char column, char *string)
{
	LCD_vCursorPos (row, column);
	while (*string)
		LCD_DisplayCharacter (*string++);
}



//
//write data to the LCD display 
//

void LCD_vWriteData(ubyte Data)
{
	while (LCD_bBusyFlag()==1);
	WRITE_Data = Data;
}





//////////////////////////////////////////////////////////////////////////////////
//	Write a text on the display             		                //
//	text:        SIEMENS  HOT                 				//
//                   Data:
//	parameter: 								//
//////////////////////////////////////////////////////////////////////////////////

void LCD_text (void)
{                                  
        LCD_vClear();

        LCD_vDisplayStringPos(1,1,"SIEMENS  HOT");
	LCD_vDisplayStringPos(2,1,"Data:");
 }


// USER CODE BEGIN (LCD_General,3)

// USER CODE END

⌨️ 快捷键说明

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