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

📄 display.c

📁 基于MMA7260QR2的跌落检查程序
💻 C
📖 第 1 页 / 共 3 页
字号:
    
 /* determine the lines that were written and need to be cleared */   
  linesToClear = mDisplayParams.writtenLines;  
  if(mIsLcdInitialized == TRUE)
  {
 /* determine if there are lines that need to be erased and after need to be written */
    deleteWriteLines = linesToClear & mDisplayParams.linesToWrite;
    if(deleteWriteLines)
    { /* if there are */
     /* mark that lines as deleted and jump over them */
      linesToClear &= ~(deleteWriteLines);  
    }
  }
   line = 0;
   /* find the first written line */
   
  do
  {
    while((!((linesToClear>>line)&0x01))&&(line<mMaxLineNumber_c))
    {
      line++;
    }
   
    if(line!= mMaxLineNumber_c)
    {
     /* in case at least a line is written */
      if(TRUE == LCD_ClearLine(line))
      {
       /* mark line as cleared */
        mDisplayParams.writtenLines &= ~(1 << line);
        linesToClear &= ~(1 << line);
       /* check if there are other lines written */
      }
    }
  }while(line!= mMaxLineNumber_c);
}

/******************************************************************************
* This function writes a string to the display. In case an error occured 
* during add to queue operation, the write string operation will not execute.
*
* Interface assumptions:
*
*
* Return value:
* None
*
*
******************************************************************************/

void LCD_WriteString_NormalFont(uint8_t line, uint8_t *pstr){
 
 uint8_t len; 
 mDisplayParams.currentXCoord = mLineParams[line].xCoord;;  
 mDisplayParams.currentYCoord = mLineParams[line].yCoord;   
 len = GetStrlen(pstr);
 
 for(uint8_t i=0; ((i< len) && (i < gMAX_LCD_CHARS_c)); i++)
 {
   LCD_WriteCharacter(*pstr,mDisplayParams.currentXCoord, mDisplayParams.currentYCoord);   
   mDisplayParams.currentXCoord += 6;
  pstr++;
 }
}

/******************************************************************************
* This function write a string and a value in decimal or hexdecimal
* to the display
*
* Interface assumptions:
* The pstr must be zero-terminated.
*
* Return value:
* None
*
*
******************************************************************************/
void LCD_WriteStringValue
  (
  uint8_t *pstr,     /* IN: Pointer to text string */
  uint16_t value,    /* IN: Value */
  uint8_t line, 	   /* IN: Line in display */
  LCD_t numberFormat /* IN: Value to show in HEX or DEC */
  )
{

  int16_t divDec=10000, divHex=16;
  uint8_t loop=5, i=0,counter=0, aH[6], aHex[6];
  uint8_t aDec[6], aString[17];
  
  /* clear the error indicator */
  mErrorIndicator = gLCD_NoError_c;

 if(numberFormat == gLCD_DecFormat_c) {
    if(value < 100) {
      loop = 2;
      divDec = 10;
    }
    else if(value >= 100 && value <1000) {
      loop = 3;
      divDec = 100;
    }
    else if(value >= 1000 && value <9999) {
      loop = 4;
      divDec = 1000;
    }

    for(i=0; i<loop; i++) {
      if((value/divDec)!= 0) {
        aDec[counter++] = (value/divDec) + 0x30;
        value = value % divDec;
      }
      else {
        aDec[counter++] = 0x30;
      }
      divDec = divDec/10;
    }
    aDec[counter]='\0';
    counter=0;
    while (*pstr != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=*pstr;
      pstr++;
    }
    i=0;
    while (aDec[i] != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=aDec[i++];
    }
    aString[counter]='\0';
    LCD_WriteString_NormalFont( line, aString );
  }
  else if(numberFormat == gLCD_HexFormat_c) {
    do{
      aH[i]=gaHexValue[value % divHex];
      value=value / divHex;
      i++;
    }
    while(value > 15);
    aH[i]=gaHexValue[value];
    counter=0;
    while(i > 0){
      aHex[counter++]=aH[i--];
    }

    aHex[counter++]=aH[0];
    aHex[counter]='\0';

    counter=0;
    while (*pstr != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=*pstr;
      pstr++;
    }
    i=0;
    while (aHex[i] != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=aHex[i++];
    }
    aString[counter]='\0';
    LCD_WriteString_NormalFont( line, aString );
  }
  else {
    LCD_WriteString_NormalFont( line, "Format unknow" );
  }
}

