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

📄 lcd.c

📁 STM32 I2C 模拟
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : lcd.c
* Author             : MCD Application Team
* Version            : V1.1.1
* Date               : 06/13/2008
* Description        : This file includes the LCD driver for AM-240320L8TNQW00H 
*                     (LCD_ILI9320) Liquid Crystal Display Module of STM3210E-EVAL
*                      board.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "lcd.h"
#include "fonts.h"


/* Private typedef -----------------------------------------------------------*/
typedef struct
{
  vu16 LCD_REG;
  vu16 LCD_RAM;
} LCD_TypeDef;

/* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */
#define LCD_BASE        ((u32)(0x60000000 | 0x0C000000))
#define LCD             ((LCD_TypeDef *) LCD_BASE)

/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/                              
/* Private variables ---------------------------------------------------------*/
  /* Global variables to set the written text color */
static  vu16 TextColor = 0x0000, BackColor = 0xFFFF;
  
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : STM3210E_LCD_Init
* Description    : Initializes the LCD.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void STM3210E_LCD_Init(void)
{
/* Configure the LCD Control pins --------------------------------------------*/
  LCD_CtrlLinesConfig();

/* Configure the FSMC Parallel interface -------------------------------------*/
  LCD_FSMCConfig();

  Systick_Delay_1ms(50); /* delay 50 ms */
 // Gamma for CMO 3.2”
    LCD_WriteReg(0x46,0x94);
    LCD_WriteReg(0x47,0x41);
    LCD_WriteReg(0x48,0x00);
    LCD_WriteReg(0x49,0x33);
    LCD_WriteReg(0x4a,0x23);
    LCD_WriteReg(0x4b,0x45);
    LCD_WriteReg(0x4c,0x44);
    LCD_WriteReg(0x4d,0x77);
    LCD_WriteReg(0x4e,0x12);
    LCD_WriteReg(0x4f,0xcc);
    LCD_WriteReg(0x50,0x46);
    LCD_WriteReg(0x51,0x82);
	
   //240x320 window setting
   LCD_WriteReg(0x02,0x00);
	 LCD_WriteReg(0x03,0x00);
	 LCD_WriteReg(0x04,0x01);
	 LCD_WriteReg(0x05,0x3f);
	 LCD_WriteReg(0x06,0x00);
	 LCD_WriteReg(0x07,0x00);
	 LCD_WriteReg(0x08,0x00); 
	 LCD_WriteReg(0x09,0xef); 

	// Display Setting
	LCD_WriteReg(0x01,0x06);
	LCD_WriteReg(0x16,0x68);
	LCD_WriteReg(0x23,0x95);
	LCD_WriteReg(0x24,0x95);
	LCD_WriteReg(0x25,0xff);

	LCD_WriteReg(0x27,0x02);
	LCD_WriteReg(0x28,0x02);
	LCD_WriteReg(0x29,0x02);
	LCD_WriteReg(0x2a,0x02);
	LCD_WriteReg(0x2c,0x02);
	  LCD_WriteReg(0x2d,0x02);						

	  LCD_WriteReg(0x3a,0x01);///*******************
	  LCD_WriteReg(0x3b,0x01);
	  LCD_WriteReg(0x3c,0xf0);
	  LCD_WriteReg(0x3d,0x00);

	  Systick_Delay_1ms(20);

	  LCD_WriteReg(0x35,0x38);
	  LCD_WriteReg(0x36,0x78);

	  LCD_WriteReg(0x3e,0x38);

	  LCD_WriteReg(0x40,0x0f);
	  LCD_WriteReg(0x41,0xf0);
    
	  // Power Supply Setting
	  LCD_WriteReg(0x19,0x49);//********
	  LCD_WriteReg(0x93,0x0f);//*******

	  Systick_Delay_1ms(10);

	  LCD_WriteReg(0x20,0x30);
	  LCD_WriteReg(0x1d,0x07);
	  LCD_WriteReg(0x1e,0x00);
	  LCD_WriteReg(0x1f,0x07);

	  // VCOM Setting for CMO 3.2” Panel
 	  LCD_WriteReg(0x44,0x4d);//4d***************4f
    LCD_WriteReg(0x45,0x13);//0x0a);
    Systick_Delay_1ms(10);
    LCD_WriteReg(0x1c,0x04);
    Systick_Delay_1ms(20);
    LCD_WriteReg(0x43,0x80);
    Systick_Delay_1ms(50);
    LCD_WriteReg(0x1b,0x08);
    Systick_Delay_1ms(40);
    LCD_WriteReg(0x1b,0x10);		  
    Systick_Delay_1ms(40);

    // Display ON Setting
    LCD_WriteReg(0x90,0x7f);
    LCD_WriteReg(0x26,0x04);
    Systick_Delay_1ms(40);
    LCD_WriteReg(0x26,0x24);
    LCD_WriteReg(0x26,0x2c);
    Systick_Delay_1ms(40);
    LCD_WriteReg(0x26,0x3c);

    // Set internal VDDD voltage
		LCD_WriteReg(0x57,0x02);
    LCD_WriteReg(0x55,0x00);
    LCD_WriteReg(0x57,0x00);
}

