zhanglewis2008 发表于 2013-3-14 18:57:16

STM32F103VCT6 ILI9320 驱动TFT液晶屏,一直白屏

现在屏幕一直是白屏,用LCD_ReadReg(0x00)能读出驱动芯片的型号为9320

各位能帮我看下我的代码有没有问题吗,现在是寄存器的数据写不进去,不明白是什么原因,个人觉得应该是硬件方面的问题。谢谢各位了!


/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : lcd.c
* Author             : MCD Application Team
* Version            : V1.0.1
* Date               : 03/07/2013
* 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 "fonts.h"
#include "etl240320.h"
#include "network.h"
#include "stm32f10x_gpio.h"

/* LCD is connected to the FSMC_Bank1_NOR/SRAM4 and NE4 is used as ship select signal */
//#define LCD_REG            (*((vu16 *) 0x60000000)) /* RS = 0 */
//#define LCD_RAM            (*((vu16 *) 0x60020000)) /* RS = 1 */

#define LCD_REG            (*((vu16 *) 0x60000000)) /* RS = 0 */
#define LCD_RAM            (*((vu16 *) 0x60080000)) /* RS = 1 */
#define AM 1 //1:横屏, 0:竖屏(DS中为默认值)
#define ID 3 //屏扫方式

/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Global variables to set the written text color */
staticvu16 TextColor = 0x0000, BackColor = 0xFFFF;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name: Decrement_TimingDelay
* Description    : Decrements the TimingDelay variable.
* Input          : None
* Output         : TimingDelay
* Return         : None
*******************************************************************************/
void Decrement_TimingDelay(void)
{
if (TimingDelay != 0x00)
{
    TimingDelay--;
}
}




/*******************************************************************************
* Function Name: Delay
* Description    : Inserts a delay time.
* Input          : nCount: specifies the delay time length (time base 10 ms).
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(u32 nCount)
{
TimingDelay = nCount;

/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);

while(TimingDelay != 0)
{
}

/* Disable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);

/* Clear the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Clear);
}

/////////////////////////////////////////////////////////////////////////////////////////////
//
//* 函数名      : void delay ( u16 times )
//* 功能      : delay times
//* 输入参数    : 无
//* 输出参数    : 无
//* 修改记录    : 无
//* 备注      : 无
//*------------------------------------------------*/
void delay ( u16 times )
{
    vu32 i;
   
    while (times --)
      for (i = 0x00; i < DELAYTIME; i ++)
            i = i;
}


/*******************************************************************************
* Function Name: STM3210E_LCD_Init
* Description    : Initializes the LCD.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_Init(void)
{
u16 i;
u16 a,b,c,d,e,f;
BackLight_Set();
/* Configure the LCD Control pins --------------------------------------------*/
//delay(1000);
LCD_CtrlLinesConfig();
// sea_printf("starting....LCD CtrlLineConfig\n");
/* Configure the FSMC Parallel interface -------------------------------------*/
//delay(10000);
LCD_FSMCConfig();

//a= LCD_ReadReg(0x00);

//while(a);
// sea_printf("starting....LCD FSMCConfig\n");
//delay(1000);



//delay(1000); /* delay 50 ms */
//sea_printf("starting.....LCD 1 \n");// %0x\n",LCD_ReadReg(0x00));
//delay(5000);
//LCD_WriteReg(0x0000,0x0001);
//GPIO_WriteBit(GPIOD, GPIO_Pin_10, Bit_SET);

//sea_printf("starting.....LCD 2\n");

              //delay(5000);
//LCD_WriteReg(0x0000,0x0001);
//GPIO_WriteBit(GPIOD, GPIO_Pin_13, Bit_RESET);

