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

📄 glasslcd.c

📁 LCD液晶显示驱动,芯片为ST7565,
💻 C
📖 第 1 页 / 共 2 页
字号:
  if (*c==0x20)
  {
    car =0x00;
  }
  
#ifdef USE_LCD_REF_PD_878   
  if (point==1)
  {
    car|=0x0004;
  }
#endif

#ifdef USE_LCD_REF_CT4_098   
  if (point==1)
  {
    car|=0x8000;
  }
#endif
  
  for (i=0;i<3;i++)
  {
    tmp = car&mask[i];
    digit[i] = tmp>>shift[i];
  }
  
  digit[3] = (car&mask[3]); 
}

/*******************************************************************************
* Function Name  : LCD_WriteChar
* Description    : This function writes a char in the LCD frame buffer
* Input          : - car: the caracter to dispaly.
*                  - point: a point to add in front of char
*                     0: no point to add in front of char.
*                     1: add a point in front of char.  
*                  - position: position in the LCD of the caracter to write. 
*                    it can be: [0:3] (in case of CT4-098 LCD glass)
*                               [0:7] (in case of PD_878 LCD glass)
* Output         : None.
* Return         : None.
*******************************************************************************/
void LCD_WriteChar(char* car,u8 point,u8 position)
  {
   u8 i;
   const u16 mask[4]={0x000F,0x00F0,0x0F00,0xF000};
   u16 Digits_Lower_Quarter[4];
   
#ifdef USE_LCD_REF_PD_878    
   u16 Digits_Higher_Quarter[4];
#endif    
   Convert(car,point);
  
   switch(position)
   {
     /* Position 0 on LCD (Digit1)*/
     case 0: for (i=0;i<4;i++)
             {
               Digits_Lower_Quarter[i] = digit[i];
#ifdef USE_LCD_REF_PD_878                 
               Digits_Higher_Quarter[i]=0;
#endif                
              }
              break;
             
     /* Position 1 on LCD (Digit2)*/
     case 1: for (i=0;i<4;i++)
             {
               Digits_Lower_Quarter[i] =(digit[i]<<4);
#ifdef USE_LCD_REF_PD_878                 
               Digits_Higher_Quarter[i]=0;
#endif               
             }
             break;
             
     /* Position 2 on LCD (Digit3)*/
     case 2: for (i=0;i<4;i++)
             {
               Digits_Lower_Quarter[i]=(digit[i]<<8);
#ifdef USE_LCD_REF_PD_878                 
               Digits_Higher_Quarter[i]=0;
#endif                
             }
             break;
 
     /* Position 3 on LCD (Digit4)*/
     case 3: for (i=0;i<4;i++)
             {
               Digits_Lower_Quarter[i]=(digit[i]<<12);
#ifdef USE_LCD_REF_PD_878               
               Digits_Higher_Quarter[i]=0;
#endif               
             }
             break;

#ifdef USE_LCD_REF_PD_878   /* Higher quarter digits in LCD (position from 4 to 7) */
             
     /* Position 4 on LCD (Digit5)*/
     case 4: for (i=0;i<4;i++)
             {
               Digits_Higher_Quarter[i]= digit[i];
               Digits_Lower_Quarter[i]=0;
             }
             break;
             
     /* Position 5 on LCD (Digit6)*/
     case 5: for (i=0;i<4;i++)
             {
               Digits_Higher_Quarter[i]=(digit[i]<<4);
               Digits_Lower_Quarter[i]=0;
             }
             break;
             
     /* Position 6 on LCD (Digit7)*/
     case 6: for (i=0;i<4;i++) 
             {
               Digits_Higher_Quarter[i]=(digit[i]<<8);
               Digits_Lower_Quarter[i]=0;
             }
             break;
             
     /* Position 7 on LCD (Digit8)*/
     case 7: for (i=0;i<4;i++)
             {
               Digits_Higher_Quarter[i]=(digit[i]<<12);
               Digits_Lower_Quarter[i]=0;
             }
             break;
#endif             
             
     default:break;
    }

   if (position < 4) /* Segments of lower quarter digits in LCD (position from 4 to 7) */
   {
     for (i=0;i<4;i++)
     {
       SegmentsValues_Lower_Quarter_Digits[i] = \
      (SegmentsValues_Lower_Quarter_Digits[i]&~mask[position])| Digits_Lower_Quarter[i];
                                                   
     }
   }
#ifdef USE_LCD_REF_PD_878    
   else  /* Segments of higher quarter digits in LCD (position from 4 to 7) */
   { 
     for (i=0;i<4;i++)
     {
       SegmentsValues_Higher_Quarter_Digits[i] = \
      (SegmentsValues_Higher_Quarter_Digits[i]&~mask[position-4])| Digits_Higher_Quarter[i];
                                                  
     }
   }
#endif
   
  }


