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

📄 dispdrv.c

📁 《OSEK/VDX汽车电子嵌入式软件编程技术》中光盘的资料
💻 C
字号:
/************************************************
*
*	$Copyright    2001 Joseph J. Lemieux  ALL RIGHTS RESERVED. $
*
*	$Filename: C:\OSEKBook\src\CH05\src\dispdrv.c $
*
*	Description: Routines to drive the LCD display	
*
************************************************/
#ifndef DISPDRVC
#define DISPDRVC

/************************************************
*
*	Include files
*
************************************************/

#include "typedefs.h"
#include "os.h"
#include "init.h"
#include "dispdrv.h"

/************************************************
*
*	Local macros
*
************************************************/

/************************************************
*
*	Local type definitions
*
************************************************/
/***
*
* Type definition for cursor position
*
***/
typedef struct CURSOR_POSITION_TYPEtag {
   UINT8 row;
   UINT8 column;
   }CURSOR_POSITION_TYPE;

/************************************************
*
*	Local Function Prototypes
*
************************************************/
void wait(UINT32 a);
void PackDisplay(char *string);
void OutputNewDisplay(void);
void OutputNewLine(void);

/************************************************
*
*	Local Variables
*
************************************************/
/* Actual string to be sent to display */
static char displayMessage[MAX_DISPLAY_ROWS][MAX_DISPLAY_LINE_LENGTH]; 

/* Current Cursor Position */
static CURSOR_POSITION_TYPE cursorPosition = {0,0};

/************************************************
*
*	Global Variables - only used until messaging
*    is enabled.
*
************************************************/
/***
* Global variable into which the application places
* the requested display, and the pointer to the buffer
* location which is updated by the display. The buffer
* accepts \n for newline and \f to clear display before
* entering the info. Ends with a NULL character which
* must also be put in by the application.
***/

char displayBuffer[100];

/************************************************
*
*	Local Constants
*
************************************************/
/* Initialization Message */
char const InitMessage[] = "\f  OSEK/VDX Example\n  Cardgame \360 \361 \362 \363   Press * to Shuffle ";

/* Setup for card suit special characters
*  These characters are sent to the display on initialization
*/
char const special[] = {	0x0a,0x1b,0x1f,0x0e,0x0e,0x04,0x04,0x00,
					0x04,0x0e,0x0e,0x1f,0x0e,0x0e,0x04,0x00,
					0x04,0x0e,0x0e,0x1f,0x1f,0x15,0x04,0x00,
					0x04,0x0e,0x04,0x0a,0x1f,0x0a,0x00,0x00,
					0x00,0x10,0x08,0x04,0x02,0x01,0x00,0x00
};

/* Row Translation Matrix */
UINT8 const RowTranslation[MAX_DISPLAY_ROWS] = {ROW_TRANSLATION};
/************************************************
*
*	Functions
*
************************************************/
/************************************************
*
*   Function:     InitDisplay
*
*   Inputs:       type - type of initialization occurring.
*
*   Outputs:      none
*
*   Returns:      none
*
*   Description:  Initializes the display and prepares for 
*                 output. Sends startup message InitMessage.
*
************************************************/
void InitDisplay(InitType type)
{

	UINT8 *displayControl = DISPLAY_CONTROL_LOCATION;
	UINT8 *display = DISPLAY_BUFFER_LOCATION;

	UINT8 i;

/***
*
* Perform display initialization sequence
*
***/
   if(type==INIT_RESET)
   {
      wait(100000);
   }
	*displayControl = 0x38;
	wait(30000);
	*displayControl = 0x38;
	wait(1000);
	*displayControl = 0x38;
	wait(1000);
	*displayControl = 0x38;
	wait(1000);
	*displayControl = 0x10;
	wait(1000);
	*displayControl = 0x01;
	wait(30000);
	*displayControl = 0x06;
	wait(1000);
	*displayControl = 0x0E;
	wait(1000);
	*displayControl = 0x40;
	wait(1000);
/***
*
* Program Card Suit special characters
*
***/
	for(i=0;i<40;i++)
	{
		*display = special[i];
	wait(1000);
	}
	*displayControl = 0x80;
	wait(1000);
	*displayControl = 0x01;
	wait(30000);

/***
*
* Pack display initialization message and output
*
***/
	
   cursorPosition.row = cursorPosition.column = 0;
   PackDisplay((char *)InitMessage);
   OutputNewDisplay();
}

