STM32+SSD1963+TFT(FSMC)已调试通过的代码。 其中要注意的两点: 1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。 6 N! s% O9 n7 o6 ^; m
2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。 - <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c -------- STM32F103VCT6 A18! I9 D( \( r" C" f2 g
- </font></div><font face="Tahoma" color="#000000">
$ k# s4 ?# H+ N V% i - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD *((volatile u16 *)0X60000000)- {) p4 i* T/ d. J0 j
- #define LCD_DATA_ADD *((volatile u16 *)0X60080000)
% D6 x. t- h5 P - </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}
0 v# i) Y" ^5 I! i - #define WriteData(data) {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">
4 Q- c% b/ P! @4 K2 r" c# S3 {9 D - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void)
( k* Q& T% N% ~8 z - {
; j- x; u$ E* o+ Q* S+ `- f2 Q - FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;4 D9 I* T4 X% }" }; O# {! z
- FSMC_NORSRAMTimingInitTypeDef p;7 R% B7 I1 l G [, d7 g0 M
- GPIO_InitTypeDef GPIO_InitStructure;
; ?$ {1 y _' d7 _ - /*-- 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 */6 q, q4 n" l `' F# U2 L
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
2 o a( o: m$ Z/ h8 m9 ]) y - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
7 }# m' d: D! d7 ]( w; q; G2 | - RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/
5 I7 R, o* E. [+ r7 }% M, @ - /* Data /Address lines configuration */% D* l0 ~' m8 D/ k$ f
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |" I7 b8 w; Q( N4 H* r ]; P1 M
- GPIO_Pin_14 | GPIO_Pin_15;
' r' H* J' h$ P1 \. Z4 p - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
: D8 g5 n _5 \* b' \. Y2 T - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;0 z. x8 U& I5 A `0 a; i# ^
- 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 |; v* ^% s: C& M9 k
- GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
$ f1 `2 u, R1 V. X9 `& p - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;; Z+ M6 j0 U( b4 }! K7 p
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
6 X1 C+ q+ _4 o - GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /* Address lines configuration: A18*/
0 l" S+ O- F7 c' m+ O - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
' h/ J- p( Q% f - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
; i2 ?. p7 f% ^# ], l - GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /*===========GPIO For the Control========================*/
/ E* a' O( j l! j - /*!< NOE and NWE configuration */ 8 J2 c% T$ N9 [
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;& M1 E- b0 v/ ^" ?+ P1 c I7 e
-
( O0 O# f3 N" z1 L2 G* d0 D; o - GPIO_Init(GPIOD, &GPIO_InitStructure);
/ D* K- G- ^: K -
' s! M0 }6 O0 n d; x# l! v - /*!< NE1 configuration */
3 w7 ~+ C6 q9 k" S+ D - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;8 p9 [& a' F/ A3 H! E) c
- GPIO_Init(GPIOD, &GPIO_InitStructure);/ l7 S8 \3 \$ |. H# \
- d/ u6 t6 Z; z- {" z0 [! X
- /*!< NADV configuration */! n/ J6 U, s E0 b' t- O
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;7 g0 R8 N$ s( h- W' `
- // GPIO_Init(GPIOB, &GPIO_InitStructure);. o" W! g% t7 D! B. ^
- #ifdef LCD_USE_TE
9 R" S6 f( h" y - /*TE :busy*/6 s/ t$ q$ N7 O8 l& x
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
# U( o1 `0 m1 ]$ v# u5 R o - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
z' [4 V+ b# D3 c1 B% c7 H7 x - GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);3 [* g+ X) m- G. Q
- #endif
: D- I3 q$ ?, g! W3 \( P- { - /*!< NBL0, NBL1 configuration */
2 J$ Z+ h( i4 P9 u! W3 ~( { - // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;, Y: F' ^0 m6 Q2 b' l$ B
- // GPIO_Init(GPIOE, &GPIO_InitStructure);- c' }5 L' N& _+ S; T' m
- GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=1
4 B" _" E+ n1 Z# J- V - GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1); 0 F7 V: T0 a1 ~( i4 Z
- GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); . ?+ f' D: X# L+ Z8 V) Q7 U
- GPIO_ResetBits(GPIOE, GPIO_Pin_0);
7 z+ p/ j) h' I9 M& O7 t0 M2 @, \! ] - GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=0
5 G, h, l2 n+ |6 D" H, B. r6 B - GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1* Z* o. g! @. Y
- GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1 0 v& M& e6 o( {
- /*-- FSMC Configuration ------------------------------------------------------*/
7 o7 u" q( P8 t! C- ~ - * C) W5 d' f/ W6 s) ^" {2 \* A
- /*----------------------- SRAM Bank 1----------------------------------------*/
7 Z) @" B7 N8 K - /* FSMC_Bank1_NORSRAM1 configuration */
, o9 T& u2 U) U9 [( u1 Y. y - p.FSMC_AddressSetupTime = 0x02;//1;
/ ~ Z9 u' \1 x' G4 v2 q - p.FSMC_AddressHoldTime = 0x00;//0;
/ e) ~" Y+ E! ? - p.FSMC_DataSetupTime = 0x05;//5//2;
/ T* K u% O9 D6 u" O - p.FSMC_BusTurnAroundDuration = 0;0 }6 u; N \9 [- Y
- p.FSMC_CLKDivision = 0;
' R1 |7 h1 B. v$ {5 G: n* P' Y - p.FSMC_DataLatency = 0;
1 u9 H' o. Y5 c6 Y" n - p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;
% K. u2 X, `+ ]* W' n. ^ - /* Color LCD configuration ------------------------------------, `5 c5 B3 S* V N" i# E# b$ r) w
- LCD configured as follow:) k0 \4 G& _8 W$ z
- - Data/Address MUX = Enable3 V% y1 F+ P- v# p( H
- - Memory Type = SRAM7 x3 c( x9 O, t
- - Data Width = 16bit
" c: j+ j4 [/ h - - Write Operation = Enable) y T* u. d) Y0 P
- - Extended Mode = Enable
* j. Y; t! q9 k1 S% N - - Asynchronous Wait = Disable */
5 j3 s) q( a. p - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;" C) @9 F9 Z, L3 u. N
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //hy@
: i$ i6 S+ J$ a* V- n( n( m - // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //hy@
' B% g {- b1 W' o0 T2 T( L. k - // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//. w; H2 s, B" z& {, y- O# l
- 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;
3 ?/ \- E( e# p% v - FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
" u; M9 `6 x& A3 I; w$ A8 D& J) u, i - // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
9 _! \+ S& V) a' w7 y - FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
* q! g& u7 h1 r9 j1 q3 V5 ~ }0 v - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
* b7 L2 z% p: V - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;/ `+ l# h, \ t+ o0 O: {0 l( H
- FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;& |6 ]/ ^2 V$ x6 P
- FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;8 q* `" r9 |6 x: g, l; L
- FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;' K( w& n5 |" P) N% n: ~
- FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
6 `+ w+ [' W" ] y - FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
* y; }/ V; y4 T$ V - FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;1 m8 j9 p" U- ]; M% Y
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
; ?6 y x$ V% S b- R& |- R - /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled *// B; K4 c% @. E9 p3 p
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);5 V+ _, r+ x5 B) E6 ?$ ]% v" e
- }</font></div><font face="Tahoma" color="#000000">
/ w9 J! b9 ]3 d$ S$ s( ^; e - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**1 {$ y. j, r$ b" e- \* n
- * @brief Initializes the LCD.
& n' J+ ^+ U: V8 \7 k) p% Y8 L - * @param None
) G+ N& y: w: t. }3 d, R - * @retval None
; p% ^' H9 ]: g6 y - */0 ~/ G% q D) E, M. I! S! O
- void IzLCDDisplayInit(void)
( S- j! p+ `1 ^5 X - {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/
6 T; s5 K4 Y& G2 h2 j5 r - LCDFSMCConfig();3 W& J' @$ |8 |" V9 c
- ; N0 ]8 |( y# n5 q4 k* d
- DelayLoop(5); /* delay 50 ms */
1 c3 n- Q1 U# k# T0 R1 ~: I. n* }- P - //LCD_SetFont(&LCDDEFAULTFONT);
+ s! x& j( M8 {2 F% A - LCDSetFont(&LCDDEFAULTFONT);# J$ s! c% a9 |; g$ l, o! T/ k- F
- InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">, z/ _: Y6 i7 Y6 U6 ` v8 j$ |
- }</font></div>
复制代码 3 f% I' U& m9 [8 V6 y$ P' Z" j% q
|