|
STM32+SSD1963+TFT(FSMC)已调试通过的代码。 其中要注意的两点: 1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。 ( [6 A( l5 s9 z" O. c
2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。 - <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c -------- STM32F103VCT6 A18# {6 e2 D9 T5 n# {" p5 F/ j. T
- </font></div><font face="Tahoma" color="#000000">
. x8 [5 `# p: n4 } - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD *((volatile u16 *)0X60000000) I* r" R) T5 ^' E/ b; u5 p8 i* p
- #define LCD_DATA_ADD *((volatile u16 *)0X60080000)
& M9 e: S) _# B5 b - </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}. }* y W* ]" i; Z- t1 @
- #define WriteData(data) {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">
/ ]; @7 l- h5 D# M6 q - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void)
; ]; M0 L8 V( @" p - {( a# B; e+ v+ b$ H2 Z4 n
- FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
9 D# _$ y3 t d8 J) F5 T& G4 H - FSMC_NORSRAMTimingInitTypeDef p;
" v! o" L+ @& t+ l" b - GPIO_InitTypeDef GPIO_InitStructure;) q; k2 E4 H/ T: x. t" w7 t# I* E8 V3 D
- /*-- 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 */4 \0 |* F: K: B6 L j
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);, j" ^0 ^6 K8 i, V
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | v" |* C1 [3 w- c' U, Z
- RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/ : T8 I4 W$ d3 S% C4 v2 B$ V, f
- /* Data /Address lines configuration *// x7 G: `1 V: J9 }& V0 u
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |# e! B: ^0 P% q
- GPIO_Pin_14 | GPIO_Pin_15; o }3 U5 m+ s1 i9 Z
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;7 r& I* P+ Z: N' j- b3 ^
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
; b0 c& G; B# y8 e. @' Y" u - 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 |* n7 W" [9 ?$ h1 n# `5 Y) Z9 a
- GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;8 p2 A8 r1 e( d; N
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
; C7 T9 A0 F* D7 w \ - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
" o) v/ k8 k, G. U - GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /* Address lines configuration: A18*/
8 X1 m9 a, T: j R - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;6 {+ t! i& q! F* G0 N, i! K
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; ! A5 r: @! P, z! e" s9 b! r$ [5 B
- GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /*===========GPIO For the Control========================*/
l& H+ |" D' ] } - /*!< NOE and NWE configuration */ . M9 H9 @6 c. W- b: d% A) ^
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
' r! e- {3 u4 b# b+ @ - ! o% N- X' D) E3 Q: q) Z0 J& I- O. y
- GPIO_Init(GPIOD, &GPIO_InitStructure);3 z3 ^: p/ {) o) d6 D$ B: D
-
' |* v7 g! j( x& h9 [ Y# Q- r$ Z - /*!< NE1 configuration */
& C p3 c2 H+ x! C4 z5 ? - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
2 q4 b& i1 R$ K7 c0 e# Q% r( ~ - GPIO_Init(GPIOD, &GPIO_InitStructure);
2 |& t! l' i' Z5 z* r' }* ^ - / b: V; Y" S* g+ j. i7 t; u
- /*!< NADV configuration */
0 t. R$ ]) k' a, s' `- T+ j; f - // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;) N }- D: u( a5 }, q
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
, x9 Y4 v0 ]7 h' b5 N* a; v) _0 c o - #ifdef LCD_USE_TE
6 u$ k; W, ]6 M. c6 J - /*TE :busy*/1 } l. B: w4 K' i1 n
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
5 Z; O3 o. A- r; e9 e( D4 j - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; * a! x% i7 ^ C( o1 T2 @) |2 f2 b6 f
- GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);9 ^3 i7 i2 F* c$ M! M% ]
- #endif
# d! ?; f8 ]" u9 C; _ - /*!< NBL0, NBL1 configuration */6 P' G- }8 j: L1 v8 e) ?6 C
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;, t8 [, |1 @4 B, o ~
- // GPIO_Init(GPIOE, &GPIO_InitStructure);
% F+ } a# V- _- A! ~: Y, j - GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=1
' c {: D, W; h7 n, E7 d" w9 _ - GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1); $ B& ^1 P M7 i1 R
- GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
; K. E0 t9 K0 o& H6 H N' H i - GPIO_ResetBits(GPIOE, GPIO_Pin_0);
3 O; Q8 ~" t0 n% I) q - GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=07 T4 p3 v* a* {5 s. O; o5 ? [
- GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1
2 l9 Z* B3 v* `% E. u+ r! q - GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1
/ H8 d8 R6 e- t/ N, B5 J - /*-- FSMC Configuration ------------------------------------------------------*/9 w/ K, e3 r- Y! |
- ! \. n5 B z D- ~) s
- /*----------------------- SRAM Bank 1----------------------------------------*/* x3 ^% {" V$ U
- /* FSMC_Bank1_NORSRAM1 configuration */+ Z9 u* o4 l2 h1 S
- p.FSMC_AddressSetupTime = 0x02;//1;
' o' v; G! B# B: e2 j! C4 l - p.FSMC_AddressHoldTime = 0x00;//0;# O$ x* I, R* f: G* q/ f" ]
- p.FSMC_DataSetupTime = 0x05;//5//2;& W7 J% D- A' [6 e
- p.FSMC_BusTurnAroundDuration = 0;
- U+ \ P* x/ q0 | - p.FSMC_CLKDivision = 0;
7 E$ s9 F" _1 X' }; L; A; Q& n - p.FSMC_DataLatency = 0;7 i5 A6 H) J e% H
- p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;# L/ T1 ~0 ~* s4 W& J
- /* Color LCD configuration ------------------------------------/ T& H3 b( l0 u- ?% k+ }3 T: u1 @! y
- LCD configured as follow:
: g- d5 h" }/ P" ] - - Data/Address MUX = Enable
# H7 Z/ b" T1 d/ c. Y - - Memory Type = SRAM1 V- K7 H6 x9 T# i+ d, l
- - Data Width = 16bit3 Q Z. y8 H' j9 v6 _# s8 ?
- - Write Operation = Enable4 ~) j5 p# g. P B+ q: G3 l# ?+ ?
- - Extended Mode = Enable
; A) U% E* K- L- ] C - - Asynchronous Wait = Disable */
. T% a9 O5 j6 @4 q2 j( A - FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
* k2 t1 B1 S+ m! U7 ? - FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //hy@
+ z T: ]8 T# k' ^ - // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //hy@ ! X1 ~7 S% N( @2 H: Q) O% g
- // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
" K7 q4 g8 i7 N% F# ~ - 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;( i% O) V7 M4 `* \. v. l) C# S
- FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
- U& O, ?0 W; K, T - // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 6 N, P" E i+ c" {
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;2 O1 d5 [$ |' [2 B& s- ?: m ^
- FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
/ Q; j& ~+ z5 Y$ I - FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;$ V4 C8 d2 b2 J' ~7 _! W9 h
- FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
% V& g/ c! x& r/ m. G1 s% }9 h. i - FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
! I3 E& N2 s2 f B - FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
3 `" e4 M+ g& q) J0 I8 q - FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;- m7 S Y3 U! r3 T4 d1 @: Q4 q
- FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
! Y# K" j+ e; J- k+ { - FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;1 q) |. R, l b2 O" N, P8 U' s* O
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
; B# n5 Z" U1 h, q- p; v - /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
5 b* h& T' J7 b- o - FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
1 B7 Z' f- n i" a: E' e1 p - }</font></div><font face="Tahoma" color="#000000">
9 n9 I- N5 s9 k" j, _6 J, I - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**
# G& Z; `7 F; N8 \* C: x/ ?( K - * @brief Initializes the LCD.' y& H$ H: Y7 {; g
- * @param None
, T; v& a- y4 w- x: B; S3 l/ Z - * @retval None- N; y/ q! k f$ q0 F. h: v, Z
- */
T N; M. R+ [4 o; R% ] - void IzLCDDisplayInit(void)- b" X) w- q2 B
- {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/
0 j6 g( s. Q% V - LCDFSMCConfig();
# q1 v! s2 E" {9 T- m -
, w- z* r2 a9 V* h# R6 E$ t0 ^ - DelayLoop(5); /* delay 50 ms */
5 |" Y3 R; _2 u( d3 |8 Q, A - //LCD_SetFont(&LCDDEFAULTFONT);8 l8 s0 j; q- Y1 k# u3 m. _: ^
- LCDSetFont(&LCDDEFAULTFONT);" ^; o9 X2 g7 m9 x- ?
- InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">3 J2 l( E; t- z6 D' z' w
- }</font></div>
复制代码 " V$ |8 ^1 v; j" X
|