/*******************************************************************************
* Function Name  : LCD_SetTextColor
* Description    : Sets the Text color.
* Input          : - Color: specifies the Text color code RGB(5-6-5).
* Output         : - TextColor: Text color global variable used by LCD_DrawChar
*                  and LCD_DrawPicture functions.
* Return         : None
*******************************************************************************/
void LCD_SetTextColor(vu16 Color)
{
  TextColor = Color;
}

/*******************************************************************************
* Function Name  : LCD_SetBackColor
* Description    : Sets the Background color.
* Input          : - Color: specifies the Background color code RGB(5-6-5).
* Output         : - BackColor: Background color global variable used by 
*                  LCD_DrawChar and LCD_DrawPicture functions.
* Return         : None
*******************************************************************************/
void LCD_SetBackColor(vu16 Color)
{
  BackColor = Color;
}

/*******************************************************************************
* Function Name  : LCD_ClearLine
* Description    : Clears the selected line.
* Input          : - Line: the Line to be cleared.
*                    This parameter can be one of the following values:
*                       - Linex: where x can be 0..9
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_ClearLine(u8 Line)
{
  LCD_DisplayStringLine(Line, "                    ");
}

/*******************************************************************************
* Function Name  : LCD_Clear
* Description    : Clears the hole LCD.
* Input          : Color: the color of the background.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_Clear(u16 Color)
{
  u32 index = 0;
  
  LCD_SetCursor(0,0); 

  LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */

  for(index = 0; index < 76800; index++)
  {
    LCD->LCD_RAM = Color;
  }
 // while(1);  
}

/*******************************************************************************
* Function Name  : LCD_SetCursor
* Description    : Sets the cursor position.
* Input          : - Xpos: specifies the X position.
*                  - Ypos: specifies the Y position. 
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_SetCursor(u8 Xpos, u16 Ypos)
{
   
   LCD_WriteReg(0x06,(Xpos&0xff00)>>8);
   LCD_WriteReg(0x07,Xpos&0x00ff);
  
   LCD_WriteReg(0x02, (Ypos &0xff00)>>8);
   LCD_WriteReg(0x03, (Ypos) &0x00ff);  
 /* LCD_WriteReg(R32, Xpos);
  LCD_WriteReg(R33, Ypos); */ 
}			 

/*******************************************************************************
* Function Name  : LCD_DrawChar
* Description    : Draws a character on LCD.
* Input          : - Xpos: the Line where to display the character shape.
*                    This parameter can be one of the following values:
*                       - Linex: where x can be 0..9
*                  - Ypos: start column address.
*                  - c: pointer to the character data.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DrawChar(u8 Xpos, u16 Ypos, uc16 *c)
{
  u32 index = 0, i = 0;
  u8 Xaddress = 0;
  u16 Yaddress=0;
   
   Xaddress = Xpos;
   Yaddress=319-Ypos;			   
  LCD_SetCursor(Xaddress, Yaddress);  
 // LCD_SetDisplayWindow( Xpos+24, 319 - Ypos, 24,16 );
  for(index = 0; index < 24; index++)
  {
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    for(i = 0; i < 16; i++)
    {
      if((c[index] & (1 << i)) == 0x00)
      {
        LCD_WriteRAM(BackColor);
      }
      else
      {
        LCD_WriteRAM(TextColor);
      }
    }
   Xaddress++;
    LCD_SetCursor(Xaddress, Yaddress);
  }
}

/*******************************************************************************
* Function Name  : LCD_DisplayChar
* Description    : Displays one character (16dots width, 24dots height).
* Input          : - Line: the Line where to display the character shape .
*                    This parameter can be one of the following values:
*                       - Linex: where x can be 0..9
*                  - Column: start column address.
*                  - Ascii: character ascii code, must be between 0x20 and 0x7E.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DisplayChar(u8 Line, u16 Column, u8 Ascii)
{
  Ascii -= 32;
  LCD_DrawChar(Line, Column, &ASCII_Table[Ascii * 24]);
}

/*******************************************************************************
* Function Name  : LCD_DisplayStringLine
* Description    : Displays a maximum of 20 char on the LCD.
* Input          : - Line: the Line where to display the character shape .
*                    This parameter can be one of the following values:
*                       - Linex: where x can be 0..9
*                  - *ptr: pointer to string to display on LCD.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DisplayStringLine(u8 Line, u8 *ptr)
{
  u32 i = 0;
  u16 refcolumn =319;

  /* Send the string character by character on lCD */
  while ((*ptr != 0) & (i < 24))
  {
    /* Display one character on LCD */
    LCD_DisplayChar(Line, refcolumn, *ptr);
    /* Decrement the column position by 16 */
    refcolumn -= 14;
    /* Point on the next character */
    ptr++;
    /* Increment the character counter */
    i++;
  }
}