//sea_printf("starting.....LCD 2\n");

      LCD_WriteReg(0xe3,0x3008);
      LCD_WriteReg(0xe7,0x0012);
      LCD_WriteReg(0xef,0x1231);
       // LCD_WriteReg(0xe5,0x8000);
      LCD_WriteReg(0x00,0x0000);//0001

      LCD_WriteReg(0x01,0x0100);
      LCD_WriteReg(0x02,0x0700);
      LCD_WriteReg(0x03,0x1030);//1038   1018//(1<<12)|(1<<5)|(1<<4)
      LCD_WriteReg(0x04,0x0000);
      LCD_WriteReg(0x08,0x0202);//020E//(2<<8)|(2<<0)
      LCD_WriteReg(0x09,0x0000);   /* set non-display area refresh cycle ISC */       
      LCD_WriteReg(0x0a,0x0000);/* FMARK function */
      LCD_WriteReg(0x0c,(1<<0));//0x0001/* RGB interface setting */
      LCD_WriteReg(0x0d,0x0000);/* Frame marker Position */
      LCD_WriteReg(0x0f,0x0000);/* RGB interface polarity */
      delay(50);
      LCD_WriteReg(0x07,0x0101);
      delay(50);
      LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4));//0x0000        //Power Control 1.(0x16b0)
        LCD_WriteReg(0x11,0x0007);                        //Power Control 2.(0x0001)

        LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0));        //0x0000//Power Control 3.(0x0138)
        LCD_WriteReg(0x13,0x0b00);        //Power Control 4.
      //++delay(50);
       // ++LCD_WriteReg(0x10,0x1290);        //Power Control 1.(0x16b0)
        //++LCD_WriteReg(0x11,0x0221);        //Power Control 2.(0x0001)
      //++delay(50);
        //++LCD_WriteReg(0x12,0x001a);        //Power Control 3.(0x0138)
      //++delay(50);
        //++LCD_WriteReg(0x13,0x1600);
        LCD_WriteReg(0x29,0x0000);//0x0022
      LCD_WriteReg(0x2b,(1<<14)|(1<<4)); //0x000a//frame rate and color control(0x0000)0x0020
      delay(50);
      LCD_WriteReg(0x20, 0x0000); // GRAM horizontal Address
        LCD_WriteReg(0x21, 0x0000); // GRAM Vertical Address
      // ----------- Adjust the Gamma Curve ----------//
        LCD_WriteReg(0x30, 0x0007);
        LCD_WriteReg(0x31, 0x0302);
        LCD_WriteReg(0x32, 0x0105);
        LCD_WriteReg(0x35, 0x0206);
        LCD_WriteReg(0x36, 0x0808);
        LCD_WriteReg(0x37, 0x0206);
        LCD_WriteReg(0x38, 0x0504);
        LCD_WriteReg(0x39, 0x0007);
        LCD_WriteReg(0x3c, 0x0105);
        LCD_WriteReg(0x3d, 0x0808);
/* Set GRAM area -------------------------------------------------------------*/
      LCD_WriteReg(0x50,0x0000);/* Horizontal GRAM Start Address */
      LCD_WriteReg(0x51,0x00ef);/* Horizontal GRAM End Address */
      LCD_WriteReg(0x52,0x0000);/* Vertical GRAM Start Address */
      LCD_WriteReg(0x53,0x013f);/* Vertical GRAM End Address */
      LCD_WriteReg(0x60,0x2700);/* Gate Scan Line   (1<<15)|(0x27<<8)*/
      LCD_WriteReg(0x61,0x0001); /* NDL,VLE, REV, 0x0000:互补色显示*/
      LCD_WriteReg(0x6a,0x0000);/* set scrolling line */
      
/* Partial Display Control ---------------------------------------------------*/
      LCD_WriteReg(0x80,0x0000);
      LCD_WriteReg(0x81,0x0000);
      LCD_WriteReg(0x82,0x0000);
      LCD_WriteReg(0x83,0x0000);
      LCD_WriteReg(0x84,0x0000);
      LCD_WriteReg(0x85,0x0000);