void LCD_WriteStringDecValue
  (
  uint8_t *pstr,     /* IN: Pointer to text string */
  uint16_t value,    /* IN: Value */
  uint8_t line, 	   /* IN: Line in display */
  LCD_t numberFormat /* IN: Value to show in HEX or DEC */
  )
{

  int16_t divDec=10000, divHex=16;
  uint8_t loop=5, i=0,counter=0, aH[6], aHex[6];
  uint8_t aDec[6], aString[17] = {0};
  uint8_t u8TempVal;
  uint8_t u8Count;
 
  
  /* clear the error indicator */
  mErrorIndicator = gLCD_NoError_c;

 if(numberFormat == gLCD_DecFormat_c) {
    u8TempVal = (value >> 8);
    
    for( u8Count= 0;  u8Count < 2;  u8Count++)
    {
      if(u8TempVal < 100) 
      {
        loop = 2;
        divDec = 10;
      }
      else if(u8TempVal >= 100 && u8TempVal < 255) {
        loop = 3;
        divDec = 100;
      }
      for(i=0; i<loop; i++) {
        if((u8TempVal/divDec)!= 0) 
        {
          aDec[counter++] = (u8TempVal/divDec) + 0x30;
          u8TempVal = u8TempVal % divDec;
        }
        else {
          aDec[counter++] = 0x30;
        }
        divDec = divDec/10;
      }
      if(u8Count < 1)
      {  
        aDec[counter++] = '.';
      }
      u8TempVal = value;
    } 
      
    aDec[counter]='\0';
    counter=0;
    
    while (*pstr != '\0' && counter <gMAX_LCD_CHARS_c ) 
    {
      aString[counter++]=*pstr;
      pstr++;
    }
    i=0;

    while (aDec[i] != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=aDec[i++];
    }
    LCD_WriteString_NormalFont( line, aString );
  }
 
  else if(numberFormat == gLCD_HexFormat_c) {
    do{
      aH[i]=gaHexValue[value % divHex];
      value=value / divHex;
      i++;
    }
    while(value > 15);
    aH[i]=gaHexValue[value];
    counter=0;
    while(i > 0){
      aHex[counter++]=aH[i--];
    }

    aHex[counter++]=aH[0];
    aHex[counter]='\0';

    counter=0;
    while (*pstr != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=*pstr;
      pstr++;
    }
    i=0;
    while (aHex[i] != '\0' && counter <gMAX_LCD_CHARS_c ) {
      aString[counter++]=aHex[i++];
    }
    aString[counter]='\0';
    LCD_WriteString_NormalFont( line, aString );
  }
  else {
    LCD_WriteString_NormalFont( line,"Format unknow"); 
  }
}



/******************************************************************************
* This functions allows to write raw bytes to the LCD, the maximum number of bytes
*	capable per line is 8, this functions transfors every hex simbol in a byte to a char.
*
* Interface assumptions:
*	IN: The pointer to the label to print with the bytes.
*	IN: The bytes to print.
*	IN: The line in the LCD where the bytes with the label.
*	IN: The number of bytes to print in the LCD.
*
* Return value:
* None
*
*
******************************************************************************/
void LCD_WriteBytes
(
	uint8_t   *pstr,   /* IN: The pointer to the label to print with the bytes. */
	uint8_t   *value,  /* IN: The bytes to print in hex. */
	uint8_t   line,    /* IN: The line in the LCD where the bytes with the label. */
	uint8_t   length   /* IN: The number of bytes to print in the LCD. */
)
{

	uint8_t i=0,counter=0, cIndex,auxIndex;
	uint8_t aString[17];

	uint8_t  hexIndex;
	uint8_t aHex[gMAX_LCD_CHARS_c]={'S','i','z','e',' ','N','o','t',' ','V','a','l','i','d','*','*'};

  /* clear the error indicator */
  mErrorIndicator = gLCD_NoError_c;
  
	counter=0;
	while (*pstr != '\0' && counter <gMAX_LCD_CHARS_c )
	{
		aString[counter++]=*pstr;
		pstr++;
	}
	if ((((length*2)+counter) <= gMAX_LCD_CHARS_c) && ((length*2) > 0))
	{
		for (cIndex =0,auxIndex = 0; cIndex < length; cIndex++,auxIndex+=2)
		{
			hexIndex = value[cIndex]&0xf0;
			hexIndex = hexIndex>>4;
			aHex[auxIndex] = gaHexValue[hexIndex];
			hexIndex = value[cIndex] & 0x0f;
			aHex[auxIndex + 1] = gaHexValue[hexIndex];
		}
		aHex[(length * 2)]='\0';
	}
	else
		counter = 0;

	i=0;
	while (aHex[i] != '\0' && counter <gMAX_LCD_CHARS_c )
		aString[counter++]=aHex[i++];

	aString[counter]='\0';
	LCD_WriteString( line, aString );
}

