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

📄 lcd.c

📁 ST32F10xxx+uCOSII2.85的官方源代码,带LCD驱动,支持Keil3和IAR环境.这个可以做为参考,实际使用需要修改,他做的太复杂了,目录也很深
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name          : lcd.c
* Author             : MCD Application Team
* Date First Issued  : 05/21/2007
* Description        : This file includes the LCD driver for AM-240320LTNQW00H
*                      liquid Crystal Display Module of STM32F10x-EVAL.
********************************************************************************
* History:
* 05/21/2007: V0.1
********************************************************************************
* THE PRESENT SOFTWARE 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 SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

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

/* Private typedef -----------------------------------------------------------*/
/* 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 ---------------------------------------------------------*/
static  u32   StrLength(u8 *Str);
static  void  Delay    (u32 nCount);

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

/* Configure the SPI2 interface ----------------------------------------------*/
  LCD_SPIConfig();

/* Enable the LCD Oscillator -------------------------------------------------*/
  LCD_WriteReg(R1, 0x10);
  LCD_WriteReg(R0, 0xA0);
  LCD_WriteReg(R3, 0x01);
  Delay(1); /* Delay 10 ms */
  LCD_WriteReg(R3, 0x00);
  LCD_WriteReg(R43, 0x04);

  LCD_WriteReg(R40, 0x18);
  LCD_WriteReg(R26, 0x05);
  LCD_WriteReg(R37, 0x05);
  LCD_WriteReg(R25, 0x00);

/* LCD Power On --------------------------------------------------------------*/
  LCD_WriteReg(R28, 0x73);
  LCD_WriteReg(R36, 0x74);
  LCD_WriteReg(R30, 0x01);
  LCD_WriteReg(R24, 0xC1);
  Delay(1); /* Delay 10 ms */
  LCD_WriteReg(R24, 0xE1);
  LCD_WriteReg(R24, 0xF1);
  Delay(6); /* Delay 60 ms */
  LCD_WriteReg(R24, 0xF5);
  Delay(6); /* Delay 60 ms */
  LCD_WriteReg(R27, 0x09);
  Delay(1); /* Delay 10 ms */
  LCD_WriteReg(R31, 0x11);
  LCD_WriteReg(R32, 0x0E);
  LCD_WriteReg(R30, 0x81);
  Delay(1); /* Delay 10 ms */

/* Chip Set ------------------------------------------------------------------*/
  LCD_WriteReg(R157, 0x00);
  LCD_WriteReg(R192, 0x00);

  LCD_WriteReg(R14, 0x00);
  LCD_WriteReg(R15, 0x00);
  LCD_WriteReg(R16, 0x00);
  LCD_WriteReg(R17, 0x00);
  LCD_WriteReg(R18, 0x00);
  LCD_WriteReg(R19, 0x00);
  LCD_WriteReg(R20, 0x00);
  LCD_WriteReg(R21, 0x00);
  LCD_WriteReg(R22, 0x00);
  LCD_WriteReg(R23, 0x00);

  LCD_WriteReg(R52, 0x01);
  LCD_WriteReg(R53, 0x00);

  LCD_WriteReg(R75, 0x00);
  LCD_WriteReg(R76, 0x00);
  LCD_WriteReg(R78, 0x00);
  LCD_WriteReg(R79, 0x00);
  LCD_WriteReg(R80, 0x00);

  LCD_WriteReg(R60, 0x00);
  LCD_WriteReg(R61, 0x00);
  LCD_WriteReg(R62, 0x01);
  LCD_WriteReg(R63, 0x3F);
  LCD_WriteReg(R64, 0x02);
  LCD_WriteReg(R65, 0x02);
  LCD_WriteReg(R66, 0x00);
  LCD_WriteReg(R67, 0x00);
  LCD_WriteReg(R68, 0x00);
  LCD_WriteReg(R69, 0x00);
  LCD_WriteReg(R70, 0xEF);
  LCD_WriteReg(R71, 0x00);
  LCD_WriteReg(R72, 0x00);
  LCD_WriteReg(R73, 0x01);
  LCD_WriteReg(R74, 0x3F);

  LCD_WriteReg(R29, 0x08);  /* R29:Gate scan direction setting */

  LCD_WriteReg(R134, 0x00);
  LCD_WriteReg(R135, 0x30);
  LCD_WriteReg(R136, 0x02);
  LCD_WriteReg(R137, 0x05);

  LCD_WriteReg(R141, 0x01);  /* R141:Register set-up mode for one line clock */
  LCD_WriteReg(R139, 0x20);  /* R139:One line SYSCLK number in one-line */
  LCD_WriteReg(R51, 0x01);  /* R51:N line inversion setting */
  LCD_WriteReg(R55, 0x01);  /* R55:Scanning method setting */
  LCD_WriteReg(R118, 0x00);