/* Panel Control -------------------------------------------------------------*/      
      LCD_WriteReg(0x90,(0<<7)|(16<<0));//0x0010   
      LCD_WriteReg(0x92,0x0000);
      LCD_WriteReg(0x93,0x0001);//0x0003
      LCD_WriteReg(0x95,0x0110);
      LCD_WriteReg(0x97,(0<<8));//0x0000      
      LCD_WriteReg(0x98,0x0000);
      //LCD_WriteReg(0x03,0x1000);
         //display on sequence   
      LCD_WriteReg(0x07,0x0173);/* 262K color and display ON */
      //LCD_WriteReg(0x32,0x0000);
      //LCD_WriteReg(0x33,0x013f);
      //LCD_WriteReg(0x22,0x0022);// 写0x22寄存器,
      
      LCD_Clear(White);

      //LCD_Test();
}

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



void LCD_Test(void)
{
    /* Set the LCD Back Color */
LCD_SetBackColor(Red);

/* Set the LCD Text Color */
LCD_SetTextColor(Red);

//LCD_DisplayStringLine(Line5,"      LCD TEST       ");

LCD_SetTextColor(Green);
LCD_DrawCircle(50,50,10);
}

//void Button1(u16 Xpos, u8 Ypos, vu16 Color)   //blocked by ray 10/06/28
//{
//s16 i = 0;
//LCD_SetTextColor(Color);
//for(i = 0; i < 5; i++)
//    LCD_DrawCircle(Xpos, Ypos, i);
//}
//
//
//void Button(u16 Xpos, u8 Ypos, vu16 Color)
//{
//LCD_SetTextColor(Color);
//LCD_DrawRect(Xpos, Ypos, 80, 40);
//}
//
//void Manu(void)
//{
//s16 i = 0;
//s16 j = 0;
//
//LCD_Clear(Yellow);
//delay(50);
//LCD_SetBackColor(Green);
//for (i = 0; i < 4; i++)
//    for (j = 0; j < 6; j++)
//      Button(i * 80, j * 40, Magenta);
//}



/*******************************************************************************
* 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(0x00, 0x00);

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

for(index = 0; index < 76800; index++)
{
    LCD_RAM = Color;
}
}




/*******************************************************************************
* 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(u16 Xpos, u8 Ypos)
{
LCD_WriteReg(0x20,Xpos); // 行
LCD_WriteReg(0x21,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(u16 x, u8 y, uc16 *c)
{
u16 index = 0;
s32i = 0;
u16 Yaddress = 0;   
Yaddress = y;
LCD_SetCursor(x,Yaddress);
for(index = 0; index < 24; index++)
{
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    for(i = 0; i < 16; i++)
      {
      if((c & (1 << i)) == 0x00)
      {
          LCD_WriteRAM(BackColor);//BackColor
      }
       else
      {
          LCD_WriteRAM(TextColor);//TextColor
      }
      }
      Yaddress++;
      LCD_SetCursor(x,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(u16 Column, u8 Line, u8 Ascii)   //blocked by ray ASCII 10/06/28
//{
//Ascii -= 32;
//LCD_DrawChar(Column, Line, &ASCII_Table);
//LCD_DrawChar(Line, Column, &ASCII_Table);
//}

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

/* Send the string character by character on lCD */
// while ((*ptr != 0) & (i < 20))
//{
//    /* Display one character on LCD */
//    LCD_DisplayChar(refcolumn, Line, *ptr);
//    /* Decrement the column position by 16 */
//   refcolumn += 16;
    /* 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(u16 Xpos, u8 Ypos, u8 Height, u16 Width)//需修改 blocked by ray 10/06/28
//{
///* Horizontal GRAM Start Address */
//if(Xpos >= Height)
//{
//    LCD_WriteReg(R80, (Xpos - Height + 1));
//}
//else
//{
//    LCD_WriteReg(R80, 0);
//}
///* Horizontal GRAM End Address */
//LCD_WriteReg(R81, Xpos);
///* Vertical GRAM Start Address */
//if(Ypos >= Width)
//{
//    LCD_WriteReg(R82, (Ypos - Width + 1));
//}
//else
//{
//    LCD_WriteReg(R82, 0);
//}
///* Vertical GRAM End Address */
//LCD_WriteReg(R83, Ypos);
//
//LCD_SetCursor(Xpos, Ypos);
//}