/******************************************************************************
* This function sends a command to the display controller
*
* Interface assumptions:
*
*
* Return value:
* None
*
*
******************************************************************************/
void LCD_WriteCommand(uint8_t command)
{
  /* clear the error indicator */
  mErrorIndicator = gLCD_NoError_c;
  
  Gpio_SetPinData(LCD_A0, LCD_A0_COMMAND);
  SetOutput();
  Gpio_SetPinData(LCD_CS, LCD_CS_ACTIVE);
  Gpio_SetPinData(LCD_WR, LCD_WR_ACTIVE);
  SendData(command);
  DelayUs(1);
  Gpio_SetPinData(LCD_WR, LCD_WR_INACTIVE);
  Gpio_SetPinData(LCD_CS, LCD_CS_INACTIVE);
  SetHiZ();
  DelayUs(1);
}

/******************************************************************************
* This function sends a data to the display controller
*
* Interface assumptions:
*
*
* Return value:
* None
*
*
******************************************************************************/
void LCD_WriteData(uint8_t data)
{
  /* clear the error indicator */
  mErrorIndicator = gLCD_NoError_c;

  Gpio_SetPinData(LCD_A0, LCD_A0_DATA);
  Gpio_SetPinData(LCD_CS, LCD_CS_ACTIVE);
  SetOutput();
  SendData(data);
  Gpio_SetPinData(LCD_WR, LCD_WR_ACTIVE);
  DelayUs(1);
  Gpio_SetPinData(LCD_WR, LCD_WR_INACTIVE);
  Gpio_SetPinData(LCD_CS, LCD_CS_INACTIVE);
  SetHiZ();
  DelayUs(1);  
 
}

/******************************************************************************
* This function sets the font received as parameter as default font
*
* Interface assumptions:
*
*
* Return value:
*      TRUE:  when the font is correctly set
*      FALSE: when an unsupported font is received as parameter
* char
*
*
******************************************************************************/
bool_t LCD_SetFont(lcdFontType_t font)
{
  /* clear the error indicator */
  mErrorIndicator = gLCD_NoError_c;

  if(gLCDNumFonts_c > font)
  {
    mDisplayParams.currentFontType = font;
    return TRUE;
  }
  else
  {
    return FALSE;
  }
}

/******************************************************************************
* This function checks if an error occured during an interface function call.
* User must always call this function to verify if an interface function executed 
* successufully.
*
* Interface assumptions:
*
*
* Return value:  lcdError_t
*      gLCD_NoError_c:   no error
*      gLCD_QueueFull_c: queue is full
*
*
******************************************************************************/
lcdError_t LCD_CheckError(void)
{
  return mErrorIndicator;
}

/************************************************************************************
*************************************************************************************
* Private functions
*************************************************************************************
************************************************************************************/


/******************************************************************************
* This function enables/disables the backlight
*
* Interface assumptions:
*   0 - disable backlight
*   >0 - enables backlight
*
*
* Return value:
* None
*
*
******************************************************************************/
void LCD_SetBacklight(uint8_t brightnessValue)
{
    GpioPinState_t backLightState;
    backLightState = (0 != brightnessValue) ? gGpioPinStateHigh_c : gGpioPinStateLow_c;
    Gpio_SetPinData(LCD_BL_PWM,  backLightState);

⌨️ 快捷键说明

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