/************************************************
*
*   Function:     wait
*
*   Inputs:       time - number of loops to wait
*
*   Outputs:      none
*
*   Returns:      none
*
*   Description:  Small routine that inserts a small delay
*                 into the display writes.
*
************************************************/
void wait(UINT32 time)
{
	while(time-- != 0);
}

/************************************************
*
*   Function:     PackDisplay
*
*   Inputs:       string - Pointer to string that contains
*                 the data to be output - null terminated.
*
*   Outputs:      none
*
*   Returns:      none
*
*   Description:  Adds the data from the string to the display
*                 at the current cursor position. If the
*                 string has \f, the display is cleared. If \n,
*                 the cursor is moved to the next line. If 0xF0
*                 or greater, then a special character is output.
*
************************************************/
void PackDisplay(char *string)
{
UINT8 i,j;

   while(*string != 0)
   {
      switch(*string)
      {
/***
*
* If line feed, then output new line to screen.
*
***/
         case 0x0a:
            OutputNewLine();
            break;
         case 0x0c:
/***
*
* If form feed, clear screen
*
***/
            for(i=0;i<MAX_DISPLAY_ROWS;i++)
            {
               for(j=0;j<MAX_DISPLAY_LINE_LENGTH;j++)
               {
                  displayMessage[i][j] = ' ';
               }
            }
            cursorPosition.row = cursorPosition.column = 0;
            break;
/***
*
* Place character, then increment cursor. If at end of line, go to new line
*
***/
         default:
            if(*string >= 240)
            {
               displayMessage[cursorPosition.row][cursorPosition.column++] = *string - (char)240;
            }
            else
            {
               displayMessage[cursorPosition.row][cursorPosition.column++] = *string;
            }
            if(cursorPosition.column == MAX_DISPLAY_LINE_LENGTH)
            {
               OutputNewLine();
            }
      }
      ++string;
   }
}

/************************************************
*
*   Function:     OutputNewDisplay
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      none
*
*   Description:  Outputs the value in displayMessage
*                 buffer to the display, switching
*                 the lines as necessary.
*
************************************************/
void OutputNewDisplay(void)
{
   UINT8 *displayControl = DISPLAY_CONTROL_LOCATION;
   UINT8 *display = DISPLAY_BUFFER_LOCATION;
   UINT8 i,outputRow;
   UINT8 translateRow = 0;

/***
*
* First clear the display, then output message.
*
***/
   *displayControl = 0x01;
	wait(30000);
   while(translateRow < MAX_DISPLAY_ROWS)
   {
      outputRow = RowTranslation[translateRow++];
      for(i=0;i<MAX_DISPLAY_LINE_LENGTH;i++)
      {
         *display = displayMessage[outputRow][i];
         wait(1000);
      }
   }
   i=((cursorPosition.row&0x01)*0x40) + 
       ((cursorPosition.row&0x02)/2*MAX_DISPLAY_LINE_LENGTH) +
         cursorPosition.column;
   *displayControl = 0x80+i;
   wait(1000);
}

/************************************************
*
*   Function:     OutputNewLine
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      none
*
*   Description:  Moves the cursor to the new line.
*                 If at the last line, scroll up.
*
************************************************/
void OutputNewLine(void)
{

UINT8 i,j;

   if(++cursorPosition.row == MAX_DISPLAY_ROWS)
   {
       --cursorPosition.row;
       for(i=0;i<MAX_DISPLAY_ROWS-1;i++)
       {
          for(j=0;j<MAX_DISPLAY_LINE_LENGTH;j++)
          {
             displayMessage[i][j] = displayMessage[i+1][j];
          }
       }
       for(j=0;j<MAX_DISPLAY_LINE_LENGTH;j++)
       {
          displayMessage[i][j] = ' ';
       }
   }
   cursorPosition.column = 0;
}

/************************************************
*
*   Function:     OutputDisplay
*
*   Inputs:       none
*
*   Outputs:      none
*
*   Returns:      none
*
*   Description:  Task which performs the display
*                 output.
*
************************************************/
TASK(OutputDisplay)
{
   PackDisplay(displayBuffer);
   OutputNewDisplay();
   TerminateTask();
}
#endif /* DISPDRVC */

⌨️ 快捷键说明

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