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

📄 lcd.c

📁 FreeRTOS - V5.1.1 Last Update: Nov 20 2008 http://sourceforge.net/projects/freertos/
💻 C
📖 第 1 页 / 共 4 页
字号:
/* Public functions for CircleOS ---------------------------------------------*/

/*******************************************************************************
*
*                                LCD_Init
*
*******************************************************************************/
/**
*
*  Initialize LCD. Called at CircleOS startup.
*
*  @attention  This function must <b>NOT</b> be called by the user.
*
**/
/******************************************************************************/
void LCD_Init( void )
   {
   LCD_SetBackLight( UTIL_ReadBackupRegister( BKP_BKLIGHT ) );

   /* Do some gpio configs*/
   GPIO_InitTypeDef GPIO_InitStructure;

   /* Enable GPIO clock for LCD */
   RCC_APB2PeriphClockCmd( GPIO_LCD_CTRL_PERIPH, ENABLE );
   RCC_APB2PeriphClockCmd( GPIO_LCD_D_PERIPH, ENABLE );
   RCC_APB2PeriphClockCmd( GPIO_LCD_CS_PERIPH, ENABLE );

   /* Enable GPIOC clock */
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );

   /* Init BackLight*/
   LCD_BackLightConfig();

   /* Configure control lines signals as output mode */
   LCD_CtrlLinesConfig();

   /* LCD LCD Init */
   LCD_7637_Controller();
   }

/*******************************************************************************
*
*                                LCD_Handler
*
*******************************************************************************/
/**
*
*  Called by the CircleOS scheduler to manage LCD tasks.
*
*  @attention  This function must <b>NOT</b> be called by the user.
*
**/
/******************************************************************************/
void LCD_Handler( void )
   {
   if( ++HandlerDivider % BACKLIGHT_DIVIDER )
      {
      return;
      }

   LCD_BackLightChange();
   }


/// @endcond

/* Public functions ----------------------------------------------------------*/

/*******************************************************************************
*
*                                LCD_SendLCDCmd
*
*******************************************************************************/
/**
*
*  Send on command byte to the LCD.
*
*  @param[in]  Cmd   An unsigned char containing the user command to send to the LCD.
*
**/
/******************************************************************************/
void LCD_SendLCDCmd( u8 Cmd )
   {
   /* Start the LCD send data sequence */
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET );     /* RS = 0 */
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );       /* RD = 1 */
   LCD_CtrlLinesWrite( GPIOx_CS_LCD,   CtrlPin_CS, Bit_RESET );     /* CS = 0 */
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET );     /* WR = 0 */

   /* Write data to the LCD */
   LCD_DataLinesWrite( GPIOx_D_LCD, (u32)Cmd );
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET );       /* WR = 1 */
   }

/*******************************************************************************
*
*                                LCD_SendLCDData
*
*******************************************************************************/
/**
*
*  Send one data byte to the LCD.
*
*  @param[in]  Data  An unsigned character containing the data to send to the LCD.
*  @pre        An LCD_SendLCDCmd was done with a command waiting for data.
*
*
**/
/******************************************************************************/
void LCD_SendLCDData( u8 Data )
   {
   /* Configure Data lines as Output */
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_SET );
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );
   LCD_CtrlLinesWrite( GPIOx_CS_LCD,   CtrlPin_CS, Bit_RESET );
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET );

   /* Write data to the LCD */
   LCD_DataLinesWrite( GPIOx_D_LCD,(u32)Data );
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET );
   }

/***********************************************************************************
*
*                                LCD_ReadLCDData
*
************************************************************************************/
/**
*
*  Read one data byte from the LCD.
*
*  @return     An unsigned 32 bit word containing the data returned by a LCD command.
*  @pre        An LCD_SendLCDCmd was done with a command returning data.
*
**/
/********************************************************************************/
u32 LCD_ReadLCDData( void )
   {
   u32 LCDData = 0;

   /* Configure Data lines as Input */
   LCD_DataLinesConfig(Input);

   /* Start the LCD send data sequence */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );         /* RS = 1 */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_SET );         /* WR = 1 */
   LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET );       /* CS = 0 */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_RESET );       /* RD = 0 */

   /* Read data from the LCD */
   LCDData = (GPIO_ReadInputData( GPIOx_D_LCD ) & LCD_DATA_PINS );

   LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET );          /* RD = 1 */

   /* Read the LCD returned data */
   LCD_DataLinesConfig( Output );

   return LCDData;
   }

