|
STM32+SSD1963+TFT(FSMC)已调试通过的代码。 其中要注意的两点: 1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。 , d- H# i8 U) ^8 g% }7 `+ B
2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。 - <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c -------- STM32F103VCT6 A182 r! W( }) b+ n& g3 W$ \
- </font></div><font face="Tahoma" color="#000000">
% j- \7 d5 `6 s* {0 B - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD *((volatile u16 *)0X60000000)
, y, q: N9 F- A' }" R9 N3 R - #define LCD_DATA_ADD *((volatile u16 *)0X60080000)% }8 L7 M( X2 S8 a+ a: E6 A
- </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}4 o: S" }2 o5 U+ u
- #define WriteData(data) {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">
+ e( f& X5 z6 N. `9 m& | - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void)
5 n) O* T( ?0 h& P - {: h9 T3 c) Q" r1 p1 j
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;1 W5 q6 c j9 a6 A7 T
- FSMC_NORSRAMTimingInitTypeDef p;9 X4 N# z& q; _/ _
- GPIO_InitTypeDef GPIO_InitStructure;
1 t8 G. d! l+ I0 o - /*-- FSMC Configuration ------------------------------------------------------*/</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */) S! I- Y' v" v7 x7 l
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
4 F1 u0 h, Q3 s - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |& d" E1 ]3 B' O6 W# [
- RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/
; j3 S& O; [; D# v. `5 g - /* Data /Address lines configuration */
" J" H! s) Y0 P" g* l! J - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |4 W" W, P7 Y5 U4 a% Y+ m
- GPIO_Pin_14 | GPIO_Pin_15;4 E2 r' t5 S9 [0 K$ B8 v4 e) J; G' Z
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;/ M3 |4 R) I$ H7 Y u: a7 ~- \% P) Q
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;$ i" a- [/ W6 {" l7 t/ n
- GPIO_Init(GPIOD, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
- b* M8 z+ m D - GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;9 \$ c: k0 W% g. p& I
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
o6 c& j. h& J2 R5 E% Y - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ G. n, ^7 t4 |$ I: T N$ N - GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /* Address lines configuration: A18*/
; d! B- F! `! y, o+ S) u - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
: i6 V+ @2 i& I3 n5 c& H, ~* Z7 w9 e - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
* v+ t4 q& K( ]% @0 W' q: A4 v - GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /*===========GPIO For the Control========================*/
$ V1 j7 f8 C1 K+ {3 y2 y - /*!< NOE and NWE configuration */
- d7 Y0 T# _8 F4 @+ L - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
! e4 W, h1 X- y+ i" Q -
' U* U2 `% T" R5 p! y/ h% G' r - GPIO_Init(GPIOD, &GPIO_InitStructure);. I- \5 U" b& q' w, Y6 k# E
-
- W2 @3 x8 N; e% p7 T& I/ j - /*!< NE1 configuration */
& ~8 ?& J3 e1 \; u - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;2 T5 f6 m7 N z3 K( z( \
- GPIO_Init(GPIOD, &GPIO_InitStructure);
2 `& ^! d( P+ m9 m/ t- @7 ] - ( |! u- K% a& J ~
- /*!< NADV configuration */! S/ s9 F$ P# L
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;2 j+ y$ {, L& b7 s; Y+ u
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
" h7 L9 E2 i0 l8 B- U Q" w - #ifdef LCD_USE_TE2 G& Y8 v1 u/ t: R8 }* C
- /*TE :busy*/
+ [0 b+ x5 Y* N; S8 e) s - GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
8 @8 U! n: ^; j/ X6 Y - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; - F3 u) J- e$ d# ]1 P' m5 Y9 }4 c
- GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);3 }* G& w. J& s; G( P
- #endif
4 m( B7 y w0 R3 Y; i; Y - /*!< NBL0, NBL1 configuration */
+ c% A& y2 l+ c2 j8 M& F& F) A: A - // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
4 W( L% Z" Q) [3 z' Y! {2 T - // GPIO_Init(GPIOE, &GPIO_InitStructure);/ ^2 s! v+ y) M/ Y( R
- GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=11 l, h- H& J( }1 h$ F5 z8 O3 v
- GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);
; g9 l' N( J$ x4 `# p7 t( w - GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
* b/ L5 r) w. _8 W1 J' a+ Z' s9 U% c - GPIO_ResetBits(GPIOE, GPIO_Pin_0);
! ~% g$ g% R- D8 M - GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=0
$ z9 L9 T* d6 r1 f8 e - GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1
) }5 j9 i! ?' _ _ - GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1 ( E! E( P& b. G% q. k
- /*-- FSMC Configuration ------------------------------------------------------*/
$ |/ B4 O8 m: ~, c5 N9 i! `# |- m -
" H6 c8 @( T; k$ f2 @* g0 J' L - /*----------------------- SRAM Bank 1----------------------------------------*/
1 W9 B) E0 e" K" S1 n! \ - /* FSMC_Bank1_NORSRAM1 configuration */
7 |/ V" {9 E3 Q: M - p.FSMC_AddressSetupTime = 0x02;//1;: l2 {% _0 ^3 @' f W6 \
- p.FSMC_AddressHoldTime = 0x00;//0;3 |5 G$ t$ @' f( n" @0 X& q5 c
- p.FSMC_DataSetupTime = 0x05;//5//2;
; `$ |+ K9 S* L9 ] - p.FSMC_BusTurnAroundDuration = 0;
3 {4 @/ I! R u# D+ |3 u% v' |! n - p.FSMC_CLKDivision = 0; U. Z) V( e8 z- s' C+ {
- p.FSMC_DataLatency = 0;! P2 b+ Q2 ?) E, n) D b/ a
- p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;# q& _5 {0 A1 R3 q
- /* Color LCD configuration ------------------------------------
, r& P5 `% [$ {/ k4 P! ]" Z; G - LCD configured as follow:
. o1 W3 \' J4 K0 D6 g - - Data/Address MUX = Enable
0 U& J3 a; |! L; G - - Memory Type = SRAM
# u$ G+ j* L0 g% @# h/ Q- R - - Data Width = 16bit( ]7 _8 Q/ s/ q2 J* L
- - Write Operation = Enable. E2 k9 K" ]( @7 {9 c
- - Extended Mode = Enable* N6 ?+ s8 v6 F- B0 q
- - Asynchronous Wait = Disable */" O6 p* }1 j' ?
- FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;" ]2 S6 Q2 J# e# ^& K5 ?% x
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //hy@
3 v2 Q( S4 B7 X - // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //hy@ ( U1 o2 n/ a \6 i: E. G
- // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
: ?( k$ g9 @# ~/ E# j - FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;9 c1 W I& o5 H: b) A# f, V. h8 y; E
- FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;, A( k8 q9 ^, h. z9 n7 b4 B) y
- // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; . n4 p& {0 r% {# V; \ v0 T
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
6 g- F- f: J" j, F5 i P1 ? - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; E$ g% ~9 |5 `; z- W, P- }
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
# K% k6 _& M/ a - FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
' j# I% }9 v; }3 P/ J" u - FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;* c6 l8 v3 K' }5 z% \) O
- FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;/ O+ [: `! d# C/ S$ o/ A; U, `& m9 e0 j
- FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;' M6 G# S" r7 w5 f
- FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
0 F+ Z! o' ^. s - FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
9 `+ `* O, w$ \7 m# F* K7 O - FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
/ Y& C: T8 r3 J2 ^9 e5 I - /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */+ s) G( v9 c1 F+ K
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);4 [) S j; }* \: u
- }</font></div><font face="Tahoma" color="#000000">
" K% r: A8 _# ~: F6 }/ M+ l0 Y. s - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**! \! g9 x F6 p8 A7 L" I
- * @brief Initializes the LCD.
# r0 Q8 w" G y0 ~9 C8 ?8 ?6 l - * @param None$ b% q x7 u% x
- * @retval None# [7 x; x$ C1 @, r
- */
2 J% k r2 U. b$ R - void IzLCDDisplayInit(void). M/ t2 X7 q) N1 A" \# ]9 i- ?
- {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/1 ^: \4 ^) B7 _, s& U, ]9 H: D" G: s
- LCDFSMCConfig();7 Y3 Q& y1 g4 p& I9 B" i& u
-
) n) x$ C% r4 ~6 y - DelayLoop(5); /* delay 50 ms */) O( H1 _2 W W4 h3 h4 ]% \/ X+ {
- //LCD_SetFont(&LCDDEFAULTFONT);
' p1 }; n( J5 h; T% X - LCDSetFont(&LCDDEFAULTFONT);( y1 S2 }# q7 t
- InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">- `, N, c% \. Y& t( `$ Q- q
- }</font></div>
复制代码 / Z0 Q t9 q% [
|