/*******************************************************************************
* Function Name: LCD_WindowModeDisable
* Description    : Disables LCD Window mode.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WindowModeDisable(void)//需修改
{
// LCD_SetDisplayWindow(239, 0x13F, 240, 320);
LCD_WriteReg(R3, 0x1038); //0x1030   
}
/*******************************************************************************
* 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(u16 Xpos, u8 Ypos, u16 Length, u8 Direction)
{
u32 i = 0;

LCD_SetCursor(Xpos, 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);
      Ypos++;
      LCD_SetCursor(Xpos, Ypos);
    }
}
}

/*******************************************************************************
* Function Name: LCD_DrawRect
* Description    : Displays a rectangle.
* Input          : - Xpos: specifies the X position.
*                  - Ypos: specifies the Y position.
*                  - Height: display rectangle height.
*                  - Width: display rectangle width.
* Output         : None
* Return         : None
*******************************************************************************/
//void LCD_DrawRect(u16 Xpos, u8 Ypos, u16 Width, u8 Height)
//{
//LCD_DrawLine(Xpos, Ypos, Width, Horizontal);
//LCD_DrawLine(Xpos, (Ypos + Height) , Width, Horizontal);
//
//LCD_DrawLine(Xpos, Ypos, Height, Vertical);
//LCD_DrawLine((Xpos + Width - 1), Ypos , Height, Vertical);
//}

/*******************************************************************************
* Function Name: LCD_DrawCircle
* Description    : Displays a circle.
* Input          : - Xpos: specifies the X position.
*                  - Ypos: specifies the Y position.
*                  - Height: display rectangle height.
*                  - Width: display rectangle width.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DrawCircle(u16 Xpos, u8 Ypos, u16 Radius)
{
s32D;/* Decision Variable */
u32CurX;/* Current X Value */
u32CurY;/* Current Y Value */

D = 3 - (Radius << 1);
CurX = 0;
CurY = Radius;

while (CurX <= CurY)
{
    LCD_SetCursor(Xpos + CurX, Ypos + CurY);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos + CurX, Ypos - CurY);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos - CurX, Ypos + CurY);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos - CurX, Ypos - CurY);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos + CurY, Ypos + CurX);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos + CurY, Ypos - CurX);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos - CurY, Ypos + CurX);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    LCD_SetCursor(Xpos - CurY, Ypos - CurX);
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
    LCD_WriteRAM(TextColor);

    if (D < 0)
    {
      D += (CurX << 2) + 6;
    }
    else
    {
      D += ((CurX - CurY) << 2) + 10;
      CurY--;
    }
    CurX++;
}
}

/*******************************************************************************
* Function Name: LCD_DrawMonoPict
* Description    : Displays a monocolor picture.
* Input          : - Pict: pointer to the picture array.
* Output         : None
* Return         : None
*******************************************************************************/
//void LCD_DrawMonoPict(uc32 *Pict)   //blocked by ray 10/06/28
//{
//u32 index = 0, i = 0;
//
//LCD_SetCursor(0, 0);
//
//LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
//for(index = 0; index < 2400; index++)
//{
//    for(i = 0; i < 32; i++)
//    {
//      if((Pict & (1 << i)) == 0x00)
//      {
//      LCD_WriteRAM(BackColor);
//      }
//      else
//      {
//      LCD_WriteRAM(TextColor);
//      }
//    }
//}
//}

/*******************************************************************************
* Function Name: LCD_WriteBMP
* Description    : Displays a bitmap picture loaded in the internal Flash.
* Input          : - BmpAddress: Bmp picture address in the internal Flash.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteBMP(u32 BmpAddress)//blocked by ray 10/06/28
{
u32 index = 0, size = 0;

/* Read bitmap size */
size = *(vu16 *) (BmpAddress + 2);
size |= (*(vu16 *) (BmpAddress + 4)) << 16;

