大侠们,帮我看下,我今天用FSMC去驱动ILI9481,显示始终不对,点不亮液晶,急死人了。
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : lcd_control.c
* Author : MingYe Application Team
* Version : V1.1.1
* Date : 07/28/2011
* Description : This file includes the LCD driver for LCD_ILI9481 Liquid
* Crystal Display Module of STM32103VCT6-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"lcd_control.h"
#define LCD_RAM (*((PUINT16)0x60020000))
#define LCD_REG (*((PUINT16)0x60000000))
UINT16 DeviceCode;
//static UINT16 TextColor = 0x0000, BackColor = 0xFFFF;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*********************************************************************************************************/
/*=======================================================================================================*/
/*******************************************************************************
* 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, and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB, GPIO_Pin_10); // LCD RESET
GPIO_SetBits(GPIOB, GPIO_Pin_11); // make the DataWidth of the LCD is 16 bits.
GPIO_SetBits(GPIOB, GPIO_Pin_10); // LCD restart
/* 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);
/* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
PE.14(D11), PE.15(D12) as alternate function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | 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_Init(GPIOE, &GPIO_InitStructure);
/*********************************************
** 硬件连接说明 **
** STM32 ili9481 **
** PE/PD(FSMC_D0-15) <----> DB0~15 **
** PD4 (FSMC_NOE) <----> nRD **
** PD5 (FSMC_NWE) <----> nWR **
** PD7 (FSMC_NE1) <----> nCS **
** PD11(FSMC_A16) <----> RS **
** PB10 <----> nReset **
*********************************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_11;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/*******************************************************************************
* 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_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
/*-- FSMC Configuration ------------------------------------------------------*/
/*----------------------- SRAM Bank 1 ----------------------------------------*/
/* FSMC_Bank1_NORSRAM1configuration */
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;
/* Color LCD configuration ------------------------------------
LCD configured as follow:
- Data/Address MUX = Disable
- Memory Type = SRAM
- Data Width = 16bit
- Write Operation = Enable
- Extended Mode = Enable
- Asynchronous Wait = Disable */
FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
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_NORSRAMInitStructure.FSMC_AsyncWait = FSMC_AsyncWait_Disable;
FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
void LCD_X_Init(void)
{
/* Configure the LCD Control pins --------------------------------------------*/
LCD_CtrlLinesConfig();
/* Configure the FSMC Parallel interface -------------------------------------*/
LCD_FSMCConfig();
}
/*******************************************************************************
* 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(UINT16 LCD_Reg,UINT16 LCD_RegValue)
{
/* Write 16-bit Index, then Write Reg */
LCD_REG = LCD_Reg;
/* Write 16-bit Reg */
LCD_RAM = LCD_RegValue;
}
void LCD_WriteReg_Only(UINT16 LCD_Reg)
{
/* Write 16-bit Index, then Write Reg */
LCD_REG = LCD_Reg;
}
/*******************************************************************************
* Function Name : LCD_ReadReg
* Description : Reads the selected LCD Register.
* Input : None
* Output : None
* Return : LCD Register Value.
*******************************************************************************/
UINT16 LCD_ReadReg(UINT16 LCD_Reg)
{
/* Write 8-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 = 0x002C;
}
/*******************************************************************************
* 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(UINT16 RGB_Code)
{
/* Write 8-bit GRAM Reg */
LCD_RAM = RGB_Code;
}
/*******************************************************************************
* Function Name : LCD_ReadRAM
* Description : Reads the LCD RAM.
* Input : None
* Output : None
* Return : LCD RAM Value.
*******************************************************************************/
UINT16 LCD_ReadRAM(void)
{
// UINT16 dummy;
/* Write 16-bit Index (then Read Reg) */
LCD_REG = 0x002C; /* Select GRAM Reg */
/* Read 16-bit Reg */
return LCD_RAM;
}
/*******************************************************************************
* 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(UINT16 Xpos, UINT16 Ypos)
{
LCD_WriteReg(0x002A,Xpos>>8);
LCD_WriteRAM(Xpos&0x00FF);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x003F);
LCD_WriteReg(0x002b,Ypos>>8);
LCD_WriteRAM(0x00FF&Ypos);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x00df);
LCD_WriteReg_Only(0x002C);
}
void Delay(u32 nCount)
{
u32 TimingDelay;
while(nCount--)
{
for(TimingDelay=0;TimingDelay<10000;TimingDelay++);
}
}
/****************************************************************************
* 名 称:void LCD_Init()
* 功 能:初始化 ILI9481 控制器
* 入口参数:无
* 出口参数:无
* 说 明:
* 调用方法:LCD_Init();
****************************************************************************/
void LCD_Init(void)
{
UINT16 i;
LCD_X_Init();
Delay(500); /* delay 50 ms */
DeviceCode = LCD_ReadReg(0x00BF);
LCD_WriteReg_Only(0x0011);
for(i=15000;i>0;i--);
LCD_WriteReg_Only(0x0013);
LCD_WriteReg(0x00d0,0x0007);
LCD_WriteRAM(0x0040);
LCD_WriteRAM(0x001c);
//VCOM Control
LCD_WriteReg(0xD1,0x0000);
LCD_WriteRAM(0x0018);
LCD_WriteRAM(0x001D);
//Power set for normol mode
LCD_WriteReg(0xD2,0x0001);
LCD_WriteRAM(0x0011);
//panel driving setting
LCD_WriteReg(0xC0,0x0000);
LCD_WriteRAM(0x003B);
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0002);
LCD_WriteRAM(0x0011);
//Display time setting for normal mode
LCD_WriteReg(0xC1,0x0010);
LCD_WriteRAM(0x000B);
LCD_WriteRAM(0x0088);
// Frame rate and inversion control
LCD_WriteReg(0xC5,0x0001);
//GAMMA Setting
LCD_WriteReg(0xC8,0x0000);
LCD_WriteRAM(0x0030);
LCD_WriteRAM(0x0036);
LCD_WriteRAM(0x0045);
LCD_WriteRAM(0x0004);
LCD_WriteRAM(0x0016);
LCD_WriteRAM(0x0037);
LCD_WriteRAM(0x0075);
LCD_WriteRAM(0x0077);
LCD_WriteRAM(0x0054);
LCD_WriteRAM(0x000f);
LCD_WriteRAM(0x0000);
//LSI TEST Registers
LCD_WriteReg(0xE4,0x00A0);
LCD_WriteReg(0xF0,0x0001);
LCD_WriteReg(0xF3,0x0040);
LCD_WriteRAM(0x000A);
LCD_WriteReg(0xF7,0x0080);
//set address_mode
LCD_WriteReg(0x36,0x000A);
//set piexel formoat
LCD_WriteReg(0x3A,0x0055);
//set column_adress
LCD_WriteReg(0x2A,0x0000);
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x003f);
//set page address
LCD_WriteReg(0x2B,0x0000);
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x00df);
//set play on
for(i=50000;i>0;i--);
LCD_WriteReg_Only(0x29);
LCD_WriteReg_Only(0x2C);
for(i=5000;i>0;i--);
} |