A simple stm32vet6 driven Tianma 4-wire SPI-1.77-inch LCD color screen DEMO

Publisher:幸福家庭Latest update time:2017-01-21 Source: eefocusKeywords:stm32vet6  SPI- Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:stm32vet6  SPI- Reference address:A simple stm32vet6 driven Tianma 4-wire SPI-1.77-inch LCD color screen DEMO

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

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号