STM32+SSD1963+TFT(FSMC)已调试通过的代码。 其中要注意的两点: 1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。
2 o/ i- Y' A) }0 x4 [& G( q2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。 - <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c -------- STM32F103VCT6 A18
5 ]) m- M) D# C1 R9 y4 o. d - </font></div><font face="Tahoma" color="#000000">1 t7 ?; Q% A$ c' B% V; z! D( G) s
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD *((volatile u16 *)0X60000000)0 ?4 b) J+ l. m" N; A
- #define LCD_DATA_ADD *((volatile u16 *)0X60080000)% V( Z% T3 j# Q+ Q
- </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}0 h" v3 c+ S) C: v1 b
- #define WriteData(data) {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">" j0 M. r7 _8 ~
- </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void). C) g4 j1 ?1 C* h( m3 x9 \, m
- {
# K: q! |' \' e6 c8 Q/ h - FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;& s- c, B5 d) h! Z/ n
- FSMC_NORSRAMTimingInitTypeDef p;
4 |) Z( x" s3 L4 c) _ - GPIO_InitTypeDef GPIO_InitStructure;! T4 X4 F5 J: p, S! v2 c' f
- /*-- 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 */5 T, h* Z0 }$ p5 C
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
# y8 S; _4 ~3 q. B5 Y% F+ q - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |1 x2 C5 Q: Y8 t m! B' R" C
- RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/ 4 z: U9 i5 G2 E+ F0 q" T
- /* Data /Address lines configuration */
6 A4 {! o2 O# B - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
% L3 j8 ]4 d2 X/ `& s) W - GPIO_Pin_14 | GPIO_Pin_15;. j4 x/ [' W8 ?( D) n; R1 o3 X
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
" f) ]5 L, B" B3 B# G6 ? - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
! g& S5 a0 _6 P( y# H8 h - 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 |
D, n, G9 {- ?! b# \ - GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
# ~2 B; C6 O3 E1 T+ L, [4 h - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;! Y/ q, ~6 l: d! Q& Q, T
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;6 ]) G/ n% c5 _/ q
- GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /* Address lines configuration: A18*/
! y) D u$ a; R3 L. Q' U5 \* a+ Y - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;3 |$ A# M ?6 a
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
c; V$ R; f R& j7 }: E1 J - GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> /*===========GPIO For the Control========================*/
, u+ v4 \" ?4 A Q0 \8 E - /*!< NOE and NWE configuration */
' E# X3 I+ q& A: v4 P - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;6 ^6 E' E& Y5 Y, X( s1 `) ^! }
-
' n# d1 V) ^3 e2 t% I1 u - GPIO_Init(GPIOD, &GPIO_InitStructure); r8 B, O, P& b3 s0 R& n+ B: I1 m7 W
-
) i) y7 ]$ F* _) ^# g f' z1 l - /*!< NE1 configuration */4 v5 p Q0 E G0 g" z+ I7 u
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;+ G% V1 k5 u. z: g3 O9 u
- GPIO_Init(GPIOD, &GPIO_InitStructure);( j5 l3 r4 o* E5 A3 \
-
; a5 b* F4 V; S: k - /*!< NADV configuration */* P0 R7 W2 T: Q/ k
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;" z# y0 ?/ I$ E- V+ a
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
% S4 P) \% X% m- r - #ifdef LCD_USE_TE4 t1 h2 f, A" F& m" B
- /*TE :busy*/2 h$ t& X/ D9 y! Y( t
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;& I+ M0 X+ l: q$ K3 h" o: k' L6 j) f
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 6 Q0 r \; N1 s! H% U5 i
- GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);+ V T4 {4 _/ p/ @% ]9 L9 E
- #endif4 f. L& O& A% k: Z: Y S
- /*!< NBL0, NBL1 configuration */9 ]4 \4 W6 k" O3 J1 F9 M* O
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
0 g/ \- `4 b% D* E - // GPIO_Init(GPIOE, &GPIO_InitStructure);
) a) N7 O: S+ ]6 m - GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=15 B* J" V' z7 y. ]- Q H
- GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);
% F. w7 ?# `' R% P - GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10); " K* s3 T! z+ X
- GPIO_ResetBits(GPIOE, GPIO_Pin_0);9 C1 v I6 Z+ Z' L' k5 `
- GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=0
' I0 c9 r5 R* @/ c - GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1
* t2 u1 x: J$ R* ` - GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1
- }3 I/ i$ B% W/ G; F5 O% ] - /*-- FSMC Configuration ------------------------------------------------------*/% n* J {$ z( ~8 {) H) j* P
- + e: e1 q" l) V, F; c7 f
- /*----------------------- SRAM Bank 1----------------------------------------*/" i3 i% o) D3 R8 r& ?
- /* FSMC_Bank1_NORSRAM1 configuration */6 J3 g) C1 `2 r. \. ^) y9 b
- p.FSMC_AddressSetupTime = 0x02;//1;% O% r. c8 e. h5 j6 ?
- p.FSMC_AddressHoldTime = 0x00;//0;
2 y9 k+ a/ _* L3 |$ \ - p.FSMC_DataSetupTime = 0x05;//5//2;
* I4 A# S9 a* s6 f$ c% V - p.FSMC_BusTurnAroundDuration = 0;% i9 w% `/ y4 O2 G) ]
- p.FSMC_CLKDivision = 0;
k: H* [" N( F, e5 a+ T! A0 B M - p.FSMC_DataLatency = 0;
% R; B4 r3 m) m6 J% N' c0 F! P6 h - p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;
& D2 e, j% I) ^3 Y( D# M - /* Color LCD configuration ------------------------------------) w8 a! |. p: Q0 a, a {
- LCD configured as follow:
5 _$ d9 Y( `/ C4 F& E6 A& r - - Data/Address MUX = Enable9 m) F8 u! B4 p: ~
- - Memory Type = SRAM% M# c- Q9 V( U/ k+ N% s
- - Data Width = 16bit) s% o; G) X. \/ A q
- - Write Operation = Enable+ |' T* H U7 K d" @; d3 x2 D; N) G
- - Extended Mode = Enable
1 c0 _) b! J3 B - - Asynchronous Wait = Disable */. c0 F' x0 d2 Q; l& z4 V
- FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;& v* }! J9 z( N3 @3 ~, c) [& ^# x
- FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; //hy@" G+ k1 c& H* u/ V5 p+ G" @# A. [
- // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable; //hy@ % P- h P: W, H, B, V! m! U. E( z- G- f
- // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
o& P5 e. P3 T9 I6 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;! I$ w1 r6 S; ^- v
- FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
. z o8 Q2 f$ h9 C5 T# {, I - // FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
6 p( q& Z( ?4 W3 Q - FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
( u3 j+ T' O! X t2 S - FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;- P1 w: h/ n6 |1 g! E) M
- FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;" ~' h7 M! k" P9 m7 a: _5 U
- FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
& a- l& e F% V( S - FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;$ O X; q- P* l C
- FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
/ T8 {; O0 O; B' Z L& c+ ? - FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; D, g% d! i5 M# D
- FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;; K2 o8 r' {2 C, T+ C
- FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;3 d. ~6 p# l+ z$ s6 F$ [
- FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
( Q1 X4 m9 f& e& b: ]& M: W. C' H - /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */3 z+ O$ p9 E' A" d, m# B0 M
- FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
. l! G! R5 a' O# j' ^3 F, O& r2 q - }</font></div><font face="Tahoma" color="#000000">
7 W1 e. ?4 G: K! A( Z3 _" k - </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**
: }* l4 u r6 K) h9 _% f1 G- k8 E& ~ - * @brief Initializes the LCD.
- p+ h9 X" ]7 |: d1 c - * @param None
" B+ y* P3 Y) J& t - * @retval None# Z; i* z# f$ |! U4 M4 _7 P
- */+ j/ m. a4 r7 U. G! [* W
- void IzLCDDisplayInit(void)
. I5 q3 b2 m# _" z$ t - {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/
' N0 p, j9 O* o6 N# s O - LCDFSMCConfig();/ a2 q6 y4 ^% @: f
-
1 F, m7 i+ H* h Y3 M& e- J ` - DelayLoop(5); /* delay 50 ms */
- _4 ?9 \6 X4 ?* P2 y- {+ P9 P - //LCD_SetFont(&LCDDEFAULTFONT);
9 n. h+ N8 ]+ \# p - LCDSetFont(&LCDDEFAULTFONT);
, z$ T8 Z6 D1 M/ ] - InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">
( \- q6 t/ K V1 R, j - }</font></div>
复制代码 9 P( j4 z- f5 ^- b6 Q
|