目录
一、标准库配置
1、FSMC_NORSRAMInitTypeDef
2、FSMC_NORSRAMTimingInitTypeDef
3、GPIO
4、写命令
5、写数据
6、读数据
7、屏幕显示像素点
8、ILI934
二、用户侧
一、标准库配置
1、FSMC_NORSRAMInitTypeDef
FSMC_NORSRAMInitTypeDef在stm32f10x_fsmc.h中,比较重要的有FSMC_Bank本成员用于选择 FSMC 映射的存储区域,FSMC_MemoryType本成员用于设置要控制的存储器类型,FSMC_MemoryDataWidth本成员用于设置要控制的存储器的数据宽度,FSMC_WriteOperation这个成员用于设置是否写使能,FSMC_ExtendedMode本成员用于设置是否使用扩展模式。
typedef struct
{
uint32_t FSMC_Bank; /*!< Specifies the NOR/SRAM memory bank that will be used.
This parameter can be a value of @ref FSMC_NORSRAM_Bank */
uint32_t FSMC_DataAddressMux; /*!< Specifies whether the address and data values are
multiplexed on the databus or not.
This parameter can be a value of @ref FSMC_Data_Address_Bus_Multiplexing */
uint32_t FSMC_MemoryType; /*!< Specifies the type of external memory attached to
the corresponding memory bank.
This parameter can be a value of @ref FSMC_Memory_Type */
uint32_t FSMC_MemoryDataWidth; /*!< Specifies the external memory device width.
This parameter can be a value of @ref FSMC_Data_Width */
uint32_t FSMC_BurstAccessMode; /*!< Enables or disables the burst access mode for Flash memory,
valid only with synchronous burst Flash memories.
This parameter can be a value of @ref FSMC_Burst_Access_Mode */
uint32_t FSMC_AsynchronousWait; /*!< Enables or disables wait signal during asynchronous transfers,
valid only with asynchronous Flash memories.
This parameter can be a value of @ref FSMC_AsynchronousWait */
uint32_t FSMC_WaitSignalPolarity; /*!< Specifies the wait signal polarity, valid only when accessing
the Flash memory in burst mode.
This parameter can be a value of @ref FSMC_Wait_Signal_Polarity */
uint32_t FSMC_WrapMode; /*!< Enables or disables the Wrapped burst access mode for Flash
memory, valid only when accessing Flash memories in burst mode.
This parameter can be a value of @ref FSMC_Wrap_Mode */
uint32_t FSMC_WaitSignalActive; /*!< Specifies if the wait signal is asserted by the memory one
clock cycle before the wait state or during the wait state,
valid only when accessing memories in burst mode.
This parameter can be a value of @ref FSMC_Wait_Timing */
uint32_t FSMC_WriteOperation; /*!< Enables or disables the write operation in the selected bank by the FSMC.
This parameter can be a value of @ref FSMC_Write_Operation */
uint32_t FSMC_WaitSignal; /*!< Enables or disables the wait-state insertion via wait
signal, valid for Flash memory access in burst mode.
This parameter can be a value of @ref FSMC_Wait_Signal */
uint32_t FSMC_ExtendedMode; /*!< Enables or disables the extended mode.
This parameter can be a value of @ref FSMC_Extended_Mode */
uint32_t FSMC_WriteBurst; /*!< Enables or disables the write burst operation.
This parameter can be a value of @ref FSMC_Write_Burst */
FSMC_NORSRAMTimingInitTypeDef* FSMC_ReadWriteTimingStruct; /*!< Timing Parameters for write and read access if the ExtendedMode is not used*/
FSMC_NORSRAMTimingInitTypeDef* FSMC_WriteTimingStruct; /*!< Timing Parameters for write access if the ExtendedMode is used*/
}FSMC_NORSRAMInitTypeDef;
2、FSMC_NORSRAMTimingInitTypeDef
FSMC_AddressSetupTime本成员设置地址建立时间,FSMC_DataSetupTime本成员设置数据建立时间,FSMC_AccessMode本成员设置存储器访问模式。
3、GPIO
与FSMC有关的全部复用推挽输出,如果仅控制背光、系统复位则选择推挽输出即可。
4、写命令
可以看到和SRAM一样,直接对地址操作了。
__inline void ILI9341_Write_Cmd ( uint16_t usCmd )
{
* ( __IO uint16_t * ) ( FSMC_Addr_ILI9341_CMD ) = usCmd;
}
5、写数据
可以看到也是对地址操作,但是命令和数据的地址不同。
__inline void ILI9341_Write_Data ( uint16_t usData )
{
* ( __IO uint16_t * ) ( FSMC_Addr_ILI9341_DATA ) = usData;
}
//FSMC_Bank1_NORSRAM用于LCD命令操作的地址
#define FSMC_Addr_ILI9341_CMD ( ( uint32_t ) 0x6C000000 )
//FSMC_Bank1_NORSRAM用于LCD数据操作的地址
#define FSMC_Addr_ILI9341_DATA ( ( uint32_t ) 0x6D000000 )
6、读数据
__inline uint16_t ILI9341_Read_Data ( void )
{
return ( * ( __IO uint16_t * ) ( FSMC_Addr_ILI9341_DATA ) );
}
7、屏幕显示像素点
这个是所有显示的核心,因为屏幕以像素点为单位,如果显示点,连接就是线,多个点就是字符。
void ILI9341_SetPointPixel ( uint16_t usX, uint16_t usY )
{
if ( ( usX < LCD_X_LENGTH ) && ( usY < LCD_Y_LENGTH ) )
{
ILI9341_SetCursor ( usX, usY );
ILI9341_FillColor ( 1, CurrentTextColor );
}
}
static void ILI9341_SetCursor ( uint16_t usX, uint16_t usY )
{
ILI9341_OpenWindow ( usX, usY, 1, 1 );
}
void ILI9341_OpenWindow ( uint16_t usX, uint16_t usY, uint16_t usWidth, uint16_t usHeight )
{
ILI9341_Write_Cmd ( CMD_SetCoordinateX ); /* 设置X坐标 */
ILI9341_Write_Data ( usX >> 8 ); /* 先高8位,然后低8位 */
ILI9341_Write_Data ( usX & 0xff ); /* 设置起始点和结束点*/
ILI9341_Write_Data ( ( usX + usWidth - 1 ) >> 8 );
ILI9341_Write_Data ( ( usX + usWidth - 1 ) & 0xff );
ILI9341_Write_Cmd ( CMD_SetCoordinateY ); /* 设置Y坐标*/
ILI9341_Write_Data ( usY >> 8 );
ILI9341_Write_Data ( usY & 0xff );
ILI9341_Write_Data ( ( usY + usHeight - 1 ) >> 8 );
ILI9341_Write_Data ( ( usY + usHeight - 1) & 0xff );
}
static __inline void ILI9341_FillColor ( uint32_t ulAmout_Point, uint16_t usColor )
{
uint32_t i = 0;
/* memory write */
ILI9341_Write_Cmd ( CMD_SetPixel );
for ( i = 0; i < ulAmout_Point; i ++ )
ILI9341_Write_Data ( usColor );
}
8、ILI934
#define WHITE 0xFFFF //白色
#define BLACK 0x0000 //黑色
#define GREY 0xF7DE //灰色
#define BLUE 0x001F //蓝色
#define BLUE2 0x051F //浅蓝色
#define RED 0xF800 //红色
#define MAGENTA 0xF81F //红紫色,洋红色
#define GREEN 0x07E0 //绿色
#define CYAN 0x7FFF //蓝绿色,青色
#define YELLOW 0xFFE0 //黄色
#define BRED 0xF81F
#define GRED 0xFFE0
#define GBLUE 0x07FF
/******************************* 定义 ILI934 常用命令 ********************************/
#define CMD_SetCoordinateX 0x2A //设置X坐标
#define CMD_SetCoordinateY 0x2B //设置Y坐标
#define CMD_SetPixel 0x2C //填充像素
/* 定义 LCD 驱动芯片 ID */
#define LCDID_UNKNOWN 0
#define LCDID_ILI9341 0x9341
#define LCDID_ST7789V 0x8552
二、用户侧
可以看到,不再和RGB屏幕打交道,而是直接和IL1934驱动IC进行交流,其他IIC、SPI驱动屏幕都是一样的道理,屏幕本身自带了驱动芯片,用户只需要和驱动芯片沟通即可。