/*******************************************************************************
*
*                                LCD_FillRect
*
*******************************************************************************/
/**
*
*  Fill a rectangle with a provided color.
*
*  @param[in]  x        The horizontal coordinate of the rectangle low left corner.
*  @param[in]  y        The vertical coordinate of the rectangle low left corner.
*  @param[in]  width    The rectangle width in pixels.
*  @param[in]  height   The rectangle height in pixels.
*  @param[in]  color    The RGB color to fill the rectangle with.
*
*  @warning    The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void LCD_FillRect( u16 x, u16 y, u16 width, u16 height, u16 color )
   {
   u8 Line;
   u8 Column;

   /* Select LCD screen area. */
   LCD_SetRect_For_Cmd( x, y, width, height );

   /* Send LCD RAM write command. */
   LCD_SendLCDCmd( ST7637_RAMWR );

   /* Fill selected LCD screen area with provided color. */
   for( Line = 0; Line < width; Line++ )
      {
      for( Column = 0; Column < height; Column++ )
         {
         LCD_SendLCDData( color & 0xff );
         LCD_SendLCDData( ( color >> 8 ) & 0xff );
         }
      }

   #ifdef TESTLCD
   /* Configure Data lines as Input */
   LCD_DataLinesConfig( Input );

   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET );    /* RST = 1  */
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET );  /* RST = 0  */
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET );    /* RST = 1  */

   /* Start the LCD send data sequence */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_RESET );     /* RS = 0   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */

   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_RESET );     /* RS = 0   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */

   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_SET );       /* WR = 1   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_RESET );     /* WR = 1   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_SET );       /* WR = 1   */

   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_RESET );     /* RD = 0   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */

   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_RESET );     /* RD = 0   */
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */

   /* Configure Data lines as Input */
   LCD_DataLinesConfig( Output );

   LCD_DataLinesWrite( GPIOx_D_LCD, ~0 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 0 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~1 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 1 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~2 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 2 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~4 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 4 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~8 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 8 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x10 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x10 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x20 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x20 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x40 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x40 );
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x80 );
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x80 );

   LCD_DataLinesConfig( Input );

   #endif
   }

/*******************************************************************************
*
*                                LCD_DrawRect
*
*******************************************************************************/
/**
*
*  Draw a rectangle with a provided color.
*
*  @param[in]  x        The horizontal coordinate of the rectangle low left corner.
*  @param[in]  y        The vertical coordinate of the rectangle low left corner.
*  @param[in]  width    The rectangle width in pixels.
*  @param[in]  height   The rectangle height in pixels.
*  @param[in]  color    The RGB color to draw the rectangle with.
*
*  @warning    The (0x0) point in on the low left corner.
*
**/
/******************************************************************************/
void LCD_DrawRect( u16 x, u16 y, u16 width, u16 height, u16 color )
   {
   // Draw horizontal sides.
   LCD_FillRect( x, y,              width, 1, color );
   LCD_FillRect( x, y + height - 1, width, 1, color );

   // Draw vertical sides.
   LCD_FillRect( x,              y, 1, height, color );
   LCD_FillRect( x + width - 1,  y, 1, height, color );
   }

/*******************************************************************************
*
*                                LCD_DrawPixel
*
*******************************************************************************/
/**
*
*  Draw a pixel on the LCD with the provided color.
*
*  @param[in]  XPos     The horizontal coordinate of the pixel.
*  @param[in]  YPos     The vertical coordinate of the pixel.
*  @param[in]  Color    The RGB color to draw the pixel with.

⌨️ 快捷键说明

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