STM32 LCD英文字符显示学习笔记

开发板:野火指南者(STM32F103VE)

STM32库版本:STM32F10x_StdPeriph_Lib_V3.5.0

IDE:KEIL5(代码编写很不方便,只在编译的时候用到)

代码编写工具:Source Insight 4.0(跟读代码、编写代码的最佳工具)

硬件原理图:

STM32 LCD英文字符显示学习笔记

 

 

1. 新建user_fsmc_lcd.h、user_fsmc_lcd.c、main.c 3个文件,并从STM32官方库的例子中将stm32f10x_it.c、stm32f10x_it.h、stm32f10x_conf.h拷贝到自己的工程目录下。

 

2. 在user_fsmc_lcd.h中添加如下代码

STM32 LCD英文字符显示学习笔记
 1 #ifndef __USER_FSMC_LCD_H
 2 #define __USER_FSMC_LCD_H
 3 
 4 #include "stm32f10x.h"
 5 
 6 #define LCD_CMD        ((uint32_t)0x60000000)
 7 #define LCD_DATA    ((uint32_t)0x60020000)
 8 
 9 #define TEXTCOLOR    0xF800
10 #define BACKGROUND    0x0000
11 
12 
13 
14 void time_delay(uint32_t t);    //时间延时函数
15 void user_lcd_display_string(char * pchar);        //显示英文字符串函数
16 void user_lcd_fill_color(uint32_t fill_lcd, uint16_t color);        //整个屏幕填充的颜色函数
17 void user_lcd_clear(void);        //清屏函数,将屏幕配置为黑色
18 void user_lcd_display_char(uint16_t x, uint16_t y, char ch);        //单个字符显示函数
19 void user_View_Window(uint16_t lcd_x, uint16_t lcd_y, uint16_t lcd_width, uint16_t lcd_height);        //初始化整个屏幕
20 void user_LCD_Init(void);        //LCD初始化函数
21 void user_LCD_Scan(void);        //LCD扫描函数,这里配置为模式六,即X--240, Y--320,X从左到右,Y从上到下扫描
22 void user_LCD_DATA(uint16_t data);        //LCD数据写入函数
23 void user_LCD_CMD(uint16_t cmd);        //LCD命令操作函数
24 void user_LCD_REG_Config(void);            //LCD对应的IC控制寄存器配置函数,这个配置与LCD上控制芯片相关,如何配置应该是向供应商获取的
25 void user_FSMC_Config(void);        //FSMC配置函数
26 void user_LCD_BL(FunctionalState Status);        //LCD背光信号控制函数
27 void user_LCD_RST(FunctionalState Status);        //LCD复位信号控制函数
28 void user_LCD_GPIO_Config(void);        //LCD相关GPIO PIN初始化函数
29 
30 
31 
32 #endif
View Code

 

3. 在user_fsmc_lcd.c中添加如下代码

