一個(gè)簡單的stm32vet6驅(qū)動(dòng)2.4寸240X320的8位并口tft屏DEMO
掃描二維碼
隨時(shí)隨地手機(jī)看文章
書接上文:
最近在研究用低速、低RAM的單片機(jī)來驅(qū)動(dòng)小LCD或TFT彩屏實(shí)現(xiàn)動(dòng)畫效果
首先我用一個(gè)16MHz晶振的m0內(nèi)核的8位單片機(jī)nRF51822嘗試驅(qū)動(dòng)一個(gè)1.77寸的4線SPI屏(128X160),
發(fā)現(xiàn),刷一屏大約要0.8s左右的時(shí)間,
具體收錄在《1、一個(gè)簡單的nRF51822驅(qū)動(dòng)的天馬4線SPI-1.77寸LCD彩屏DEMO》中
覺得,如果用72MHz的STM32也許效果會(huì)好很多
于是在stm32上做了個(gè)類似的版本,
具體收錄在《一個(gè)簡單的stm32vet6驅(qū)動(dòng)的天馬4線SPI-1.77寸LCD彩屏DEMO》中
發(fā)現(xiàn)刷一屏0.2s左右,
效果是有的,但是還不能達(dá)到支持播放流暢動(dòng)畫的效果!
于是,決定將串行數(shù)據(jù)改成并行數(shù)據(jù)傳輸
本節(jié)將帶來一個(gè)用stm32驅(qū)動(dòng)的2.4寸240X320的8位并口tft屏的刷屏效果
工程結(jié)構(gòu)
main.c
1 /* Includes ------------------------------------------------------------------*/
2 #include "stm32f10x.h"
3 #include "LCD2.h"
4
5
6 void RCC_Configuration(void);
7 /****************************************************************************
8 * 名 稱:int main(void)
9 * 功 能:主函數(shù)
10 * 入口參數(shù):無
11 * 出口參數(shù):無
12 * 說 明:
13 * 調(diào)用方法:無
14 ****************************************************************************/
15 int main(void)
16 {
17 RCC_Configuration(); //系統(tǒng)時(shí)鐘配置
18 LCD2_GPIO_Init();
19 LCD2_Init();
20 while (1)
21 {
22 Show_RGB(0,240,0,320,0xff0f);
23 DELAY_MS(1000);
24 Show_RGB(0,240,0,320,0x00fe);
25 DELAY_MS(1000);
26 }
27 }
28
29 /****************************************************************************
30 * 名 稱:void RCC_Configuration(void)
31 * 功 能:系統(tǒng)時(shí)鐘配置為72MHZ
32 * 入口參數(shù):無
33 * 出口參數(shù):無
34 * 說 明:
35 * 調(diào)用方法:無
36 ****************************************************************************/
37 void RCC_Configuration(void)
38 {
39 SystemInit();
40 }
LCD2.c
1 #include "LCD2.h"
2
3
4
5 void LCD2_GPIO_Init()
6 {
7 GPIO_InitTypeDef GPIO_InitStructure;
8
9 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB " RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
10
11
12 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
13 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
14 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口線翻轉(zhuǎn)速度為50MHz
15 GPIO_Init(GPIOB, &GPIO_InitStructure);
16
17 //8位數(shù)據(jù)輸出
18 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
19 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
20 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口線翻轉(zhuǎn)速度為50MHz
21 GPIO_Init(GPIOD, &GPIO_InitStructure);
22 }
23
24 //////////////////////////////////////////////////////////////////
25 //最底層數(shù)據(jù)傳輸函數(shù)
26 //////////////////////////////////////////////////////////////////
27 //寫命令
28 void Write_Cmd(unsigned char DH,unsigned char DL)
29 {
30 LCD2_CS=0;
31 LCD2_RS=0;
32
33 DataPort=DH;
34 LCD2_RW=0;
35 LCD2_RW=1;
36
37 DataPort=DL;
38
39 LCD2_RW=0;
40 LCD2_RW=1;
41 LCD2_CS=1;
42 }
43 //寫數(shù)據(jù) 雙8位
44 void Write_Data(unsigned char DH,unsigned char DL)
45 {
46 LCD2_CS=0;
47
48 LCD2_RS=1;
49 DataPort=DH;
50 LCD2_RW=0;
51 LCD2_RW=1;
52
53 DataPort=DL;
54 LCD2_RW=0;
55 LCD2_RW=1;
56 LCD2_CS=1;
57 }
58
59 //寫數(shù)據(jù) 雙8位
60 void Write_Data2(unsigned char DH,unsigned char DL)
61 {
62 DataPort=DH;
63 LCD2_RW=0;
64 LCD2_RW=1;
65
66 DataPort=DL;
67 LCD2_RW=0;
68 LCD2_RW=1;
69 }
70
71 //////////////////////////////////////////////////////////////////
72 //調(diào)用上面最底層實(shí)現(xiàn)稍高層寫命令和數(shù)據(jù)函數(shù)
73 //////////////////////////////////////////////////////////////////
74 /*----------------------------------------------------------------
75 寫命令、寫數(shù)據(jù)
76 輸入?yún)?shù):x 需要輸入的命令 16位
77 y 需要輸入的數(shù)據(jù) 16位
78 ----------------------------------------------------------------*/
79 void Write_Cmd_Data (unsigned char x,unsigned int y)
80 {
81 unsigned char m,n;
82 m=y>>8;
83 n=y;
84 Write_Cmd(0x00,x);
85 Write_Data(m,n);
86 }
87 /*----------------------------------------------------------------
88 寫16位數(shù)據(jù)
89 ----------------------------------------------------------------*/
90 void Write_Data_U16(unsigned int y)
91 {
92 unsigned char m,n;
93 m=y>>8;
94 n=y;
95 Write_Data2(m,n);
96 }
97
98 /*----------------------------------------------------------------
99 液晶初始化
100 ----------------------------------------------------------------*/
101 void LCD2_Init(void)
102 {
103 LCD2_CS=1;
104 DELAY_MS(5);
105 LCD2_RES=0;
106 DELAY_MS(5);
107 LCD2_RES=1;
108 DELAY_MS(50);
109 Write_Cmd_Data(0x0001,0x0100);
110 Write_Cmd_Data(0x0002,0x0700);
111 Write_Cmd_Data(0x0003,0x1030);
112 Write_Cmd_Data(0x0004,0x0000);
113 Write_Cmd_Data(0x0008,0x0207);
114 Write_Cmd_Data(0x0009,0x0000);
115 Write_Cmd_Data(0x000A,0x0000);
116 Write_Cmd_Data(0x000C,0x0000);
117 Write_Cmd_Data(0x000D,0x0000);
118 Write_Cmd_Data(0x000F,0x0000);
119 //power on sequence VGHVGL
120 Write_Cmd_Data(0x0010,0x0000);
121 Write_Cmd_Data(0x0011,0x0007);
122 Write_Cmd_Data(0x0012,0x0000);
123 Write_Cmd_Data(0x0013,0x0000);
124 //vgh
125 Write_Cmd_Data(0x0010,0x1290);
126 Write_Cmd_Data(0x0011,0x0227);
127 //DELAY_MS(100);
128 //vregiout
129 Write_Cmd_Data(0x0012,0x001d); //0x001b
130 //DELAY_MS(100);
131 //vom amplitude
132 Write_Cmd_Data(0x0013,0x1500);
133 //DELAY_MS(100);
134 //vom H
135 Write_Cmd_Data(0x0029,0x0018);
136 Write_Cmd_Data(0x002B,0x000D);
137
138 //gamma
139 Write_Cmd_Data(0x0030,0x0004);
140 Write_Cmd_Data(0x0031,0x0307);
141 Write_Cmd_Data(0x0032,0x0002);// 0006
142 Write_Cmd_Data(0x0035,0x0206);
143 Write_Cmd_Data(0x0036,0x0408);
144 Write_Cmd_Data(0x0037,0x0507);
145 Write_Cmd_Data(0x0038,0x0204);//0200
146 Write_Cmd_Data(0x0039,0x0707);
147 Write_Cmd_Data(0x003C,0x0405);// 0504
148 Write_Cmd_Data(0x003D,0x0F02);
149 //ram
150 Write_Cmd_Data(0x0050,0x0000);
151 Write_Cmd_Data(0x0051,0x00EF);
152 Write_Cmd_Data(0x0052,0x0000);
153 Write_Cmd_Data(0x0053,0x013F);
154 Write_Cmd_Data(0x0060,0xA700);
155 Write_Cmd_Data(0x0061,0x0001);
156 Write_Cmd_Data(0x006A,0x0000);
157 //
158 Write_Cmd_Data(0x0080,0x0000);
159 Write_Cmd_Data(0x0081,0x0000);
160 Write_Cmd_Data(0x0082,0x0000);
161 Write_Cmd_Data(0x0083,0x0000);
162 Write_Cmd_Data(0x0084,0x0000);
163 Write_Cmd_Data(0x0085,0x0000);
164 //
165 Write_Cmd_Data(0x0090,0x0010);
166 Write_Cmd_Data(0x0092,0x0600);
167 Write_Cmd_Data(0x0093,0x0003);
168 Write_Cmd_Data(0x0095,0x0110);
169 Write_Cmd_Data(0x0097,0x0000);
170 Write_Cmd_Data(0x0098,0x0000);
171