/* Get bitmap data address offset */
index = *(vu16 *) (BmpAddress + 10);
index |= (*(vu16 *) (BmpAddress + 12)) << 16;

size = (size - index)/2;

BmpAddress += index;

/* Set GRAM write direction and BGR = 1 */
/* I/D=00 (Horizontal : decrement, Vertical : decrement) */
/* AM=1 (address is updated in vertical writing direction) */
LCD_WriteReg(R3, 0x1038);//0x1008

LCD_WriteRAM_Prepare();

for(index = 0; index < size; index++)
{
    LCD_WriteRAM(*(vu16 *)BmpAddress);
    BmpAddress += 2;
}

/* Set GRAM write direction and BGR = 1 */
/* I/D = 01 (Horizontal : increment, Vertical : decrement) */
/* AM = 1 (address is updated in vertical writing direction) */
LCD_WriteReg(R3, 0x1038);//0x1018
}

/*******************************************************************************
* Function Name: LCD_WriteReg
* Description    : Writes to the selected LCD register.
* Input          : - LCD_Reg: address of the selected register.
*                  - LCD_RegValue: value to write to the selected register.
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
LCD_REG = LCD_Reg;
/* Write 16-bit Reg */
LCD_RAM = LCD_RegValue;
}

/*******************************************************************************
* Function Name: LCD_ReadReg
* Description    : Reads the selected LCD Register.
* Input          : None
* Output         : None
* Return         : LCD Register Value.
*******************************************************************************/
u16 LCD_ReadReg(u8 LCD_Reg)
{
/* Write 16-bit Index (then Read Reg) */
LCD_REG = LCD_Reg;
/* Read 16-bit Reg */
return (LCD_RAM);
}

/*******************************************************************************
* Function Name: LCD_WriteRAM_Prepare
* Description    : Prepare to write to the LCD RAM.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteRAM_Prepare(void)
{
//LCD_REG = R34;
LCD_REG = 0x22;

}

/*******************************************************************************
* Function Name: LCD_WriteRAM
* Description    : Writes to the LCD RAM.
* Input          : - RGB_Code: the pixel color in RGB mode (5-6-5).
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_WriteRAM(u16 RGB_Code)
{
/* Write 16-bit GRAM Reg */
LCD_RAM = RGB_Code;
}

/*******************************************************************************
* Function Name: LCD_ReadRAM
* Description    : Reads the LCD RAM.
* Input          : None
* Output         : None
* Return         : LCD RAM Value.
*******************************************************************************/
u16 LCD_ReadRAM(void)
{
/* Write 16-bit Index (then Read Reg) */
LCD_REG = R34; /* Select GRAM Reg */
/* Read 16-bit Reg */
return LCD_RAM;
}

/*******************************************************************************
* Function Name: LCD_PowerOn
* Description    : Power on the LCD.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_PowerOn(void) //需要修改
{
/* Power On sequence ---------------------------------------------------------*/
LCD_WriteReg(R16, 0x0000); /* SAP, BT, AP, DSTB, SLP, STB */
LCD_WriteReg(R17, 0x0007); /* DC1, DC0, VC */
LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
LCD_WriteReg(R19, 0x0000); /* VDV for VCOM amplitude*/
delay(200);             /* Dis-charge capacitor power voltage (200ms) */
LCD_WriteReg(R16, 0x17B0); /* SAP, BT, AP, DSTB, SLP, STB */
LCD_WriteReg(R17, 0x0227); /* DC1, DC0, VC   0x0001*/
delay(50);            /* Delay 50 ms */
LCD_WriteReg(R18, 0x001c); /* VREG1OUT voltage 0x013e*/
delay(50);            /* Delay 50 ms */
LCD_WriteReg(R19, 0x1800); /* VDV for VCOM amplitude 0x1c00*/
LCD_WriteReg(R41, 0x001c); /* VCM for VCOMH 0x001e*/
delay(50);            /* Delay 50 ms */
LCD_WriteReg(R7, 0x0173);/* 262K color and display ON */
}