STM32 LCD英文字符显示学习笔记
  1 #include "user_fsmc_lcd.h"
  2 
  3 
  4 
  5 
  6 //存放英文字模的数组,宽度8bit像素,高度16bit像素
  7 const uint8_t ASCII8x16_Table [ ] = {
  8 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  9 0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x08,0x00,0x08,0x18,0x00,0x00,0x00,
 10 0x00,0x00,0x00,0x34,0x24,0x24,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 11 0x00,0x00,0x00,0x00,0x16,0x24,0x7f,0x24,0x24,0x24,0x7e,0x24,0x24,0x00,0x00,0x00,
 12 0x00,0x00,0x00,0x08,0x3e,0x68,0x48,0x68,0x1c,0x16,0x12,0x12,0x7c,0x10,0x10,0x00,
 13 0x00,0x00,0x00,0x61,0xd2,0x96,0x74,0x08,0x10,0x16,0x29,0x49,0xc6,0x00,0x00,0x00,
 14 0x00,0x00,0x00,0x00,0x3c,0x64,0x64,0x38,0x72,0x4a,0xce,0x46,0x7f,0x00,0x00,0x00,
 15 0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 16 0x00,0x00,0x00,0x04,0x08,0x18,0x10,0x30,0x30,0x30,0x30,0x10,0x10,0x18,0x0c,0x04,
 17 0x00,0x00,0x00,0x20,0x10,0x08,0x08,0x0c,0x04,0x04,0x04,0x0c,0x08,0x18,0x10,0x20,
 18 0x00,0x00,0x00,0x08,0x0a,0x34,0x1c,0x6a,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 19 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x7f,0x18,0x18,0x18,0x00,0x00,0x00,
 20 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x08,0x30,0x00,
 21 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,
 22 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
 23 0x00,0x00,0x00,0x02,0x06,0x04,0x0c,0x08,0x08,0x10,0x10,0x20,0x20,0x40,0x00,0x00,
 24 0x00,0x00,0x00,0x00,0x3c,0x66,0x42,0x47,0x5b,0x73,0x42,0x66,0x3c,0x00,0x00,0x00,
 25 0x00,0x00,0x00,0x00,0x18,0x78,0x48,0x08,0x08,0x08,0x08,0x08,0x7e,0x00,0x00,0x00,
 26 0x00,0x00,0x00,0x00,0x3c,0x46,0x06,0x06,0x04,0x08,0x10,0x20,0x7e,0x00,0x00,0x00,
 27 0x00,0x00,0x00,0x00,0x7c,0x06,0x06,0x04,0x3c,0x02,0x02,0x06,0x7c,0x00,0x00,0x00,
 28 0x00,0x00,0x00,0x00,0x0c,0x1c,0x14,0x24,0x64,0x44,0xff,0x04,0x04,0x00,0x00,0x00,
 29 0x00,0x00,0x00,0x00,0x7e,0x60,0x60,0x60,0x7e,0x02,0x02,0x06,0x7c,0x00,0x00,0x00,
 30 0x00,0x00,0x00,0x00,0x1e,0x30,0x60,0x48,0x76,0x42,0x42,0x62,0x3c,0x00,0x00,0x00,
 31 0x00,0x00,0x00,0x00,0x7e,0x02,0x06,0x04,0x0c,0x08,0x18,0x10,0x30,0x00,0x00,0x00,
 32 0x00,0x00,0x00,0x00,0x3c,0x62,0x42,0x36,0x1c,0x66,0x42,0x42,0x3c,0x00,0x00,0x00,
 33 0x00,0x00,0x00,0x00,0x3c,0x66,0x42,0x42,0x66,0x1a,0x02,0x04,0x78,0x00,0x00,0x00,
 34 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,
 35 0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x08,0x30,0x00,
 36 0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x18,0x30,0x60,0x10,0x0c,0x06,0x00,0x00,0x00,
 37 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,
 38 0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x18,0x04,0x06,0x0c,0x10,0x20,0x00,0x00,0x00,
 39 0x00,0x00,0x00,0x30,0x1c,0x06,0x06,0x06,0x18,0x10,0x00,0x10,0x10,0x00,0x00,0x00,
 40 0x00,0x00,0x00,0x1c,0x22,0x41,0x41,0xdd,0xb5,0xa5,0xa5,0xaf,0x94,0xc0,0x40,0x3c,
 41 0x00,0x00,0x00,0x00,0x18,0x1c,0x34,0x24,0x26,0x62,0x7e,0x43,0xc1,0x00,0x00,0x00,
 42 0x00,0x00,0x00,0x00,0x7c,0x46,0x42,0x46,0x7c,0x42,0x42,0x42,0x7c,0x00,0x00,0x00,
 43 0x00,0x00,0x00,0x00,0x1e,0x20,0x40,0x40,0x40,0x40,0x40,0x60,0x3e,0x00,0x00,0x00,
 44 0x00,0x00,0x00,0x00,0x7c,0x46,0x42,0x43,0x43,0x43,0x42,0x46,0x78,0x00,0x00,0x00,
 45 0x00,0x00,0x00,0x00,0x7e,0x60,0x60,0x60,0x7e,0x60,0x60,0x60,0x7e,0x00,0x00,0x00,
 46 0x00,0x00,0x00,0x00,0x7e,0x60,0x60,0x60,0x7e,0x60,0x60,0x60,0x60,0x00,0x00,0x00,
 47 0x00,0x00,0x00,0x00,0x1e,0x60,0x40,0x40,0xce,0x42,0x42,0x62,0x3e,0x00,0x00,0x00,
 48 0x00,0x00,0x00,0x00,0x42,0x42,0x42,0x42,0x7e,0x42,0x42,0x42,0x42,0x00,0x00,0x00,
 49 0x00,0x00,0x00,0x00,0x7e,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7e,0x00,0x00,0x00,
 50 0x00,0x00,0x00,0x00,0x7c,0x04,0x04,0x04,0x04,0x04,0x04,0x44,0x78,0x00,0x00,0x00,
 51 0x00,0x00,0x00,0x00,0x42,0x44,0x48,0x50,0x70,0x58,0x4c,0x44,0x42,0x00,0x00,0x00,
 52 0x00,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3e,0x00,0x00,0x00,
 53 0x00,0x00,0x00,0x00,0x62,0x66,0x67,0x5f,0x5b,0x5b,0xc1,0xc1,0xc1,0x00,0x00,0x00,
 54 0x00,0x00,0x00,0x00,0x62,0x62,0x72,0x52,0x5a,0x4a,0x4e,0x46,0x46,0x00,0x00,0x00,
 55 0x00,0x00,0x00,0x00,0x3c,0x62,0x43,0xc3,0xc3,0xc3,0x43,0x62,0x3c,0x00,0x00,0x00,
 56 0x00,0x00,0x00,0x00,0x7c,0x46,0x42,0x42,0x46,0x78,0x40,0x40,0x40,0x00,0x00,0x00,
 57 0x00,0x00,0x00,0x00,0x3c,0x62,0x43,0xc3,0xc3,0xc3,0x43,0x62,0x3c,0x18,0x0f,0x00,
 58 0x00,0x00,0x00,0x00,0x7c,0x66,0x62,0x66,0x7c,0x6c,0x64,0x66,0x62,0x00,0x00,0x00,
 59 0x00,0x00,0x00,0x00,0x3e,0x60,0x40,0x60,0x1c,0x06,0x02,0x02,0x7c,0x00,0x00,0x00,
 60 0x00,0x00,0x00,0x00,0x7f,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,
 61 0x00,0x00,0x00,0x00,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x62,0x3c,0x00,0x00,0x00,
 62 0x00,0x00,0x00,0x00,0xc1,0x43,0x42,0x62,0x26,0x24,0x34,0x1c,0x18,0x00,0x00,0x00,
 63 0x00,0x00,0x00,0x00,0xc1,0xc1,0x41,0x49,0x5b,0x5b,0x76,0x66,0x66,0x00,0x00,0x00,
 64 0x00,0x00,0x00,0x00,0x43,0x66,0x34,0x18,0x18,0x1c,0x24,0x66,0xc3,0x00,0x00,0x00,
 65 0x00,0x00,0x00,0x00,0xc1,0x42,0x66,0x34,0x1c,0x18,0x18,0x18,0x18,0x00,0x00,0x00,
 66 0x00,0x00,0x00,0x00,0x7e,0x02,0x04,0x0c,0x18,0x10,0x20,0x60,0x7e,0x00,0x00,0x00,
 67 0x00,0x00,0x00,0x1c,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1c,
 68 0x00,0x00,0x00,0x40,0x20,0x20,0x10,0x10,0x08,0x08,0x0c,0x04,0x06,0x02,0x00,0x00,
 69 0x00,0x00,0x00,0x3c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x3c,
 70 0x00,0x00,0x00,0x00,0x18,0x1c,0x24,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 71 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
 72 0x00,0x00,0x00,0x20,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 73 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x06,0x02,0x3e,0x42,0x46,0x7a,0x00,0x00,0x00,
 74 0x00,0x00,0x00,0x40,0x40,0x40,0x5c,0x62,0x42,0x42,0x42,0x42,0x7c,0x00,0x00,0x00,
 75 0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x20,0x60,0x40,0x60,0x20,0x3e,0x00,0x00,0x00,
 76 0x00,0x00,0x00,0x02,0x02,0x02,0x3e,0x62,0x42,0x42,0x42,0x66,0x3a,0x00,0x00,0x00,
 77 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x62,0x42,0x7e,0x40,0x60,0x3e,0x00,0x00,0x00,
 78 0x00,0x00,0x00,0x0f,0x18,0x10,0x10,0x7e,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x00,
 79 0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0x66,0x42,0x66,0x58,0x40,0x3e,0x43,0x42,0x3c,
 80 0x00,0x00,0x00,0x40,0x40,0x40,0x5c,0x62,0x42,0x42,0x42,0x42,0x42,0x00,0x00,0x00,
 81 0x00,0x00,0x00,0x18,0x18,0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x7e,0x00,0x00,0x00,
 82 0x00,0x00,0x00,0x04,0x0c,0x00,0x7c,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x0c,0x78,
 83 0x00,0x00,0x00,0x60,0x60,0x60,0x62,0x6c,0x78,0x70,0x68,0x64,0x62,0x00,0x00,0x00,
 84 0x00,0x00,0x00,0x78,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x7e,0x00,0x00,0x00,
 85 0x00,0x00,0x00,0x00,0x00,0x00,0x76,0x4b,0x4b,0x4b,0x4b,0x4b,0x4b,0x00,0x00,0x00,
 86 0x00,0x00,0x00,0x00,0x00,0x00,0x5c,0x62,0x42,0x42,0x42,0x42,0x42,0x00,0x00,0x00,
 87 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x62,0x42,0x43,0x42,0x62,0x3c,0x00,0x00,0x00,
 88 0x00,0x00,0x00,0x00,0x00,0x00,0x5c,0x62,0x42,0x42,0x42,0x42,0x7c,0x40,0x40,0x40,
 89 0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x62,0x42,0x42,0x42,0x66,0x3a,0x02,0x02,0x02,
 90 0x00,0x00,0x00,0x00,0x00,0x00,0x6e,0x72,0x63,0x60,0x60,0x60,0x60,0x00,0x00,0x00,
 91 0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x20,0x20,0x3c,0x06,0x02,0x7c,0x00,0x00,0x00,
 92 0x00,0x00,0x00,0x00,0x10,0x10,0xfe,0x10,0x10,0x10,0x10,0x10,0x1e,0x00,0x00,0x00,
 93 0x00,0x00,0x00,0x00,0x00,0x00,0x42,0x42,0x42,0x42,0x42,0x66,0x3a,0x00,0x00,0x00,
 94 0x00,0x00,0x00,0x00,0x00,0x00,0x43,0x42,0x66,0x24,0x34,0x18,0x18,0x00,0x00,0x00,
 95 0x00,0x00,0x00,0x00,0x00,0x00,0xc1,0xc1,0x5b,0x5a,0x5e,0x66,0x66,0x00,0x00,0x00,
 96 0x00,0x00,0x00,0x00,0x00,0x00,0x62,0x26,0x1c,0x18,0x1c,0x26,0x62,0x00,0x00,0x00,
 97 0x00,0x00,0x00,0x00,0x00,0x00,0x43,0x42,0x66,0x24,0x34,0x1c,0x18,0x18,0x30,0xe0,
 98 0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x06,0x0c,0x18,0x10,0x20,0x7e,0x00,0x00,0x00,
 99 0x00,0x00,0x00,0x0e,0x18,0x10,0x10,0x10,0x30,0x70,0x10,0x10,0x10,0x10,0x18,0x0e,
100 0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
101 0x00,0x00,0x00,0x30,0x18,0x08,0x08,0x08,0x0c,0x0e,0x08,0x08,0x08,0x08,0x18,0x30,
102 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x71,0x4b,0x06,0x00,0x00,0x00,0x00,0x00,
103 };  
104 
105 
106 
107 //LCD相关GPIO PIN初始化函数
108 void user_LCD_GPIO_Config(void)
109 {
110     GPIO_InitTypeDef LCD_GPIO_Config;
111 
112     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
113     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
114 
115     LCD_GPIO_Config.GPIO_Mode = GPIO_Mode_AF_PP;
116     LCD_GPIO_Config.GPIO_Speed = GPIO_Speed_50MHz;
117     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_14;
118     GPIO_Init(GPIOD, &LCD_GPIO_Config);
119 
120     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_15;
121     GPIO_Init(GPIOD, &LCD_GPIO_Config);
122 
123 
124     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_0;
125     GPIO_Init(GPIOD, &LCD_GPIO_Config);
126 
127     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_1;
128     GPIO_Init(GPIOD, &LCD_GPIO_Config);
129 
130 
131     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_7;
132     GPIO_Init(GPIOE, &LCD_GPIO_Config);
133 
134 
135     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_8;
136     GPIO_Init(GPIOE, &LCD_GPIO_Config);
137 
138     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_9;
139     GPIO_Init(GPIOE, &LCD_GPIO_Config);
140 
141 
142     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_10;
143     GPIO_Init(GPIOE, &LCD_GPIO_Config);
144 
145     
146     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_11;
147     GPIO_Init(GPIOE, &LCD_GPIO_Config);
148 
149 
150     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_12;
151     GPIO_Init(GPIOE, &LCD_GPIO_Config);
152 
153     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_13;
154     GPIO_Init(GPIOE, &LCD_GPIO_Config);
155 
156 
157     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_14;
158     GPIO_Init(GPIOE, &LCD_GPIO_Config);
159 
160     
161     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_15;
162     GPIO_Init(GPIOE, &LCD_GPIO_Config);
163 
164     
165     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_8;
166     GPIO_Init(GPIOD, &LCD_GPIO_Config);
167 
168 
169     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_9;
170     GPIO_Init(GPIOD, &LCD_GPIO_Config);
171 
172     
173     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_10;
174     GPIO_Init(GPIOD, &LCD_GPIO_Config);
175 
176 
177 
178     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_7;
179     GPIO_Init(GPIOD, &LCD_GPIO_Config);
180 
181     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_4;
182     GPIO_Init(GPIOD, &LCD_GPIO_Config);
183 
184     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_5;
185     GPIO_Init(GPIOD, &LCD_GPIO_Config);
186 
187     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_11;
188     GPIO_Init(GPIOD, &LCD_GPIO_Config);
189 
190 
191     LCD_GPIO_Config.GPIO_Mode = GPIO_Mode_Out_PP;
192     LCD_GPIO_Config.GPIO_Speed = GPIO_Speed_50MHz;
193     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_1;
194     GPIO_Init(GPIOE, &LCD_GPIO_Config);
195 
196     LCD_GPIO_Config.GPIO_Pin = GPIO_Pin_12;
197     GPIO_Init(GPIOD, &LCD_GPIO_Config);
198 
199     user_LCD_RST(ENABLE);
200     user_LCD_RST(DISABLE);
201 
202     user_LCD_BL(ENABLE);
203 
204     
205 }
206 
207 //LCD复位信号控制函数
208 void user_LCD_RST(FunctionalState Status)
209 {
210 
211     if(Status == DISABLE)
212     {
213         GPIOE->BSRR = GPIO_Pin_1;
214     }
215 
216     else
217     {
218         GPIOE->BRR = GPIO_Pin_1;
219     }
220 
221 
222 }
223 
224 //LCD背光信号控制函数
225 void user_LCD_BL(FunctionalState Status)
226 {
227     if(Status == DISABLE)
228     {
229         GPIOD->BSRR = GPIO_Pin_12;        
230     }
231 
232     else
233     {
234         GPIOD->BRR = GPIO_Pin_12;
235     }
236 
237 }
238 
239 //FSMC配置函数
240 void user_FSMC_Config(void)
241 {
242     FSMC_NORSRAMTimingInitTypeDef LCD_FSMC_Timing;
243     FSMC_NORSRAMInitTypeDef LCD_FSMC_Config;
244 
245     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
246 
247     LCD_FSMC_Timing.FSMC_AccessMode = FSMC_AccessMode_B;
248     LCD_FSMC_Timing.FSMC_AddressHoldTime = 0x00;
249     LCD_FSMC_Timing.FSMC_AddressSetupTime = 0x01;
250     LCD_FSMC_Timing.FSMC_BusTurnAroundDuration = 0x00;
251     LCD_FSMC_Timing.FSMC_CLKDivision = 0x00;
252     LCD_FSMC_Timing.FSMC_DataLatency = 0x00;
253     LCD_FSMC_Timing.FSMC_DataLatency = 0x00;
254     LCD_FSMC_Timing.FSMC_DataSetupTime = 0x04;
255 
256 
257     LCD_FSMC_Config.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
258     LCD_FSMC_Config.FSMC_Bank = FSMC_Bank1_NORSRAM1;
259     LCD_FSMC_Config.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
260     LCD_FSMC_Config.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
261     LCD_FSMC_Config.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
262     LCD_FSMC_Config.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
263     LCD_FSMC_Config.FSMC_MemoryType = FSMC_MemoryType_NOR;
264     LCD_FSMC_Config.FSMC_ReadWriteTimingStruct = &LCD_FSMC_Timing;
265     LCD_FSMC_Config.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
266     LCD_FSMC_Config.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
267     LCD_FSMC_Config.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
268     LCD_FSMC_Config.FSMC_WrapMode = FSMC_WrapMode_Disable;
269     LCD_FSMC_Config.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
270     LCD_FSMC_Config.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
271     LCD_FSMC_Config.FSMC_WriteTimingStruct = &LCD_FSMC_Timing;
272 
273     FSMC_NORSRAMInit(&LCD_FSMC_Config);
274     FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
275 
276 
277     
278 }
279 
280 //LCD对应的IC控制寄存器配置函数,这个配置与LCD上控制芯片相关,如何配置应该是向供应商获取的
281 void user_LCD_REG_Config(void)
282 {
283     /*    Power control B (CFh)  */
284     
285         user_LCD_CMD( 0xCF  );
286         user_LCD_DATA ( 0x00  );
287         user_LCD_DATA ( 0x81  );
288         user_LCD_DATA ( 0x30  );
289         
290         /*    Power on sequence control (EDh) */
291         
292         user_LCD_CMD ( 0xED );
293         user_LCD_DATA ( 0x64 );
294         user_LCD_DATA ( 0x03 );
295         user_LCD_DATA ( 0x12 );
296         user_LCD_DATA ( 0x81 );
297         
298         /*    Driver timing control A (E8h) */
299         
300         user_LCD_CMD ( 0xE8 );
301         user_LCD_DATA ( 0x85 );
302         user_LCD_DATA ( 0x10 );
303         user_LCD_DATA ( 0x78 );
304         
305         /*    Power control A (CBh) */
306     
307         user_LCD_CMD ( 0xCB );
308         user_LCD_DATA ( 0x39 );
309         user_LCD_DATA ( 0x2C );
310         user_LCD_DATA ( 0x00 );
311         user_LCD_DATA ( 0x34 );
312         user_LCD_DATA ( 0x02 );
313         
314         /* Pump ratio control (F7h) */
315         
316         user_LCD_CMD ( 0xF7 );
317         user_LCD_DATA ( 0x20 );
318         
319         /* Driver timing control B */
320     
321         user_LCD_CMD ( 0xEA );
322         user_LCD_DATA ( 0x00 );
323         user_LCD_DATA ( 0x00 );
324         
325         /* Frame Rate Control (In Normal Mode/Full Colors) (B1h) */
326     
327         user_LCD_CMD ( 0xB1 );
328         user_LCD_DATA ( 0x00 );
329         user_LCD_DATA ( 0x1B );
330         
331         /*    Display Function Control (B6h) */
332     
333         user_LCD_CMD ( 0xB6 );
334         user_LCD_DATA ( 0x0A );
335         user_LCD_DATA ( 0xA2 );
336         
337         /* Power Control 1 (C0h) */
338         
339         user_LCD_CMD ( 0xC0 );
340         user_LCD_DATA ( 0x35 );
341         
342         /* Power Control 2 (C1h) */
343 
344         user_LCD_CMD( 0xC1 );
345         user_LCD_DATA( 0x11 );
346         
347         /* VCOM Control 1 (C5h) */
348         user_LCD_CMD( 0xC5 );
349         user_LCD_DATA( 0x45 );
350         user_LCD_DATA( 0x45 );
351         
352         /*    VCOM Control 2 (C7h)  */
353         user_LCD_CMD ( 0xC7 );
354         user_LCD_DATA ( 0xA2 );
355         
356         /* Enable 3G (F2h) */
357         user_LCD_CMD ( 0xF2 );
358         user_LCD_DATA ( 0x00 );
359         
360         /* Gamma Set (26h) */
361         user_LCD_CMD ( 0x26 );
362         user_LCD_DATA ( 0x01 );
363 
364         
365         /* Positive Gamma Correction */
366         user_LCD_CMD ( 0xE0 ); //Set Gamma
367         user_LCD_DATA ( 0x0F );
368         user_LCD_DATA ( 0x26 );
369         user_LCD_DATA ( 0x24 );
370         user_LCD_DATA ( 0x0B );
371         user_LCD_DATA ( 0x0E );
372         user_LCD_DATA ( 0x09 );
373         user_LCD_DATA ( 0x54 );
374         user_LCD_DATA ( 0xA8 );
375         user_LCD_DATA ( 0x46 );
376         user_LCD_DATA ( 0x0C );
377         user_LCD_DATA ( 0x17 );
378         user_LCD_DATA ( 0x09 );
379         user_LCD_DATA ( 0x0F );
380         user_LCD_DATA ( 0x07 );
381         user_LCD_DATA ( 0x00 );
382         
383         /* Negative Gamma Correction (E1h) */
384         user_LCD_CMD ( 0XE1 ); //Set Gamma
385         user_LCD_DATA ( 0x00 );
386         user_LCD_DATA ( 0x19 );
387         user_LCD_DATA ( 0x1B );
388         user_LCD_DATA ( 0x04 );
389         user_LCD_DATA ( 0x10 );
390         user_LCD_DATA ( 0x07 );
391         user_LCD_DATA ( 0x2A );
392         user_LCD_DATA ( 0x47 );
393         user_LCD_DATA ( 0x39 );
394         user_LCD_DATA ( 0x03 );
395         user_LCD_DATA ( 0x06 );
396         user_LCD_DATA ( 0x06 );
397         user_LCD_DATA ( 0x30 );
398         user_LCD_DATA ( 0x38 );
399         user_LCD_DATA ( 0x0F );
400         
401         /* memory access control set */
402         
403         user_LCD_CMD ( 0x36 );     
404         user_LCD_DATA ( 0xC8 );    /*����    ���Ͻǵ� (���)�����½� (�յ�)ɨ�跽ʽ*/
405         
406         
407         /* column address control set */
408         user_LCD_CMD ( 0x2A ); 
409         user_LCD_DATA ( 0x00 );
410         user_LCD_DATA ( 0x00 );
411         user_LCD_DATA ( 0x00 );
412         user_LCD_DATA ( 0xEF );
413         
414         /* page address control set */
415         
416         user_LCD_CMD ( 0x2B ); 
417         user_LCD_DATA ( 0x00 );
418         user_LCD_DATA ( 0x00 );
419         user_LCD_DATA ( 0x01 );
420         user_LCD_DATA ( 0x3F );
421         
422         /*    Pixel Format Set (3Ah)    */
423     
424         user_LCD_CMD ( 0x3a ); 
425         user_LCD_DATA ( 0x55 );
426         
427         /* Sleep Out (11h)    */
428         user_LCD_CMD ( 0x11 ); 
429         //ILI9341_Delay ( 0xAFFf<<2 );
430     
431         
432         /* Display ON (29h) */
433         user_LCD_CMD ( 0x29 ); 
434 
435 
436 
437 }
438 
439 //LCD命令操作函数
440 void user_LCD_CMD(uint16_t cmd)
441 {
442      *(volatile uint16_t *) (LCD_CMD) = cmd;
443 
444 }
445 
446 //LCD数据写入函数
447 void user_LCD_DATA(uint16_t data)
448 {
449      *(volatile uint16_t *) (LCD_DATA) = data;
450 
451 }
452 
453 
454 
455 //LCD扫描函数,这里配置为模式六,即X--240, Y--320,X从左到右,Y从上到下扫描
456 void user_LCD_Scan(void)
457 {
458     
459     user_LCD_CMD(0x36);
460     //user_LCD_DATA(0x08 | (6 << 5));
461     user_LCD_CMD(0x68);
462 
463     user_LCD_CMD(0x2A);
464     user_LCD_DATA(0x00);
465     user_LCD_DATA(0x00);
466     user_LCD_DATA(((240 - 1) >> 8)&0xFF);  //因为从0开始,所以需要-1
467     user_LCD_DATA((240 - 1) &0xFF);
468 
469 
470 
471     user_LCD_CMD(0x2B);
472     user_LCD_DATA(0x00);
473     user_LCD_DATA(0x00);
474     user_LCD_DATA(((320 - 1) >> 8)&0xFF);
475     user_LCD_DATA((320 - 1) &0xFF);
476 
477 //    user_LCD_CMD(0x2C);        //这条语句后面没有跟填充的数据,去掉也不影响,这里应该是多余的
478 
479     
480 
481 }
482 
483 //LCD初始化函数
484 void user_LCD_Init(void)
485 {
486     user_LCD_GPIO_Config();
487     user_FSMC_Config();
488     
489     user_LCD_REG_Config();
490 
491     user_LCD_Scan();
492 }
493 
494 
495 //初始化整个屏幕
496 void user_View_Window(uint16_t lcd_x, uint16_t lcd_y, uint16_t lcd_width, uint16_t lcd_height)
497 {
498     
499     user_LCD_CMD(0x2A);    //行初始化命令
500     user_LCD_DATA(lcd_x >> 8);    //行起始点坐标,先给高8bit
501     user_LCD_DATA(lcd_x & 0xFF);
502     user_LCD_DATA((lcd_x + lcd_width - 1) >> 8 );    //行结束点坐标,先给高8bit
503     user_LCD_DATA((lcd_x + lcd_width -1) & 0xFF);
504 
505 
506     user_LCD_CMD(0x2B);    //列初始化命令
507     user_LCD_DATA(lcd_y >> 8);    //列起始点坐标,先给高8bit
508     user_LCD_DATA(lcd_y & 0xFF);
509     user_LCD_DATA((lcd_y + lcd_height -1 ) >> 8);    //列结束点坐标,先给高8bit
510     user_LCD_DATA((lcd_y + lcd_height -1 ) & 0xFF);
511 
512 }
513 
514 //单个字符显示函数
515 void user_lcd_display_char(uint16_t x, uint16_t y, char ch)
516 {
517     uint16_t a,b,c,d;
518 
519     uint8_t * pfont;
520 
521     a = ch - ' ';
522     b = 16;
523 
524     pfont = (uint8_t *)&ASCII8x16_Table[a * b];        //找到字模开始的位置,一个字的字模占16个字节
525 
526     user_View_Window(x, y, 8, 16);        //显示单个字模所需屏幕尺寸
527     
528     user_LCD_CMD(0x2C);        //填充像素命令
529 
530     for(c = 0; c < 16; c++)
531     {
532         for(d = 0; d < 8; d++)
533         {
534             if(*pfont & (0x80 >> d))
535             {
536                 user_LCD_DATA(TEXTCOLOR);
537             }
538             else
539             {
540                 user_LCD_DATA(BACKGROUND);
541             }
542 
543         }
544         pfont++;
545     }
546 
547 
548 
549 
550     
551 
552 }
553 
554 //清屏函数,将屏幕配置为黑色
555 void user_lcd_clear(void)
556 {
557     user_View_Window(0, 0, 240, 320);
558     user_lcd_fill_color(240*320, BACKGROUND);
559     
560 
561 }
562 
563 //整个屏幕填充的颜色函数
564 void user_lcd_fill_color(uint32_t fill_lcd, uint16_t color)
565 {
566     uint32_t i;
567 
568     user_LCD_CMD(0x2C);
569     for(i = 0; i < fill_lcd; i++)
570     {
571         user_LCD_DATA(color);
572 
573     }
574 
575 }
576 
577 //显示英文字符串函数
578 void user_lcd_display_string(char * pchar)
579 {
580     uint16_t x = 0,y = 0;
581 
582     while(*pchar != '\0')
583     {
584     
585         if((x + 8) > 240)
586         {
587             x = 0;
588             y += 16;
589         }
590         if((y + 16) > 320)
591         {
592             x = 0;
593             y = 0;
594         }
595 
596         user_lcd_display_char(x, y, *pchar);
597     
598         pchar++;
599         x +=8;
600 
601 
602     }
603 
604 
605 }
606 
607 //时间延时函数
608 void time_delay(volatile uint32_t t)
609 {
610     uint32_t time = t;
611     uint32_t i;
612     
613     for(i = 0; i < time; i++)
614     {
615 
616     }
617     
618 }
View Code

 

4. 在main.c中添加如下代码

STM32 LCD英文字符显示学习笔记
 1 #include "stm32f10x.h"
 2 #include "user_fsmc_lcd.h"
 3 
 4 
 5 int main(void)
 6 {
 7     user_LCD_Init();
 8 
 9     //user_LCD_Scan();
10 
11     while(1)
12     {
13         user_lcd_clear();
14 
15         user_lcd_display_string("it's test!");
16 
17         time_delay(0xFFFFFF);
18 
19     }
20 
21 }
View Code

 

总结:

1. void user_LCD_REG_Config(void)这个LCD 控制寄存器配置没有搞清楚是要怎么配置,有可能直接是向ILI9341芯片厂商索取的

2. 本实验有个很奇怪的现象就是,每次开关开发的电源时,LCD会白屏一段时间,其多次开关后,会一直白屏,原因暂未找到

 

实验源码:

链接:https://pan.baidu.com/s/1xo0L4i4MnQllpgtzd1n2Hg
提取码:whaa

 

上一篇:单片机LCD少量汉字显示


下一篇:51单片机定时器