微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 9G-STM32 EWARM开发过程简介之四

9G-STM32 EWARM开发过程简介之四

时间:11-29 来源:互联网 点击:
// 9G-STM32 EWARM开发过程简介之四--移植FSMC的T6963C驱动

/*
一,把VDT6与T6963C连接
NOE -> /RD ;
NWE -> /WR ;
NE1 -> /CE ;
A16 -> C/D ;A16 最近,接线最方便。
PC4 -> /RST ;
D8 -> DB0 ; D8-D15 最近, 接线最方便。
...
D15 -> DB7 ;

二,把IO配置成FSMC模式
*/
void LCD_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

/* Enable FSMC, GPIOC, GPIOD, GPIOE clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE , ENABLE);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

/* Set PC.04(LCDRST) as alternate
function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

/* Set PD.04(NOE), PD.05(NWE), PD.07(NE1), PD.08(D13), PD.09(D14), PD.10(D15), PD.11(A16) as alternate
function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 ;
GPIO_Init(GPIOD, &GPIO_InitStructure);

/* Set 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_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}

/*
三,配置FSMC工作模式
*/
void LCD_FSMCConfig(void)
{
FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
FSMC_NORSRAMTimingInitTypeDef p;

/*-- FSMC Configuration ------------------------------------------------------*/
/*----------------------- SRAM Bank 1 ----------------------------------------*/
/* FSMC_Bank1_NORSRAM1 configuration */
p.FSMC_AddressSetupTime = 1;
p.FSMC_AddressHoldTime = 1;
p.FSMC_DataSetupTime = 6;
p.FSMC_BusTurnAroundDuration = 1;
p.FSMC_CLKDivision = 1;
p.FSMC_DataLatency = 2;
p.FSMC_AccessMode = FSMC_AccessMode_A;

/* 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_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);
}
/*
四,定义物理访问地址
*///TXEC 240128BDLNW-EY
// T6963C

/*A16=0 -- dat*/
#define LCD_DAT_ADDR(*((volatile unsigned char *) 0x60000001))
/*A16=1 -- cmd*/
#define LCD_CMD_ADDR(*((volatile unsigned char *) 0x60020001))

#define IMAGE1
#define TEXT0
#define VISION_PIXEL_LENGTH240
#define VISION_PIXEL_WIDTH128
#define FRAME_BUFFER_LENGTH256
#define FRAME_BUFFER_WIDTH128
/*
五,定义指令访问接口
*///指令&数据读写状态
static void RWCheck(void)
{
while((LCD_CMD_ADDR & 0x03) != 0x03); //低电平忙
}
//数据自动写状态
void CheckAutoWrite(void)
{
while((LCD_CMD_ADDR & 0x08) != 0x08); //低电平忙
}
//屏读/屏考贝出错状态
void CheckScreen(void)
{
while(LCD_CMD_ADDR & 0x40); //1出错,0正确
}
static void WriteDATA(unsigned char Data)
{
RWCheck();
LCD_DAT_ADDR = Data;
}
static unsigned char ReadDATA(void)
{
RWCheck();
return LCD_DAT_ADDR;
}
static void WriteCMD0(unsigned char Comd)
{
RWCheck();
LCD_CMD_ADDR = Comd;
}
static void WriteCMD1(unsigned char Para,unsigned char Comd)
{
WriteDATA(Para);
WriteCMD0(Comd);
}
static void WriteCMD2(unsigned char Par1,unsigned char Par2,unsigned char Comd)
{
WriteDATA(Par1);
WriteDATA(Par2);
WriteCMD0(Comd);
}
/*
六,定义API访问接口
*/
void LCD_Reset(void)
{
GPIO_SetBits(GPIOC, GPIO_Pin_4);//置1 LCDRST = 1;
OSTimeDlyHMSM(0, 0, 0, 10);
GPIO_ResetBits(GPIOC, GPIO_Pin_4);//清0 LCDRST = 0;
OSTimeDlyHMSM(0, 0, 0, 50);
GPIO_SetBits(GPIOC, GPIO_Pin_4);//置1 LCDRST = 1;
OSTimeDlyHMSM(0, 0, 0, 50);
}

void STM32_T6963C_Init(void)
{
unsigned int i;
/* Configure the LCD Control pins --------------------------------------------*/
LCD_CtrlLinesConfig();

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

/* initialize sequence -------------------------------*/
LCD_Reset();

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top