/*******************************************************************************
* Function Name: LCD_DisplayOn
* Description    : Enables the Display.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DisplayOn(void)//需要修改
{
/* Display On */
LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
}

/*******************************************************************************
* Function Name: LCD_DisplayOff
* Description    : Disables the Display.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_DisplayOff(void)//需要修改
{
/* Display Off */
LCD_WriteReg(R7, 0x0);
}

/*******************************************************************************
* Function Name: LCD_CtrlLinesConfig
* Description    : Configures LCD Control lines (FSMC Pins) in alternate function
                   Push-Pull mode.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

/* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD |
                         RCC_APB2Periph_GPIOE |RCC_APB2Periph_GPIOF |
                         RCC_APB2Periph_GPIOG |RCC_APB2Periph_AFIO, ENABLE);


/* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
    PD.10(D15), PD.14(D0), PD.15(D1) as alternate
   function push pull */

/*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
                              GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
                              GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);*/

/*2013.02.23 LCD FSMC模式下数据线与控制线配置*/

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_14|GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOD, &GPIO_InitStructure);
      

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
      GPIO_Init(GPIOE, &GPIO_InitStructure);
      
          /* Set PD.13(A18 (RS)) as alternate function push pull */
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
      GPIO_Init(GPIOD, &GPIO_InitStructure);

        /*背光控制*/
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOC, &GPIO_InitStructure);//GPIO_Init(GPIOC, &GPIO_InitStructure);


/* Set PD.11(A16 (RS)) as alternate function push pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOD, &GPIO_InitStructure);
*/

/* Set PD.13(A18 (RS)) as alternate function push pull */
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
//GPIO_Init(GPIOD, &GPIO_InitStructure);




/* Set PD.7(NE1 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//GPIO_Init(GPIOD, &GPIO_InitStructure);

   // Configure only the gpio relative to the led LD1
//GPIO_InitStructure.GPIO_Pin =GPIO_Pin_10;//2013.02.23改   GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//GPIO_Init(GPIOD, &GPIO_InitStructure);
   
// clear (turn off) all the configured leds
//BackLight_Set();
BackLight_Clear();

}

/*******************************************************************************
* Function Name: LCD_FSMCConfig
* Description    : Configures the Parallel interface (FSMC) for LCD(Parallel mode)
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_FSMCConfig(void)
{
FSMC_NORSRAMInitTypeDefFSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDefp;

/*-- FSMC Configuration ------------------------------------------------------*/
/*----------------------- SRAM Bank 1 ----------------------------------------*/
   /* FSMC_Bank1_NORSRAM1 configuration */
#if 0
p.FSMC_AddressSetupTime = 0;   
p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 2;
p.FSMC_BusTurnAroundDuration = 0;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_B;
#endif
p.FSMC_AddressSetupTime = 0;
p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 2;
p.FSMC_BusTurnAroundDuration = 0;
p.FSMC_CLKDivision = 0;
p.FSMC_DataLatency = 0;
p.FSMC_AccessMode = FSMC_AccessMode_B;

//p.FSMC_AddressSetupTime = 0x02;
//p.FSMC_AddressHoldTime = 0x00;
//p.FSMC_DataSetupTime = 0x05;
//p.FSMC_BusTurnAroundDuration = 0x00;
//p.FSMC_CLKDivision = 0x00;
//p.FSMC_DataLatency = 0x00;
//p.FSMC_AccessMode = FSMC_AccessMode_B;


FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;//FSMC_Bank1_NORSRAM1; FSMC_Bank1_NORSRAM2
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//++FSMC_MemoryType_SRAM; FSMC_MemoryType_NOR
FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;//FSMC_ExtendedMode_Disable FSMC_ExtendedMode_Enable
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);

/* Enable FSMC_Bank1_NORSRAM1 */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}