/* Gamma Set -----------------------------------------------------------------*/
  LCD_WriteReg(R143, 0x10);
  LCD_WriteReg(R144, 0x67);
  LCD_WriteReg(R145, 0x07);
  LCD_WriteReg(R146, 0x65);
  LCD_WriteReg(R147, 0x07);
  LCD_WriteReg(R148, 0x01);
  LCD_WriteReg(R149, 0x76);
  LCD_WriteReg(R150, 0x56);
  LCD_WriteReg(R151, 0x00);
  LCD_WriteReg(R152, 0x06);
  LCD_WriteReg(R153, 0x03);
  LCD_WriteReg(R154, 0x00);

/* Display On ----------------------------------------------------------------*/
  LCD_WriteReg(R1, 0x50);
  LCD_WriteReg(R5, 0x04);

  LCD_WriteReg(R0, 0x80);
  LCD_WriteReg(R59, 0x01);
  Delay(4);  /* Delay 40 ms */
  LCD_WriteReg(R0, 0x20);
}

void  Delay (u32 nCount)
{
    volatile  int  i;


    for (i = 0; i < nCount * 100; i++) {
        ;
    }
}

/*******************************************************************************
* 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          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_Clear(void)
{
  u32 index = 0;

  LCD_SetCursor(0x00, 0x013F);

  for(index = 0; index < 76800; index++)
  {
    LCD_WriteRAM(White);
  }
}

/*******************************************************************************
* 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(R66, Xpos);
  LCD_WriteReg(R67, ((Ypos & 0x100)>> 8));
  LCD_WriteReg(R68, (Ypos & 0xFF));
}

/*******************************************************************************
* 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;

  Xaddress = Xpos;

  LCD_SetCursor(Xaddress, Ypos);

  for(index = 0; index < 24; index++)
  {
    for(i = 0; i < 16; i++)
    {
      if((c[index] & (1 << i)) == 0x00)
      {
        LCD_WriteRAM(BackColor);
      }
      else
      {
        LCD_WriteRAM(TextColor);
      }
    }
    Xaddress++;
    LCD_SetCursor(Xaddress, Ypos);
  }
}

/*******************************************************************************
* 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 < 20))
  {
    /* Display one character on LCD */
    LCD_DisplayChar(Line, refcolumn, *ptr);
    /* Decrement the column position by 16 */
    refcolumn -= 16;
    /* Point on the next character */
    ptr++;
    /* Increment the character counter */
    i++;
  }
}

/*******************************************************************************
* Function Name  : LCD_DisplayString
* Description    : Displays a maximum of 200 char on the LCD.
* Input          : - Line: the starting 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_DisplayString(u8 Line, u8 *ptr)
{
  u32 i = 0, column = 0, index = 0, spaceindex = 0;
  u16 refcolumn = 319;
  u32 length = 0;

  /* Get the string length */
  length = StrLength(ptr);
  if(length > 200)
  {
    /* Set the Cursor position */
    LCD_SetCursor(Line, 0x013F);
    /* Clear the Selected Line */
    LCD_ClearLine(Line);
    LCD_DisplayStringLine(Line, "   String too long  ");
  }
  else
  {
    /* Set the Cursor position */
    LCD_SetCursor(Line, 0x013F);
    /* Clear the Selected Line */
//    LCD_ClearLine(Line);

    while(length--)
    {
      if(index == 20)
      {
        if(*ptr == 0x20)
        {
          ptr++;
        }
        else
        {
          for(i = 0; i < spaceindex; i++)
          {
            LCD_DisplayChar(Line, column, ' ');
            column -= 16;
          }
          ptr -= (spaceindex - 1);
          length += (spaceindex - 1);
        }
        Line += 24;
        /* Clear the Selected Line */
//        LCD_ClearLine(Line);
        refcolumn = 319;
        index = 0;
      }
      /* Display one character on LCD */
      LCD_DisplayChar(Line, refcolumn, *ptr);

      /* Increment character number in one line */
      index++;

      /* Decrement the column position by 16 */
      refcolumn -= 16;
      /* Point on the next character */
      ptr++;
      /* Increment the number of character after the last space */
      spaceindex++;
      if(*ptr == 0x20)
      {
        spaceindex = 0;
        column = refcolumn - 16;
      }
    }
  }
}

/*******************************************************************************
* Function Name  : LCD_ScrollText
* Description    :
* Input          :
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_ScrollText(u8 Line, u8 *ptr)
{

⌨️ 快捷键说明

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