新手上路
- 积分
- 39
- 金钱
- 39
- 注册时间
- 2015-5-4
- 在线时间
- 0 小时
|

楼主 |
发表于 2015-5-4 12:12:52
|
显示全部楼层
自己改了一个,帮忙看下哪里有问题
#include "stm32f10x_lib.h"
#include "lcd_fsmc.h"
#include "HzLib.h"
#define LCD_Data ((u32)0x60080000) //disp Data ADDR
#define LCD_Reg ((u32)0x60000000) //disp Reg ADDR
////////////////////////////////////////////////////////////////////////////////////////
/*******************************************************************************
* Function Name: LCD_CtrlLinesConfig 引脚IO配置
* Description : Configures LCD Control lines (FSMC  ins) in alternate function
  ush-Pull mode.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable FSMC, GPIOD, GPIOE, GPIOG and AFIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO, ENABLE);
/* Set  D.00(D2),  D.01(D3),  D.04(NOE),  D.05(NWE),  D.14(D0),  D.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_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  E.00(RST),PE.07(D4),  E.08(D5), PE.09(D6), PE.10(D7)
as alternate function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_7 |GPIO_Pin_8 |
GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* Set PD.07(NE1) as alternate function push pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name: 背光控制脚PE1_LCD_BackLightCtrl
* Description :
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_LightPin(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_SetBits(GPIOE, GPIO_Pin_1);
}
/*******************************************************************************
* Function Name: LCD_FSMCConfig FSMC配置
* 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_NORSRAM1 configuration */
p.FSMC_AddressSetupTime = 2;
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 = 8bit
- 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_8b;
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);
/* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}
/*******************************************************************************
* Function Name: LCD_RST
* Description : Reset
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void LCD_RST(void)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_0);
LCD_Delay(0xAF0000);
GPIO_SetBits(GPIOE, GPIO_Pin_0 );
LCD_Delay(0xAF0000);
}
void LCD_X_Init(void)
{
/*背光引脚初始化*/
LCD_LightPin();
/* Configure the LCD Control pins --------------------------------------------*/
LCD_CtrlLinesConfig();
/* Configure the FSMC Parallel interface -------------------------------------*/
LCD_FSMCConfig();
}
/*******************************************************************************
* Function Name: LCD_Write
* Description : Writes to the selected LCD register.
* Input : - DH,DL.
* Output : None
* Return : None
*******************************************************************************/
void LCD_Write(u8 index)
{
*(u8 *) (LCD_Reg)= index;
}
/*******************************************************************************
* Function Name: LCD_Read
* Description : Reads the selected LCD Register.
* Input : None
* Output : None
* Return : LCD Register Value.
*******************************************************************************/
u16 LCD_ReadData(u16 val)
{
u16 a;
LCD_Write (0x2e);
a=*(u8 *) (LCD_Data);
a<<=8;
a|=*(u8 *) (LCD_Data);
return a;
}
void LCD_WriteData(u8 val)
{
*(u8 *) (LCD_Data)= val;
}
/****************************************************************************
* 名 称:void LCD_Initializtion()
* 功 能:初始化 LCD 控制器
* 入口参数:无
* 出口参数:无
* 说 明:
* 调用方法:LCD_Initializtion();
****************************************************************************/
void LCD_Initializtion()
{
LCD_RST();
LCD_X_Init();
//LCD_Write(0,0x3f); //设置开显示命令
//LCD_Write(0,0xc0); //设置起始位置
LCD_Write(0x3f);
}
/****************************************************************************
* 名 称:void LCD_BackLight(u8 status)
* 功 能:开、关液晶背光
* 入口参数:status 1:背光开 0:背光关
* 出口参数:无
* 说 明:
* 调用方法:LCD_BackLight(1);
****************************************************************************/
void LCD_BackLight(u8 status)
{
if ( status >= 1 )
{
GPIO_SetBits(GPIOE, GPIO_Pin_1);
}
else
{
GPIO_ResetBits(GPIOE, GPIO_Pin_1);
}
}
/****************************************************************************
* 名 称:void LCD_Delay(vu32 nCount)
* 功 能:延时
* 入口参数:nCount 延时值
* 出口参数:无
* 说 明:
* 调用方法:LCD_Delay(10000);
****************************************************************************/
void LCD_Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
/****************************************************************************
* 名 称:void SelectScreen(u8 Screen)
* 功 能:选择屏幕
* 入口参数:Screen
* 出口参数:无
* 说 明:
* 调用方法:SelectScreen(0);
****************************************************************************/
void SelectScreen(u8 Screen)
{
switch(Screen)
{
case 0:
GPIO_ResetBits(GPIOE, GPIO_Pin_2); //CS1=0
GPIO_SetBits(GPIOE, GPIO_Pin_6 | GPIO_Pin_5); //CS2=1,CS3=1
break;
case 1:
GPIO_ResetBits(GPIOE, GPIO_Pin_6); //CS2=0
GPIO_SetBits(GPIOE, GPIO_Pin_2 | GPIO_Pin_5); //CS1=1,CS3=1
break;
case 2:
GPIO_ResetBits(GPIOE, GPIO_Pin_5); //CS3=0
GPIO_SetBits(GPIOE, GPIO_Pin_2 | GPIO_Pin_6); //CS1=1,CS2=1
break;
}
}
/****************************************************************************
* 名 称:void SetAddress(u8 Address)
* 功 能:设置页地址,列地址
* 入口参数:
* 出口参数:无
* 说 明:
****************************************************************************/
void SetAddress(u8 Address)
{
LCD_Write(Address);
}
void LCD_SetPoint(u16 color,u16 x1,u16 y1)
// 起始列x1,起始行y1,宽w,高h
{
u16 x2,y2;
u8 color1,color2;
color1=(color>>8)&0x00ff;
color2=color&0x00ff;
x2=x1;
y2=y1;
LCD_Write(0x2a);
LCD_WriteData((x1>>8)&0x00ff); //列起始高8位
LCD_WriteData(x1&0x00ff); //列起始低8位
LCD_WriteData((x2>>8)&0x00ff); //列结束高8位
LCD_WriteData(x2&0x00ff); //列结束低8位
LCD_Write(0x2b);
LCD_WriteData((y1>>8)&0x00ff); //行起始高8位
LCD_WriteData(y1&0x00ff); //行起始低8位
LCD_WriteData((y2>>8)&0x00ff); //行结束高8位
LCD_WriteData(y2&0x00ff); //行结束低8位
LCD_Write(0x2c);//开始写数据
LCD_WriteData(color1);
LCD_WriteData(color2);
} |
|