/*******************************************************************************
* Function Name  : LCD_SetDisplayWindow
* Description    : Sets a display window
* Input          : - Xpos: specifies the X buttom left position.
*                  - Ypos: specifies the Y buttom left position.
*                  - Height: display window height.
*                  - Width: display window width.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_SetDisplayWindow(u8 Xpos, u16 Ypos, u8 Height, u16 Width)
{
   /* Horizontal GRAM Start Address */
  u16 Yaddress=0,Xaddress=0;
  Xaddress=239-Xpos;
  Yaddress=319-Ypos;

  if(Xaddress + Height < 240)
  {
	 LCD_WriteReg(0x06,((Xaddress)&0xff00)>>8);
	 LCD_WriteReg(0x07,(Xaddress)&0x00ff);
	  LCD_WriteReg(0x08,((Xaddress+Height-1)&0xff00)>>8);
  LCD_WriteReg(0x09,(Xaddress+Height-1)&0x00ff);	
  }
  else
  {
   LCD_WriteReg(0x06,0x00);
   LCD_WriteReg(0x07,0x00);
   LCD_WriteReg(0x08,(Height&0xff00)>>8);
  LCD_WriteReg(0x09,Height&0x00ff);
   }
   	 /* Horizontal GRAM End Address */
  
  /* Vertical GRAM Start Address */
  if(Yaddress + Width < 320 )
 //	if(Yaddress >= Width  )
  {
   LCD_WriteReg(0x02, (Yaddress&0xff00)>>8);
  // LCD_WriteReg(0x02, ((Yaddress-Width+1)&0xff00)>>8);
  //  LCD_WriteReg(0x03, ((Yaddress-Width+1)&0x00ff));
   LCD_WriteReg(0x03, Yaddress&0x00ff);
  }  
  else
  {
   LCD_WriteReg(0x02, 0x00);
   LCD_WriteReg(0x03, 0x00);
  }
  /* Vertical GRAM End Address */
   LCD_WriteReg(0x04, ((Yaddress+Width-1) &0xff00)>>8);
   LCD_WriteReg(0x05, (Yaddress +Width -1)&0x00ff);
}

/*******************************************************************************
* Function Name  : LCD_WindowModeDisable
* Description    : Disables LCD Window mode.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WindowModeDisable(void)
{ 
   	 LCD_WriteReg(0x02,0x00);
	 LCD_WriteReg(0x03,0x00);
	 LCD_WriteReg(0x04,0x01);
	 LCD_WriteReg(0x05,0x3f);
	 LCD_WriteReg(0x06,0x00);
	 LCD_WriteReg(0x07,0x00);
	 LCD_WriteReg(0x08,0x00); 
	 LCD_WriteReg(0x09,0xef);
	 LCD_WriteReg(0x16,0x68);
    
}
/*******************************************************************************
* Function Name  : LCD_DrawLine
* Description    : Displays a line.
* Input          : - Xpos: specifies the X position.
*                  - Ypos: specifies the Y position.
*                  - Length: line length.
*                  - Direction: line direction.
*                    This parameter can be one of the following values: Vertical 
*                    or Horizontal.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DrawLine(u8 Xpos, u16 Ypos, u16 Length, u8 Direction)
{
  u32 i = 0;
  
  LCD_SetCursor(Xpos,319 - Ypos);

  if(Direction == Horizontal)
  {
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    for(i = 0; i < Length; i++)
    {
      LCD_WriteRAM(TextColor);
    }
  }
  else
  {
    for(i = 0; i < Length; i++)
    {
      LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
      LCD_WriteRAM(TextColor);

⌨️ 快捷键说明

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