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

📄 bsp_lcd.c

📁 IAR 平台ATMEL 的例程, 和说明
💻 C
📖 第 1 页 / 共 2 页
字号:
Functions called  : 创BSP_LCDBusy创, 创CSP_PIO_SET_OER创, 创CSP_PIO_SET_SODR创,
                    创CSP_PIO_SET_CODR创, 
Returns           : None
******************************************************************************/
void  BSP_LCDWrite(U8_T data, U8_T section)
{
  /* Wait Lcd Not Busy */
     BSP_LCDBusy();
  
  /* Set LCD Bus as output */
     CSP_PIO_SET_OER(UPIO, LCD_BUS);
  
  /* Check Section to be Written */
     if(section == LCD_DATA)
       CSP_PIO_SET_SODR(UPIO, LCD_RS);
     else
     CSP_PIO_SET_CODR(UPIO, LCD_RS);
  
  /* Set LCD_RW Low Level 0 (Write) */
     CSP_PIO_SET_CODR(UPIO, LCD_RW);

  /* Set Lcd Enable */
     CSP_PIO_SET_SODR(UPIO, LCD_E); 
  
  /* Write Data */
     CSP_PIO_SET_SODR(UPIO, data); 
  
  /* Clear LCD_E */
     CSP_PIO_SET_CODR(UPIO, LCD_E);
  
  /* Set LCD_RW Hight Level 1 (Read) */
     CSP_PIO_SET_SODR(UPIO, LCD_RW);
  
  /* Clear the data */
     CSP_PIO_SET_CODR(UPIO, (LCD_BUS));
} 


/******************************************************************************
Function          : BSP_LCDDisplayMessage
Description       : Displays a message on the LCD at the given position.
Input             : 
- row : row number for start of message
- column : column number for start of message
- message : pointer to character string to be displayed
Functions called  : 创BSP_LCDWrite创
Returns           : None
******************************************************************************/
void BSP_LCDDisplayMessage(U8_T row, U8_T column, char *message)
{
  U8_T lcd_parameter;

  /* Calculate LCD start address for string. */
  /* Start of first row is address 0x00, start of second row is 0x40 */
     if(row == 0)
       lcd_parameter = 0x80 + column;
     else
       lcd_parameter = 0xC0 + column;
  
  /* Set DDRAM address in LCD */
     BSP_LCDWrite(lcd_parameter, LCD_CONTROL); 

  /* Write string to LCD */
     while( *message != '\0' )
     {    
     /* Display the current character */
        BSP_LCDWrite((U8_T)*message, LCD_DATA);

     /* Get Next Char */
        message++;
     }
}

/******************************************************************************
Function          : BSP_LCDDisplayChar
Description       : Displays a 8 bit character on the LCD at the given position.
Input             : 
- row : row number for start of message
- column : column number for start of message
- message : Character Code in DDRAM (DDRAM data)
Functions called  : 创BSP_LCDWrite创
Returns           : None
******************************************************************************/
void BSP_LCDDisplayChar(U8_T row, U8_T column, U8_T message)
{
  U8_T lcd_parameter;

   /* Calculate LCD start address for string. */
   /* Start of first row is address 0x00, start of second row is 0x40 */
   lcd_parameter = (U8_T) (row * LCD_ROW_OFFSET) ;
   lcd_parameter += column;
  
   /* Set Display Address */
   lcd_parameter |= LCD_DDRAM_ADDRESS ;
  
   /* Set DDRAM address in LCD */
   BSP_LCDWrite(lcd_parameter, LCD_CONTROL); 

   /* Display the current character */
   BSP_LCDWrite(message, LCD_DATA);

}



/******************************************************************************
Function          : BSP_LCDCustomCharDefinition
Description       : Init CGRAM data with User Patterns
Input             : None
Functions called  : 创BSP_LCDWrite创
Returns           : None
******************************************************************************/
void BSP_LCDCustomCharDefinition(void)
{
   U8_T lcd_parameter;
   U8_T i_u8;
  
   /* Set Display Address */
   lcd_parameter = CG_RAM_ADDRESS ;

   /* Set CGRAM address in LCD */
   BSP_LCDWrite(lcd_parameter, LCD_CONTROL); 

   /* Write string to CGRAM */
   for (i_u8=0; i_u8 < (NUMB_OF_CHAR_CGRAM*8); i_u8++)
   {    
      /* Display the current character */
      BSP_LCDWrite(CGRAM[i_u8], LCD_DATA);
   }
}


/******************************************************************************
Function          : BSP_LCDConvertIntASCII
Description       : Convert Integer into a string in decimal format
Input             : 
- *string : pointer on the string receiving the ASCII conversion
- data_u32 : integer to be converted
Functions called  : None
Returns           : None
******************************************************************************/
void BSP_LCDConvertIntASCII(char *string, U32_T data_u32)
{
   /* Local variable */
   char buff[16] ;
   char offset = 0;
   char length = 0;

   /* Loop to convert integer into a sring coded in ASCII */
   do 
   {
      /* Convert the last digit of integer freq to ASCII value */
      buff[length++] = (char)((data_u32 %10) + '0');
   } while ((data_u32/=10) > 0);

   
   /* Loop to replace the string in order */   
   do 
   {
      length-- ;
      /* The first character of string receive the last character of buffer */
      string[offset++] =buff[length] ;
   } while(length>0);

   string[offset] = '\0';   
}

/******************************************************************************
Function          : BSP_LCDConvertHexASCII
Description       : Convert integer into a string in hexadecimal format
Input             : 
- *string : pointer on the string receiving the ASCII conversion
- data_u32 : integer to be converted
Functions called  : None
Returns           : None
******************************************************************************/
void BSP_LCDConvertHexASCII(char *string, U32_T data_u32)
{
   /* Local variable */
   char buff[16] ;
   char offset = 0;
   char length = 0;
   U32_T val   = 0 ;

   /* Loop to convert integer into a sring coded in ASCII */
   do 
   {
      val = (data_u32 %16) ; 
      /* Convert the last digit of integer freq to ASCII value */
      if (val>9)
      {
         buff[length++] =(char)('A' + (val-10)) ;
      }
      else 
      { 
         buff[length++] =(char)( val + '0');
      }
   } while ((data_u32/=16) > 0);

   
   /* Loop to replace the string in order */   
   do 
   {
      length-- ;
      /* The first character of string receive the last character of buffer */
      string[offset++] = buff[length] ;
   } while(length>0);

   string[offset] = '\0';   
}


/*******************************************************************************
Function    : BSP_LCDSetContrast
Description : Enable the PWM channel1 to control the LCD contrast thanks to
              a pump charge which generates a negative voltage
Input       : 
- Frequency_u32 = PWM channel 1 frequency (Hz)
- DutyCycle_u16 = dutycycle (0 to 256).             
Returns     : None
Fct called  : 创BSP_PWM4CSetOuput创
*******************************************************************************/
void BSP_LCDSetContrast( U32_T Frequency_u32, U16_T DutyCycle_u16)
{
   BSP_PWM4CSetOuput(PWM0, 1, Frequency_u32*256, DutyCycle_u16);
}

⌨️ 快捷键说明

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