/*******************************************************************************
* Function Name  : LCD_WriteString
* Description    : This function writes a string in the LCD
* Input          : - str: string to dispaly in the LCD.
* Output         : None.
* Return         : None.
*******************************************************************************/
void LCD_WriteString(char* str)
{
  u8 i;
  
  for (i=0;i<NumberOfUsedDigits;i++)
  {
    LCD_WriteChar(str+i,0,i);
  }
} 

/*******************************************************************************
* Function Name  : LCD_GPIO_Init
* Description    : Initialize GPIOs to set segments lines and common line
*                  values to 0.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void LCD_GPIO_Init(void)
{
  /* Compute and load the GPIOs masks of the Common lines */
  LCD_GPIO_Coms_Masks_Init();
    
  /* All common lines = 0 */
  CommonLines_Port->ODR &= ~ALL_COMMON_LINES;
    
  /* All segment lines = 0 ( all SegmentsLines_LQD_Port pins = 0 ) */
  GPIO_Write(SegmentsLines_LQD_Port, (u16)~ALL_SEGMENT_LINES);
    
#ifdef USE_LCD_REF_PD_878 
  GPIO_Write(SegmentsLines_HQD_Port, (u16)~ALL_SEGMENT_LINES);
#endif          
   
  /* Configure all common lines on CommonLines port pins as Out_PP */    
  CommonLines_Port->PinsConfig &= (0xFFFF0000 << ((CommonLines_Pin_Offset) * 4)) \
                                  + OffsetValue(CommonLines_Pin_Offset);
  CommonLines_Port->PinsConfig |= ALL_COMMON_LINES_PP;
    
  /* Configure all segment lines of Lower Quarter digits as Out_PP */ 
  SegmentsLines_LQD_Port->CRL = ALL_SEGMENT_LINES_PP;
  SegmentsLines_LQD_Port->CRH = ALL_SEGMENT_LINES_PP;
       
#ifdef USE_LCD_REF_PD_878 
  /* Configure all segment lines of Higher Quarter digits as Out_PP */ 
  SegmentsLines_HQD_Port->CRL = ALL_SEGMENT_LINES_PP;
  SegmentsLines_HQD_Port->CRH = ALL_SEGMENT_LINES_PP;
#endif 
}

/*******************************************************************************
* Function Name  : LCD_SettingContrast
* Description    : Set the LCD contrast.
* Input          : - LCD_ContrastVAlue: the contrast value.
* Output         : None.
* Return         : None.
*******************************************************************************/
void LCD_SettingContrast(u16 LCD_ContrastValue)
{
  TIM_OCInitTypeDef TIM_OCInitStructure;
  
  /* Set LCD contrast */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
  TIM_OCInitStructure.TIM_Pulse = LCD_ContrastValue;  
  TIM_OCInitStructure.TIM_OutputState = ENABLE;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OC2Init(TIMER_LCD, &TIM_OCInitStructure);
}

/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

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