• 大小: 8KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: 其他
  • 标签: STM32  FSMC  ILI9341  

资源简介

使用STM32的FSMC驱动的ILI9341屏幕,能够实现画点、画线、画矩形、画圆、填充矩形、ASCII显示、汉字显示、图片显示等功能

资源截图

代码片段和文件信息

#include 
#include “lcddriver.h“

#if !USE_uC_GUI
#include 
#include “ASCII24X12.h“
#include “HZ24X24.h“
#endif

/* select BANK1-NORSRAM1 to connect LCD the address range: 0x60000000~0x63FFFFFF 
 * FSMC_A16 connect to LCD DC(data/register) pin
 * data bandth: 16bits => FSMC[24:0]== HADDR[25:1]
 * register base address: 0x60000000
 * RAM base address: 0x60020000 = 0x60000000 + 2^16 * 2
 * the address need to calculate again when select different address pin
*/
#define Bank1_LCD_DATA  ((uint32_t)0x60020000) /* display data address */
#define Bank1_LCD_REG ((uint32_t)0x60000000) /* display register address */

/* LCD write data and register */
#define LCD_WR_DATA(value) ((*(__IO uint16_t*)(Bank1_LCD_DATA)) = ((uint16_t)(value)))
#define LCD_WR_REG(index) ((*(__IO uint16_t*)(Bank1_LCD_REG)) = ((uint16_t)index))

#if !USE_uC_GUI
#define ASCII_CHARACTER 0
#define HZ_CHARACTER 1
#endif

static void delayms(uint32_t n_ms);
static void LCD_GPIO_Config(void);
static void LCD_FSMC_Config(void);
static void ILI9341_Init(void);
static void LCD_OpenWindow(uint16_t x uint16_t y uint16_t width uint16_t height);
#if !USE_uC_GUI
static uint16_t GetFontWidth(uint8_t font uint8_t type);
static uint16_t GetFontHeight(uint8_t font uint8_t type);
#endif

void delayms(uint32_t n_ms)
{
uint32_t i = 0 j = 0;
for(i = n_ms; i > 0; --i)
{
for(j = 7900; j > 0; --j)
{
}
}
}

/*
*FuncName: LCD_GPIO_Config
*Parameter: void
*Function: configure GPIO used by LCD
*/
static void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

/* enable FSMC clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC ENABLE);

/* enable GPIOD/GPIOE clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE ENABLE);

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

/* LCD backlight control pin -- PB0(TIM3-CH3) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_Init(GPIOB &GPIO_InitStructure);

/* LCD reset control pin -- PE1(FSMC_NBL1) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_Init(GPIOE &GPIO_InitStructure);

/* FSMC data pins FSMC-D0~D15: 
 * PD14-PD15-PD0 -PD1 -PE7 -PE8 -PE9 -PE10
 * PE11-PE12-PE13-PE14-PE15-PD8 -PD9 -PD10
*/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_AF_PP;
    
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | 
  GPIO_Pin_1 | 
  GPIO_Pin_8 | 
  GPIO_Pin_9 | 
                                  GPIO_Pin_10 | 
  GPIO_Pin_14 | 
  GPIO_Pin_15;
    GPIO_Init(GPIOD &GPIO_InitStructure);
    
    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_

评论

共有 条评论