/*******************************************************************************
* Function Name: void BackLight_Set ( u32 ledsel )
* Description    : Set BackLight
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void BackLight_Set (void )
{
//    GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_RESET);
   GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_SET);
} // end BackLight_Set()


/*******************************************************************************
* Function Name: void BackLight_Clear ( u32 ledsel )
* Description    : Clear BackLight
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void BackLight_Clear ( void )
{
   GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);//GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_RESET);
} // end BackLight_Clear()


/* 4 functions related to programe transplant */
//* --------------------------------------------------------------------------
//* 函数名                : void Ssd2119InitDisplay ( void )
//* 功能                : initialize lcd display
//* 输入参数                : 无
//* 输出参数                : 无
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------

void Ssd2119InitDisplay( void )
{
LCD_Init();
}


//* --------------------------------------------------------------------------
//* 函数名                : void Ssd2119PutPixel ( int x, int y, U16 color )
//* 功能                : LCD打点函数
//* 输入参数                : int x , int y坐标, u16 color 颜色
//* 输出参数                : 无
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------
void Ssd2119PutPixel   ( u16 x, u8 y, u16 color )
{
LCD_SetCursor(x, y);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM( color );   
}


//* --------------------------------------------------------------------------
//* 函数名                : void Ssd2119GetPixel ( int x, int y )
//* 功能                : get LCD color
//* 输入参数                : 无
//* 输出参数                : int color 颜色
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------
u16Ssd2119GetPixel   ( u16 x, u8 y )
{
LCD_SetCursor(x, y);
return LCD_ReadRAM();
}

//* --------------------------------------------------------------------------
//* 函数名                : void Ssd2119ClrScreen ( void )
//* 功能                : clear screen
//* 输入参数                : 无
//* 输出参数                : 无
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------
void Ssd2119ClrScreen    ( void )
{
   u16 bkcolor = (u16)getbkcolor();
   LCD_Clear( bkcolor );
}



/* 4 functions related to programe transplant */
//* --------------------------------------------------------------------------
//* 函数名                : void Etl240320InitDisplay ( void )
//* 功能                : initialize lcd display
//* 输入参数                : 无
//* 输出参数                : 无
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------

void Etl240320InitDisplay( void )
{
LCD_Init();
}


//* --------------------------------------------------------------------------
//* 函数名                : void Etl240320PutPixel ( int x, int y, U16 color )
//* 功能                : LCD打点函数
//* 输入参数                : int x , int y坐标, u16 color 颜色
//* 输出参数                : 无
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------
void Etl240320PutPixel   ( u16 x, u8 y, u16 color )
{
LCD_SetCursor(x, y);
LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
LCD_WriteRAM( color );   
}


//* --------------------------------------------------------------------------
//* 函数名                : void Etl240320GetPixel ( int x, int y )
//* 功能                : get LCD color
//* 输入参数                : 无
//* 输出参数                : int color 颜色
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------
u16Etl240320GetPixel   ( u16 x, u8 y )
{
LCD_SetCursor(x, y);
return LCD_ReadRAM();
}

//* --------------------------------------------------------------------------
//* 函数名                : void Etl240320ClrScreen ( void )
//* 功能                : clear screen
//* 输入参数                : 无
//* 输出参数                : 无
//* 修改记录                : 无
//* 备注                : 无
//* --------------------------------------------------------------------------
void Etl240320ClrScreen    ( void )
{
   u16 bkcolor = (u16)getbkcolor();
   LCD_Clear( bkcolor );
}



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

zhanglewis2008 发表于 2013-3-19 09:39:30

已解决{:smile:}

crazy_bin 发表于 2013-3-19 09:57:31

太长了,看着头晕

zhanglewis2008 发表于 2013-3-19 10:22:04

crazy_bin 发表于 2013-3-19 09:57 static/image/common/back.gif
太长了,看着头晕

难怪没人帮我解决问题,还是要靠自己呀!

crazy_bin 发表于 2013-3-19 18:43:49

zhanglewis2008 发表于 2013-3-19 10:22 static/image/common/back.gif
难怪没人帮我解决问题,还是要靠自己呀!

对啊,代码太长了。。。除了说是考题,我估计一般没人管
页: [1]
查看完整版本: STM32F103VCT6 ILI9320 驱动TFT液晶屏,一直白屏