各位大神,最近我在做用STM32F103VCT6 的FSMC 功能驱动TFT LCD 控制器是ILI9481 但读到的devicecode 老是0x0008 , 不知道是哪儿出了问题.,求大神指点.
硬件上:NOE -- RD
NWE -- RW
NE1 -- CS
FSMC_A16 -- RS
部分程序如下:
#include "usr_config.h"
#ifdef __TFT_LCD_CONFIG__
#include "common.h"
#include "ILI9481.h"
#include "stm32f10x.h"
#include "stm32f10x_conf.h"
#define LCD_RAM (*(volatile unsigned short *)0x60020000) /* RS = 1 */
#define LCD_REG (*(volatile unsigned short *)0x60000000) /* RS = 0 */
unsigned short DeviceCode;
/*******************************************************************************
* Function Name : LCD_Clk_Configure
* Description : TFT相关时钟配置
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Clk_Configure(void)
{
/* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
}
/*******************************************************************************
* Function Name : LCD_Port_Configure
* Description : TFT IO口配置
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Port_Configure(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*config PB.10 as backlight control prot*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* config PD.0/PD.1/PD.8/PD.9/PD.10/PD.14/PD.15 as lcd data port */
/* config PD.4 as FSMC_NOE(RD),PD.5 as FSMC_NWE(RW),PD.7 as FSMC_NE1(CS),PD.11 as FSMC_A16(RS) control port*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_7|
GPIO_Pin_11|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* config PE.7 -- PE.15 as lcd data port */
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_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,GPIO_Pin_7); //CS=1
GPIO_ResetBits(GPIOB,GPIO_Pin_2); //RESET=0
GPIO_SetBits(GPIOD,GPIO_Pin_4); //RD=1
GPIO_SetBits(GPIOD,GPIO_Pin_5); //RW=1
GPIO_SetBits(GPIOB,GPIO_Pin_10); //背光灯
}
/*******************************************************************************
* Function Name : LCD_FSMC_Configure
* Description : FSMC控制器配置
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_FSMC_Configure(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;
/*-- FSMC Configuration ------------------------------------------------------*/
/*----------------------- SRAM Bank 1 ----------------------------------------*/
/* FSMC_Bank1_NORSRAM1configuration */
p.FSMC_AddressSetupTime = 1;
p.FSMC_AddressHoldTime = 0;
p.FSMC_DataSetupTime = 5;
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_WriteBurst = FSMC_WriteBurst_Disable;
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/* - BANK 3 (of NOR/SRAM Bank 0~3) is enabled */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
/*******************************************************************************
* Function Name : ILI9481_Reset
* Description : ILI9481 控制器复位
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ILI9481_Reset(void)
{
LCD_RESET_1;
Delay(10);
LCD_RESET_0;
Delay(60);
LCD_RESET_1;
Delay(10);
}
/*******************************************************************************
* Function Name : LCD_Port_Init
* Description : TFT LCD 液晶接口初始化
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_Port_Init(void)
{
LCD_Clk_Configure();
LCD_Port_Configure();
LCD_FSMC_Configure();
}
/*******************************************************************************
* 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(unsigned short LCD_Reg,unsigned short LCD_RegValue)
{
/* Write 16-bit Index*/
LCD_REG = LCD_Reg;
/* Write 16-bit Reg */
LCD_RAM = LCD_RegValue;
}
void LCD_WriteReg_Only(unsigned short LCD_Reg)
{
/* Write 16-bit Index*/
LCD_REG = LCD_Reg;
}
/*******************************************************************************
* Function Name : LCD_ReadReg
* Description : Reads the selected LCD Register.
* Input : None
* Output : None
* Return : LCD Register Value.
*******************************************************************************/
unsigned short LCD_ReadReg(unsigned short LCD_Reg)
{
/* Write 8-bit Index (then Read Reg) */
LCD_REG = LCD_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(unsigned short Xpos, unsigned short 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);
}
/*******************************************************************************
* Function Name : Delay
* Description : time delay.
* Input : None
* None.
* Output : None
* Return : None
*******************************************************************************/
void Delay(u32 nCount)
{
u32 TimingDelay;
while(nCount--)
{
for(TimingDelay=0;TimingDelay<10000;TimingDelay++);
}
}
/****************************************************************************
* 名 称:void LCD_Init()
* 功 能:初始化 ILI9481 控制器
* 入口参数:无
* 出口参数:无
* 说 明:
* 调用方法:LCD_Init();
****************************************************************************/
void LCD_Init(void)
{
unsigned short i;
ILI9481_Reset();
Delay(5);
LCD_Port_Init();
Delay(5);
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); //设置地址模式:显示控制,b5=1
//set piexel formoat
LCD_WriteReg(0x3A,0x0055); //设置点格式,16位色
//set column_adress
LCD_WriteReg(0x2A,0x0000); // 行地址设置(320行,定义为X)
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x003f); // 0x13F=319
//set page address
LCD_WriteReg(0x2B,0x0000); // 列地址设置(480列,定义为Y)
LCD_WriteRAM(0x0000);
LCD_WriteRAM(0x0001);
LCD_WriteRAM(0x00df); // 0x1DF=479
//set play on
for(i=50000;i>0;i--);
LCD_WriteReg_Only(0x29); //打开显示
LCD_WriteReg_Only(0x2C); //写入显示数据
for(i=5000;i>0;i--);
}
#endif /* __ILI9481_CONFIG__ */ |
|