你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32 FSMC TFT LCD

[复制链接]
STMCU小助手 发布时间:2022-1-29 01:04
STM32+SSD1963+TFT(FSMC)已调试通过的代码。
其中要注意的两点:
1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。
 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。 , d- H# i8 U) ^8 g% }7 `+ B
2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。
  1. <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c   -------- STM32F103VCT6 A182 r! W( }) b+ n& g3 W$ \
  2. </font></div><font face="Tahoma" color="#000000">
    % j- \7 d5 `6 s* {0 B
  3. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD  *((volatile u16 *)0X60000000)
    , y, q: N9 F- A' }" R9 N3 R
  4. #define LCD_DATA_ADD  *((volatile u16 *)0X60080000)% }8 L7 M( X2 S8 a+ a: E6 A
  5. </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}4 o: S" }2 o5 U+ u
  6. #define WriteData(data)  {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">
    + e( f& X5 z6 N. `9 m& |
  7. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void)
    5 n) O* T( ?0 h& P
  8. {: h9 T3 c) Q" r1 p1 j
  9.   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;1 W5 q6 c  j9 a6 A7 T
  10.   FSMC_NORSRAMTimingInitTypeDef  p;9 X4 N# z& q; _/ _
  11.   GPIO_InitTypeDef GPIO_InitStructure;
    1 t8 G. d! l+ I0 o
  12. /*-- 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 */) S! I- Y' v" v7 x7 l
  13.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
    4 F1 u0 h, Q3 s
  14.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |& d" E1 ]3 B' O6 W# [
  15.              RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/
    ; j3 S& O; [; D# v. `5 g
  16.   /*  Data /Address lines configuration */
    " J" H! s) Y0 P" g* l! J
  17.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |4 W" W, P7 Y5 U4 a% Y+ m
  18.           GPIO_Pin_14 | GPIO_Pin_15;4 E2 r' t5 S9 [0 K$ B8 v4 e) J; G' Z
  19.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;/ M3 |4 R) I$ H7 Y  u: a7 ~- \% P) Q
  20.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;$ i" a- [/ W6 {" l7 t/ n
  21.   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* M8 z+ m  D
  22.           GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;9 \$ c: k0 W% g. p& I
  23.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      o6 c& j. h& J2 R5 E% Y
  24.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    + G. n, ^7 t4 |$ I: T  N$ N
  25.   GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">  /*  Address lines configuration: A18*/
    ; d! B- F! `! y, o+ S) u
  26.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    : i6 V+ @2 i& I3 n5 c& H, ~* Z7 w9 e
  27.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    * v+ t4 q& K( ]% @0 W' q: A4 v
  28.   GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">  /*===========GPIO For the Control========================*/
    $ V1 j7 f8 C1 K+ {3 y2 y
  29. /*!< NOE and NWE configuration */
    - d7 Y0 T# _8 F4 @+ L
  30. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
    ! e4 W, h1 X- y+ i" Q

  31. ' U* U2 `% T" R5 p! y/ h% G' r
  32. GPIO_Init(GPIOD, &GPIO_InitStructure);. I- \5 U" b& q' w, Y6 k# E

  33. - W2 @3 x8 N; e% p7 T& I/ j
  34. /*!< NE1 configuration */
    & ~8 ?& J3 e1 \; u
  35.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;2 T5 f6 m7 N  z3 K( z( \
  36.     GPIO_Init(GPIOD, &GPIO_InitStructure);
    2 `& ^! d( P+ m9 m/ t- @7 ]
  37. ( |! u- K% a& J  ~
  38. /*!< NADV configuration */! S/ s9 F$ P# L
  39. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;2 j+ y$ {, L& b7 s; Y+ u
  40. // GPIO_Init(GPIOB, &GPIO_InitStructure);
    " h7 L9 E2 i0 l8 B- U  Q" w
  41. #ifdef LCD_USE_TE2 G& Y8 v1 u/ t: R8 }* C
  42. /*TE :busy*/
    + [0 b+ x5 Y* N; S8 e) s
  43.    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
    8 @8 U! n: ^; j/ X6 Y
  44.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; - F3 u) J- e$ d# ]1 P' m5 Y9 }4 c
  45.    GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);3 }* G& w. J& s; G( P
  46.     #endif
    4 m( B7 y  w0 R3 Y; i; Y
  47. /*!< NBL0, NBL1 configuration */
    + c% A& y2 l+ c2 j8 M& F& F) A: A
  48. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
    4 W( L% Z" Q) [3 z' Y! {2 T
  49. // GPIO_Init(GPIOE, &GPIO_InitStructure);/ ^2 s! v+ y) M/ Y( R
  50.   GPIO_SetBits(GPIOD, GPIO_Pin_7);   //CS=11 l, h- H& J( }1 h$ F5 z8 O3 v
  51.   GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);   
    ; g9 l' N( J$ x4 `# p7 t( w
  52.   GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);  
    * b/ L5 r) w. _8 W1 J' a+ Z' s9 U% c
  53.   GPIO_ResetBits(GPIOE, GPIO_Pin_0);
    ! ~% g$ g% R- D8 M
  54.   GPIO_ResetBits(GPIOE, GPIO_Pin_1);   //RESET=0
    $ z9 L9 T* d6 r1 f8 e
  55.   GPIO_SetBits(GPIOD, GPIO_Pin_4);      //RD=1
    ) }5 j9 i! ?' _  _
  56.   GPIO_SetBits(GPIOD, GPIO_Pin_5);   //WR=1    ( E! E( P& b. G% q. k
  57. /*-- FSMC Configuration ------------------------------------------------------*/
    $ |/ B4 O8 m: ~, c5 N9 i! `# |- m

  58. " H6 c8 @( T; k$ f2 @* g0 J' L
  59. /*----------------------- SRAM Bank 1----------------------------------------*/
    1 W9 B) E0 e" K" S1 n! \
  60.   /* FSMC_Bank1_NORSRAM1 configuration */
    7 |/ V" {9 E3 Q: M
  61.   p.FSMC_AddressSetupTime = 0x02;//1;: l2 {% _0 ^3 @' f  W6 \
  62.   p.FSMC_AddressHoldTime = 0x00;//0;3 |5 G$ t$ @' f( n" @0 X& q5 c
  63.   p.FSMC_DataSetupTime = 0x05;//5//2;
    ; `$ |+ K9 S* L9 ]
  64.   p.FSMC_BusTurnAroundDuration = 0;
    3 {4 @/ I! R  u# D+ |3 u% v' |! n
  65.   p.FSMC_CLKDivision = 0;  U. Z) V( e8 z- s' C+ {
  66.   p.FSMC_DataLatency = 0;! P2 b+ Q2 ?) E, n) D  b/ a
  67.   p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;# q& _5 {0 A1 R3 q
  68.   /* Color LCD configuration ------------------------------------
    , r& P5 `% [$ {/ k4 P! ]" Z; G
  69.      LCD configured as follow:
    . o1 W3 \' J4 K0 D6 g
  70.         - Data/Address MUX = Enable
    0 U& J3 a; |! L; G
  71.         - Memory Type = SRAM
    # u$ G+ j* L0 g% @# h/ Q- R
  72.         - Data Width = 16bit( ]7 _8 Q/ s/ q2 J* L
  73.         - Write Operation = Enable. E2 k9 K" ]( @7 {9 c
  74.         - Extended Mode = Enable* N6 ?+ s8 v6 F- B0 q
  75.         - Asynchronous Wait = Disable */" O6 p* }1 j' ?
  76.   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;" ]2 S6 Q2 J# e# ^& K5 ?% x
  77.   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;  //hy@
    3 v2 Q( S4 B7 X
  78. // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;  //hy@ ( U1 o2 n/ a  \6 i: E. G
  79. // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
    : ?( k$ g9 @# ~/ E# j
  80.   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;9 c1 W  I& o5 H: b) A# f, V. h8 y; E
  81.   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;, A( k8 q9 ^, h. z9 n7 b4 B) y
  82. //  FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; . n4 p& {0 r% {# V; \  v0 T
  83.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
    6 g- F- f: J" j, F5 i  P1 ?
  84.   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;  E$ g% ~9 |5 `; z- W, P- }
  85.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
    # K% k6 _& M/ a
  86.   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
    ' j# I% }9 v; }3 P/ J" u
  87.   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;* c6 l8 v3 K' }5 z% \) O
  88.   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;/ O+ [: `! d# C/ S$ o/ A; U, `& m9 e0 j
  89.   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;' M6 G# S" r7 w5 f
  90.   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
    0 F+ Z! o' ^. s
  91.   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
    9 `+ `* O, w$ \7 m# F* K7 O
  92.   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
    / Y& C: T8 r3 J2 ^9 e5 I
  93.   /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */+ s) G( v9 c1 F+ K
  94.   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);4 [) S  j; }* \: u
  95. }</font></div><font face="Tahoma" color="#000000">
    " K% r: A8 _# ~: F6 }/ M+ l0 Y. s
  96. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**! \! g9 x  F6 p8 A7 L" I
  97.   * @brief  Initializes the LCD.
    # r0 Q8 w" G  y0 ~9 C8 ?8 ?6 l
  98.   * @param  None$ b% q  x7 u% x
  99.   * @retval None# [7 x; x$ C1 @, r
  100.   */
    2 J% k  r2 U. b$ R
  101. void IzLCDDisplayInit(void). M/ t2 X7 q) N1 A" \# ]9 i- ?
  102. {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/1 ^: \4 ^) B7 _, s& U, ]9 H: D" G: s
  103.   LCDFSMCConfig();7 Y3 Q& y1 g4 p& I9 B" i& u

  104. ) n) x$ C% r4 ~6 y
  105.   DelayLoop(5); /* delay 50 ms */) O( H1 _2 W  W4 h3 h4 ]% \/ X+ {
  106.   //LCD_SetFont(&LCDDEFAULTFONT);
    ' p1 }; n( J5 h; T% X
  107.   LCDSetFont(&LCDDEFAULTFONT);( y1 S2 }# q7 t
  108.   InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">- `, N, c% \. Y& t( `$ Q- q
  109. }</font></div>
复制代码
/ Z0 Q  t9 q% [
赞 收藏 评论0 发布时间:2022-1-29 01:04

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版