|
STM32+SSD1963+TFT(FSMC)已调试通过的代码。 其中要注意的两点: 1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。
; p5 ?$ Q* J3 D( g' c2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。 - <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c -------- STM32F103VCT6 A18: e# n* p4 o# M! O6 O: d
- </font></div><font face="Tahoma" color="#000000">' b( [( Y! s4 j: p% V6 j+ i
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD *((volatile u16 *)0X60000000)
f" }% Z, p+ Q# P2 [/ r; U - #define LCD_DATA_ADD *((volatile u16 *)0X60080000)' i6 t1 j& [/ \+ N7 N
- </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}
6 n! \! E3 }3 }7 |+ i: W - #define WriteData(data) {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">. r2 K( Z2 H2 |, \5 W: N B
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void). a5 q. Y8 T' a' C$ N. d
- {0 I8 h+ n j% \) i' L6 I; Z
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;4 x/ B7 P) r, |# B0 W
- FSMC_NORSRAMTimingInitTypeDef p;& q: B+ a) Y4 n A9 g w
- GPIO_InitTypeDef GPIO_InitStructure;- [4 |9 ]; {& ^8 w
- /*-- 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 */; N% m7 H% u1 J! x& G& W: R) }
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
1 s: C$ p+ V" m% S( \7 ]2 C. e - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
# P! x9 B2 k0 O4 B$ S j8 i! Q - RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/ / U4 O. C! L( ^8 i
- /* Data /Address lines configuration */8 U. l2 g* e: ]& ?; F& Y3 t
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |$ i) ]# N4 Y) [, h# I
- GPIO_Pin_14 | GPIO_Pin_15;
6 R; |# w* O* n - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
7 U" F# \0 ~# a% M, a- U9 u# A) ] - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
' K7 H7 m# U7 |0 s - 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 |
; _ [! E4 Z8 b. t% f F - GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;1 t+ o+ X- s X$ U- W$ ?/ j
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;- ^5 ^/ e- Z% F( s" a4 `
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
) d8 G; `4 B6 {1 [* e2 G - GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /* Address lines configuration: A18*/0 M1 \7 O7 t$ l) r* b
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
% S( n$ j s8 Q2 P - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
1 ]* s. |: }, i# ^) B# H - GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /*===========GPIO For the Control========================*/
. B, N6 Z* S, n7 M. A - /*!< NOE and NWE configuration */
" b9 p: g. V7 X! y5 C, A - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
+ P1 h& n. Z+ C2 S* E; P- P Z -
/ B1 U' A6 S. a1 x7 K1 d7 z - GPIO_Init(GPIOD, &GPIO_InitStructure);
: ~6 p5 G9 t( u5 _3 D - $ d2 W' U, x5 v
- /*!< NE1 configuration */
4 |# R7 U. S' w. R1 J( a& R- T - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
. m! s! U/ F' E6 m4 g - GPIO_Init(GPIOD, &GPIO_InitStructure);
4 Y' L6 W, J) i) a8 e8 y/ q6 ? - 7 F3 b7 B: a6 ]. e( j
- /*!< NADV configuration */; p+ O7 i# S: w+ `: d' Q
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
! {% h0 t, ]7 f; W- w8 m2 V - // GPIO_Init(GPIOB, &GPIO_InitStructure);, n- `3 n$ @- E8 t
- #ifdef LCD_USE_TE
d7 F, m, x0 t6 n& V - /*TE :busy*/. v, e+ f3 e( O6 ~
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
* `3 A6 K2 {! p' q7 I0 U - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
, |1 B2 |# C: ` - GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);
9 O5 K, C3 i5 K+ z8 c/ o/ X4 K - #endif
! g) M& \2 r/ m7 l/ a% [% o - /*!< NBL0, NBL1 configuration */
2 ?" u! o% i" p. m8 L j - // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
4 [! w5 Q6 c, h$ n1 G. R2 N: U/ O - // GPIO_Init(GPIOE, &GPIO_InitStructure);3 j, p {$ O* ]9 X9 b8 I
- GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=1
, M; s8 o+ I9 k! F5 H) o - GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);
% V- q2 d: y- q+ V* ^ - GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
3 D) T( G' F. M5 B. z. ]7 L - GPIO_ResetBits(GPIOE, GPIO_Pin_0);! r3 q; H# e' [* B
- GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=05 K0 m* D& E! t6 O# u0 Z p$ w
- GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1
7 i& x/ V8 T6 W& v9 ~: v) ] - GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1 / G0 x K9 _/ E1 }
- /*-- FSMC Configuration ------------------------------------------------------*/. b7 {: q* T$ V' A% p) g7 C
- " K; w' Q% D( M, ?( L
- /*----------------------- SRAM Bank 1----------------------------------------*/3 r- e# d+ |, `( { |
- /* FSMC_Bank1_NORSRAM1 configuration */3 l8 ]0 ~% ~( {/ n9 S- P9 ^
- p.FSMC_AddressSetupTime = 0x02;//1;
- y: F7 g9 v6 _( u5 }+ R4 { - p.FSMC_AddressHoldTime = 0x00;//0;" D9 L: b7 E. v/ T3 _
- p.FSMC_DataSetupTime = 0x05;//5//2;% V: [/ g4 q9 m+ A$ n c
- p.FSMC_BusTurnAroundDuration = 0;+ R; G- v& W2 J. d5 O8 C# p3 g# f
- p.FSMC_CLKDivision = 0;& l' r" y% T3 i0 i# P$ d
- p.FSMC_DataLatency = 0;9 }; y" z- p; D" _" _% k7 }& Q
- p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;) e/ ^$ n3 T' Y; ^# P6 y
- /* Color LCD configuration ------------------------------------
& E$ E. [% E$ r( t6 Y' l/ p - LCD configured as follow:
8 T: s. s( r4 x. t - - Data/Address MUX = Enable, d; q% h D3 a( b. l
- - Memory Type = SRAM
& X9 ^/ P$ Y# f3 _ - - Data Width = 16bit9 G+ L8 Z4 C' O4 u' x5 M" n
- - Write Operation = Enable# D) V: S/ w+ `9 P3 g+ |% W) ^. \* w
- - Extended Mode = Enable
7 `$ {% X) z( v) G0 H - - Asynchronous Wait = Disable */
8 `8 ^; C/ l1 q W# c - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;! o+ K0 O; M i; a: ~
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //hy@
" L& u# Y0 l7 W$ b - // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //hy@ - f" S; C6 c. n% ]6 v* p
- // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
1 e/ R/ l; m# s - 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;- \, K0 T6 K7 ~; Q
- FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
2 c3 B, W3 r( }+ ^' n3 C; z - // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 0 X4 w0 h. `8 `; S& q
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;; f: g) _4 L/ I2 b6 t+ b! f
- FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
; U) b- ~4 R( x7 t - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
$ R7 t- T1 s3 e# r8 S4 \ - FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;: [$ X1 E0 Q5 s( ]5 A" s. B
- FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
/ ^' n* r% m9 A/ X" ? - FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
' N0 m& `9 l- U% p; u - FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
" z& \# `. Q+ r7 |, K5 A/ L - FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;) ^* f2 q7 W; o( r! b
- FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
- T; D, e+ E: I5 `+ O$ z$ v - FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
3 X3 M4 l7 E6 _/ I3 g - /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
$ W7 {% J5 X4 x& i6 f$ x* L - FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);, g; T( P# K( o' [5 o/ B6 ?
- }</font></div><font face="Tahoma" color="#000000">
& X* J! m1 j1 u+ J: ~7 I - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**8 A, S& L1 I5 U' _0 U* N
- * @brief Initializes the LCD.
1 D$ w ?/ L# z9 p* ?9 b - * @param None
2 {, N3 R% y$ ^( o8 L: } - * @retval None
. e8 d% V! z2 l: B/ l6 R% N) [ - */
" m3 O, R' l# A @1 l- j0 w - void IzLCDDisplayInit(void)2 ~8 X, |; v& t& y3 ^& N) _
- {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/
% G4 \% P0 ^+ M. ?3 u: }" c, n" W! v. x - LCDFSMCConfig();. x8 s) Z! g R9 ?8 H
-
4 l& ^5 H- X3 j/ G: `. v8 V - DelayLoop(5); /* delay 50 ms */2 b! V& U9 j) `" r6 A; M/ t
- //LCD_SetFont(&LCDDEFAULTFONT);
7 F4 h# M/ W% I: x6 U7 d6 L - LCDSetFont(&LCDDEFAULTFONT);
- z: n$ @1 {+ f- \. W: W0 V - InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">7 W( H7 ~* Y, I% B
- }</font></div>
复制代码 . u. U- ^5 A3 J4 j
|