Continue from the previous article "1. A simple nRF51822-driven Tianma 4-wire SPI-1.77-inch LCD color screen DEMO"
We found that the speed of driving the 1.77-inch spi with the nRF51822 with a 16MHz crystal oscillator was not up to the required level.
This section mainly uses 72MHz stm32 to try the screen refresh effect
The project structure is as follows:
Note: The most important part of the whole project is in USR, the others are required!
First is LCD.c:
1. Similar to the color screen driver made with nRF51822, the main difference here is the initialization of the pins~
2. At the same time, in order to make the screen refresh faster, the original loop is split into 8 lines of commands in lines 39 to 46~
3. The parts not written are the same as those based on nRF51, which are described in detail in the previous article
1 #include "LCD.h"
2
3
4 void LCD_GPIO_Init()
5 {
6 GPIO_InitTypeDef GPIO_InitStructure;
7
8 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
9
10 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4;
11 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
12 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //The port line flip speed is 50MHz
13 GPIO_Init(GPIOA, &GPIO_InitStructure);
14 }
15
16 ////////////////////////////////////////////////////////////////////////////////////
17 // Below is the SPI function and the write data and write command functions that implement the basic LCD communication
18 //With these two functions, complex LCD initialization and GUI can be realized
19 ////////////////////////////////////////////////////////////////////////////////////
20 /*
21 SPI Send Data
22 */
23 void SendDataSPI(unsigned char DatByte)
24 {
25 // unsigned char i;
26 // for(i = 0; i < 8; i++)
27 // {
28 // if((dat&0x80)!=0)SDA_SET;
29 // else SDA_CLEAR;
30
31 // dat <<= 1;
32
33 // SCL_CLEAR;
34 // SCL_SET;
35 // }
36 int bit;
37
38
39 bit = DatByte >> 7; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
40 bit = DatByte >> 6; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
41 bit = DatByte >> 5; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
42 bit = DatByte >> 4; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
43 bit = DatByte >> 3; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
44 bit = DatByte >> 2; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
45 bit = DatByte >> 1; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
46 bit = DatByte >> 0; LCD_SCK = 0; LCD_SDA = bit; LCD_SCK = 1;
47
48 }
49
50 /*
51 LCD WRITE COMMAND AND DATA
52 */
53 void WriteComm(unsigned int i)
54 { 59 }
60 void WriteData(unsigned int i)
61 { 66 }
67
68 /*
69 Write display data to the screen (screen display data requires 2 bytes)
70 */
71 void WriteDispData(unsigned char DataH, unsigned char DataL)
72 { 75 }
76 ////////////////////////////////////////////////////////////////////////////////////
77
78 /*
79 LCD initialization function
80 */
81 void LCD_Init(void)
82 {173 }
174
175 /*
176 LCD block write (modify a large amount of data, equivalent to erase)
177 */
178 void BlockWrite(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend)
179 {194 }
195
196
197 /*
198 LCD display color (color has been defined in the .h file)
199 */
200 void DispColor(unsigned int color)
201 {216 }
217
218
219 /*
220 Write a point (with color)
221 */
222 void WriteOneDot(unsigned int color)
223 {231 }
232
233 ////////////////////////////////////////////////////////////////////////////////////
234
235
236 /*
237 Draw a pixel
238 */
239 void PutPixel(unsigned int x, unsigned int y, unsigned int color)
240 {247 }
248
249 /*
250 Draw an area (named as line, but it can actually draw a surface)
251 */
252 void DrawLine(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend, unsigned int color)
253 {265 }
266
267 void Delay_ms(u16 time)
268 {
269 u16 i=0;
270 while(time--)
271 {
272 i=12000;
273 while(i--);
274 }
275 }
Similarly, in order to adapt to stm32, the macro definitions in the .H file have also been adjusted accordingly:
1. The high and low level macro definitions of the blue pins are modified according to the STM pin setting characteristics.
2. The yellow part is to enable the pins of stm32 to be directly assigned values like 51 MCU, such as: LCD_CS=0 or LCD_CS=1
3. The other parts remain unchanged, which shows the benefits of using macro definitions before~
1 #include "stm32f10x.h"
2
3
4
5 /*
6 pin high and low level macro definition
7 */
8 #define CS_SET GPIO_SetBits(GPIOA, GPIO_Pin_0)//GPIO_Mode_Out_PP
9 #define CS_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_0) //Normal push-pull output
10 #define RS_SET GPIO_SetBits(GPIOA, GPIO_Pin_1)
11 #define RS_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_1)
12 #define RET_SET GPIO_SetBits(GPIOA, GPIO_Pin_2)
13 #define RET_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_2)
14 #define SCL_SET GPIO_SetBits(GPIOA, GPIO_Pin_3)//GPIO_Mode_AF_PP
15 #define SCL_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_3) //Multiplexed push-pull output
16 #define SDA_SET GPIO_SetBits(GPIOA, GPIO_Pin_4)
17 #define SDA_CLEAR GPIO_ResetBits(GPIOA, GPIO_Pin_4)
18
19 #define BitBand(Addr, Bit) *((volatile int*)(((int)(Addr) & 0x60000000) + 0x02000000 + (int)(Addr) * 0x20 + (Bit) * 4))
20 #define LCD_CS BitBand(&GPIOA->ODR, 0)
21 #define LCD_RS BitBand(&GPIOA->ODR, 1)
22 #define LCD_SDA BitBand(&GPIOA->ODR, 4)
23 #define LCD_SCK BitBand(&GPIOA->ODR, 3)
24
25 /*
26 Macro definition wait function
27 */
28 #define DELAY_MS(n) Delay_ms(n)
29
30 //-------------------------------------------------------------
31 #define ROW 160 //Number of rows and columns displayed
32 #define COL 128
33
34
35 #define BLUE 0xF800 //Define color constant
36 #define GREEN 0x07E0
37 #define RED 0x001F
38 #define WHITE 0xFFFF
39 #define BLACK 0x0000
40 #define GRAY 0xEF5D //0x2410
41 #define GRAY75 0x39E7
42 #define GRAY50 0x7BEF
43 #define GRAY25 0xADB5
44
45 void Delay(u16 time);
46 void Delay_ms(u16 time);
47 void DrawLine(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend, unsigned int color);
48 void PutPixel(unsigned int x, unsigned int y, unsigned int color);
49 void WriteOneDot(unsigned int color);
50 void DispColor(unsigned int color);
51 void BlockWrite(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend);
52 void LCD_Init(void);
53 void WriteDispData(unsigned char DataH, unsigned char DataL);
54 void LCD_GPIO_Init(void);
In this way, you only need to call it in the main function:
1 #include "stm32f10x.h"
2 #include "LCD.h"
3
4
5 void RCC_Configuration(void);
6
7
8 int main(void)
9 {
10 RCC_Configuration(); //System clock configuration
11 LCD_GPIO_Init();
12 // Delay_ms(5000);
13 LCD_Init();
14 while (1>0)
15 {
16 DispColor(RED);
17 Delay_ms(1000);
18 DispColor(BLUE);
19 Delay_ms(1000);
20 }
21 }
22
23 void RCC_Configuration(void)//System clock is configured to 72MHZ
24 {
25 SystemInit();
26 }
summary:
From the video above, even if it is changed to STM32, driving the SPI screen still cannot achieve the screen refresh effect that cannot be distinguished by the naked eye.
Next, try using parallel port data transmission.
Previous article:A simple stm32vet6 driver for a 2.4-inch 240X320 8-bit parallel port tft screen DEMO
Next article:STM32 system understanding (EXTI) and slot-type photoelectric switch tp850 circuit research
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Linear thyristor power supply dimming and EMC issues
- [National Technology N32 MCU Development Package] --N32G4FR Series
- CC3220 Wireless MCU LaunchPad Development Kit Design
- 422 Driver Output Level
- NB-IoT application classification and technical characteristics analysis
- "Operational Amplifier Parameter Analysis and LTspice Application Simulation" 2. Chapter 2 Bias Current
- I2C Timing
- CUBEMX configures six-step square wave drive BLDC
- Resource Download: IoT technology is everywhere in the home
- [GD32307E-START] Development practice->K2 button + USART to achieve user interaction control + USRT print output status