|
STM32+SSD1963+TFT(FSMC)已调试通过的代码。 其中要注意的两点: 1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。
$ b6 a2 J8 _3 \. k6 T) k9 g2 x2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。 - <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c -------- STM32F103VCT6 A18" u5 H- K3 }: q
- </font></div><font face="Tahoma" color="#000000">! t; \% L: |) R3 v& n
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD *((volatile u16 *)0X60000000)
7 [7 f) M/ J: y! n4 q" _ - #define LCD_DATA_ADD *((volatile u16 *)0X60080000)
% T4 N- \4 g q6 f - </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}
) e+ S* a2 Y$ |$ P1 y - #define WriteData(data) {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">8 b3 T% O1 g' u0 {* }: H( l6 X
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void)( v& D7 T. m: @
- {
4 F/ u' Z, @0 z- Q2 Z - FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;+ i" k0 w6 V* \
- FSMC_NORSRAMTimingInitTypeDef p;
" R d% ]: K! K# h$ x - GPIO_InitTypeDef GPIO_InitStructure;
" O1 J8 j1 i7 F3 I - /*-- 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 */
. G1 }) j) m! p# _ - RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);/ k/ B0 r9 z- q! [
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |( M& i3 R! L2 u2 M4 b# d# R1 n
- RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/
% i( C) T# H' P. J5 E - /* Data /Address lines configuration */5 d. I; H9 A/ n/ b& d V
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |5 n# i' c. g' j0 _, i- r; p
- GPIO_Pin_14 | GPIO_Pin_15;
! k+ y. N2 J# N! _ X - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;, P7 v+ C$ H0 c/ n0 j
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
?$ h3 e. Q1 e: s9 V - 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* G- E: } Q W9 b% h - GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;# u* [% ]0 F8 M& O3 D
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;2 h: z! u7 w+ V3 R' e9 w' d
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
4 h+ O$ X% @/ |" B9 V/ ^" `5 d' v) V8 j - GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /* Address lines configuration: A18*/
6 q& ^5 Q7 |5 q9 p- p$ p1 @" S7 i - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
) Z6 q# W% X8 Y: _# N - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 5 R/ I3 |/ G4 U1 x" N5 w2 b+ Y
- GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /*===========GPIO For the Control========================*/
' M$ d p. g1 `- d: g - /*!< NOE and NWE configuration */ 9 q5 Y4 g6 P$ b" e2 r' |# c* S
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;3 H5 x- ~# J8 h5 _
-
9 A' D+ z9 @: H b+ W, ^ - GPIO_Init(GPIOD, &GPIO_InitStructure);6 t. p. ]+ B3 R2 O. M9 h6 Y8 T
-
' Q3 f: Q0 ~9 K' a( l% f' |. u; y - /*!< NE1 configuration */( _8 T+ u. E, _4 A3 B& }
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
9 o9 f+ ~. A' e) r4 T$ r$ I5 a - GPIO_Init(GPIOD, &GPIO_InitStructure);
u4 N/ \2 \5 J+ V! i5 Y& d - ( D( o' {4 \5 S* j5 m
- /*!< NADV configuration */" ?$ D0 b* R/ _" Z6 Z3 ]
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
+ r/ i5 Z' g9 f# s. B - // GPIO_Init(GPIOB, &GPIO_InitStructure);
2 d/ S4 Q7 F$ K$ z* D* O - #ifdef LCD_USE_TE j1 o8 H/ I3 x0 u6 s8 R
- /*TE :busy*/, L4 ~ n4 b5 u6 u3 {: d
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;3 C* m% m( {' U* X: _
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 3 L+ Q- J( x9 a& I8 A8 T' _% _
- GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);2 \* P* R3 j, v' r
- #endif
7 e' h) g: B" d; u - /*!< NBL0, NBL1 configuration */
$ N! f) e6 G( a9 v9 y) d7 x% I; n - // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;' |" w6 A$ P* v, K4 a: k* @
- // GPIO_Init(GPIOE, &GPIO_InitStructure);
$ ~3 l( S' z a1 G - GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=15 }* I9 u% O& H8 F
- GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1); * Y2 x0 _) ^3 {% n
- GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
5 V+ H/ V1 h1 a7 \# X - GPIO_ResetBits(GPIOE, GPIO_Pin_0);( r. i5 i; {! m+ }4 D& ^" A9 v6 Z
- GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=0$ R7 q% |' H+ {5 J/ q+ l
- GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=16 i. S0 q# k+ u }% W: ]7 \
- GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1
; v/ u) e. [& u2 u& ^* M - /*-- FSMC Configuration ------------------------------------------------------*/
. p, Q+ y8 W& k# W0 u4 ~* i - ! H! s7 ?" h, y2 _
- /*----------------------- SRAM Bank 1----------------------------------------*/6 R. e: V( J1 A9 f
- /* FSMC_Bank1_NORSRAM1 configuration */
5 _' x& e5 A7 l: T: C( z# _ - p.FSMC_AddressSetupTime = 0x02;//1;
8 V2 c; B3 I, {' D' y" W - p.FSMC_AddressHoldTime = 0x00;//0;
, E+ q2 |5 C6 m3 G: x3 d - p.FSMC_DataSetupTime = 0x05;//5//2;" J0 j3 x# `4 j& P$ ~9 A
- p.FSMC_BusTurnAroundDuration = 0;- {3 _- w8 R' a
- p.FSMC_CLKDivision = 0;
: E% `1 Y6 `3 s6 R; r# ? - p.FSMC_DataLatency = 0;
! [2 {7 W9 S9 A - p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;+ ^. _4 ?+ Y2 A+ U
- /* Color LCD configuration ------------------------------------% a' g& Z% T. y" T7 H1 {2 e z- U
- LCD configured as follow:% ~& V! @' t- @* [3 @, D
- - Data/Address MUX = Enable
3 d# M% t0 b: t0 {( R - - Memory Type = SRAM
, n: w. i, [! `( ?5 w/ Y - - Data Width = 16bit
/ R1 Z5 U Z& K% h& S - - Write Operation = Enable* k. |! u- N$ H. I. ~: E
- - Extended Mode = Enable
4 [6 }/ g9 V# h: U k- K6 i! j [' F - - Asynchronous Wait = Disable */
8 A# H) Z; t. b1 x - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;3 _& O/ @2 k$ |& n8 ?
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //hy@
; r, F) ^7 @- ] j- R% | - // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //hy@ / I$ u3 c* }/ i
- // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
* q& }/ J2 u" Q9 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; L$ Z7 \+ a2 G; B
- FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;8 z7 `! k8 f, }6 T) V% r3 R
- // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 5 v: {1 r5 b* d) L4 g% p
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
$ c+ p, l1 n! C" b1 I- F! u+ K - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
7 R6 @ n# j" n/ P p' Q" I- v - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;5 J8 x8 b$ f8 S, d* ~7 |6 g
- FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
/ n5 B/ E, L+ M6 }- X; }0 O. @1 K - FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
9 {0 I$ W1 C2 [, @ - FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;8 C$ X2 B# O+ O8 C
- FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;4 a1 C! L+ H$ l! f
- FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;* ]$ W, a+ m4 t' i
- FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
% z; l8 x1 Z0 u1 _4 \ - FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); - n! u# N8 N$ w3 D% f
- /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
! W4 o1 h! A- ^( L) } - FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);, P9 _$ v6 X% Q7 s) D6 [1 h
- }</font></div><font face="Tahoma" color="#000000">! v) t8 y* O; g; o3 r
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**! v( p; @1 C6 l2 n- Q* Q
- * @brief Initializes the LCD.
3 d- U. d, C* t - * @param None
$ y% K% `3 G* w - * @retval None2 {$ e* D4 v/ }/ [2 r: P( \$ c" \
- */: q8 U% s( O! {+ m! T9 ]1 y/ v
- void IzLCDDisplayInit(void)
4 i4 I/ j7 k" y+ C# N3 c' h0 q4 { - {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/
7 ^2 k; x+ D% _9 y7 F% r - LCDFSMCConfig();
- w/ `2 z) m# j& Q9 J! d - % P$ X, B" F* o1 D6 h, Z
- DelayLoop(5); /* delay 50 ms */
* x& y+ R+ p: ? - //LCD_SetFont(&LCDDEFAULTFONT);
& o4 O# M* n7 R" `0 r - LCDSetFont(&LCDDEFAULTFONT);! b: M- I; _9 ?1 T: b: [4 m
- InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">
* z' P. C1 y0 ^3 x+ A& Q6 ~) j+ K% _ - }</font></div>
复制代码 8 w ~! k6 Y5 X1 ~
|