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

【经验分享】STM32 FSMC TFT LCD

[复制链接]
STMCU小助手 发布时间:2022-1-29 01:04
STM32+SSD1963+TFT(FSMC)已调试通过的代码。
其中要注意的两点:
1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。
 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。 ( [6 A( l5 s9 z" O. c
2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。
  1. <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
  2. </font></div><font face="Tahoma" color="#000000">
    . x8 [5 `# p: n4 }
  3. </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
  4. #define LCD_DATA_ADD  *((volatile u16 *)0X60080000)
    & M9 e: S) _# B5 b
  5. </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 @
  6. #define WriteData(data)  {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">
    / ]; @7 l- h5 D# M6 q
  7. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void)
    ; ]; M0 L8 V( @" p
  8. {( a# B; e+ v+ b$ H2 Z4 n
  9.   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
    9 D# _$ y3 t  d8 J) F5 T& G4 H
  10.   FSMC_NORSRAMTimingInitTypeDef  p;
    " v! o" L+ @& t+ l" b
  11.   GPIO_InitTypeDef GPIO_InitStructure;) q; k2 E4 H/ T: x. t" w7 t# I* E8 V3 D
  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 */4 \0 |* F: K: B6 L  j
  13.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);, j" ^0 ^6 K8 i, V
  14.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |  v" |* C1 [3 w- c' U, Z
  15.              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
  16.   /*  Data /Address lines configuration *// x7 G: `1 V: J9 }& V0 u
  17.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |# e! B: ^0 P% q
  18.           GPIO_Pin_14 | GPIO_Pin_15;  o  }3 U5 m+ s1 i9 Z
  19.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;7 r& I* P+ Z: N' j- b3 ^
  20.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    ; b0 c& G; B# y8 e. @' Y" u
  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 |* n7 W" [9 ?$ h1 n# `5 Y) Z9 a
  22.           GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;8 p2 A8 r1 e( d; N
  23.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    ; C7 T9 A0 F* D7 w  \
  24.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    " o) v/ k8 k, G. U
  25.   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
  26.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;6 {+ t! i& q! F* G0 N, i! K
  27.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; ! A5 r: @! P, z! e" s9 b! r$ [5 B
  28.   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' ]  }
  29. /*!< NOE and NWE configuration */ . M9 H9 @6 c. W- b: d% A) ^
  30. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
    ' r! e- {3 u4 b# b+ @
  31. ! o% N- X' D) E3 Q: q) Z0 J& I- O. y
  32. GPIO_Init(GPIOD, &GPIO_InitStructure);3 z3 ^: p/ {) o) d6 D$ B: D

  33. ' |* v7 g! j( x& h9 [  Y# Q- r$ Z
  34. /*!< NE1 configuration */
    & C  p3 c2 H+ x! C4 z5 ?
  35.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    2 q4 b& i1 R$ K7 c0 e# Q% r( ~
  36.     GPIO_Init(GPIOD, &GPIO_InitStructure);
    2 |& t! l' i' Z5 z* r' }* ^
  37. / b: V; Y" S* g+ j. i7 t; u
  38. /*!< NADV configuration */
    0 t. R$ ]) k' a, s' `- T+ j; f
  39. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;) N  }- D: u( a5 }, q
  40. // GPIO_Init(GPIOB, &GPIO_InitStructure);
    , x9 Y4 v0 ]7 h' b5 N* a; v) _0 c  o
  41. #ifdef LCD_USE_TE
    6 u$ k; W, ]6 M. c6 J
  42. /*TE :busy*/1 }  l. B: w4 K' i1 n
  43.    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
    5 Z; O3 o. A- r; e9 e( D4 j
  44.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; * a! x% i7 ^  C( o1 T2 @) |2 f2 b6 f
  45.    GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);9 ^3 i7 i2 F* c$ M! M% ]
  46.     #endif
    # d! ?; f8 ]" u9 C; _
  47. /*!< NBL0, NBL1 configuration */6 P' G- }8 j: L1 v8 e) ?6 C
  48. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;, t8 [, |1 @4 B, o  ~
  49. // GPIO_Init(GPIOE, &GPIO_InitStructure);
    % F+ }  a# V- _- A! ~: Y, j
  50.   GPIO_SetBits(GPIOD, GPIO_Pin_7);   //CS=1
    ' c  {: D, W; h7 n, E7 d" w9 _
  51.   GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);   $ B& ^1 P  M7 i1 R
  52.   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
  53.   GPIO_ResetBits(GPIOE, GPIO_Pin_0);
    3 O; Q8 ~" t0 n% I) q
  54.   GPIO_ResetBits(GPIOE, GPIO_Pin_1);   //RESET=07 T4 p3 v* a* {5 s. O; o5 ?  [
  55.   GPIO_SetBits(GPIOD, GPIO_Pin_4);      //RD=1
    2 l9 Z* B3 v* `% E. u+ r! q
  56.   GPIO_SetBits(GPIOD, GPIO_Pin_5);   //WR=1   
    / H8 d8 R6 e- t/ N, B5 J
  57. /*-- FSMC Configuration ------------------------------------------------------*/9 w/ K, e3 r- Y! |
  58. ! \. n5 B  z  D- ~) s
  59. /*----------------------- SRAM Bank 1----------------------------------------*/* x3 ^% {" V$ U
  60.   /* FSMC_Bank1_NORSRAM1 configuration */+ Z9 u* o4 l2 h1 S
  61.   p.FSMC_AddressSetupTime = 0x02;//1;
    ' o' v; G! B# B: e2 j! C4 l
  62.   p.FSMC_AddressHoldTime = 0x00;//0;# O$ x* I, R* f: G* q/ f" ]
  63.   p.FSMC_DataSetupTime = 0x05;//5//2;& W7 J% D- A' [6 e
  64.   p.FSMC_BusTurnAroundDuration = 0;
    - U+ \  P* x/ q0 |
  65.   p.FSMC_CLKDivision = 0;
    7 E$ s9 F" _1 X' }; L; A; Q& n
  66.   p.FSMC_DataLatency = 0;7 i5 A6 H) J  e% H
  67.   p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;# L/ T1 ~0 ~* s4 W& J
  68.   /* Color LCD configuration ------------------------------------/ T& H3 b( l0 u- ?% k+ }3 T: u1 @! y
  69.      LCD configured as follow:
    : g- d5 h" }/ P" ]
  70.         - Data/Address MUX = Enable
    # H7 Z/ b" T1 d/ c. Y
  71.         - Memory Type = SRAM1 V- K7 H6 x9 T# i+ d, l
  72.         - Data Width = 16bit3 Q  Z. y8 H' j9 v6 _# s8 ?
  73.         - Write Operation = Enable4 ~) j5 p# g. P  B+ q: G3 l# ?+ ?
  74.         - Extended Mode = Enable
    ; A) U% E* K- L- ]  C
  75.         - Asynchronous Wait = Disable */
    . T% a9 O5 j6 @4 q2 j( A
  76.   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
    * k2 t1 B1 S+ m! U7 ?
  77.   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;  //hy@
    + z  T: ]8 T# k' ^
  78. // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;  //hy@ ! X1 ~7 S% N( @2 H: Q) O% g
  79. // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
    " K7 q4 g8 i7 N% F# ~
  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;( i% O) V7 M4 `* \. v. l) C# S
  81.   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
    - U& O, ?0 W; K, T
  82. //  FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 6 N, P" E  i+ c" {
  83.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;2 O1 d5 [$ |' [2 B& s- ?: m  ^
  84.   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
    / Q; j& ~+ z5 Y$ I
  85.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;$ V4 C8 d2 b2 J' ~7 _! W9 h
  86.   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
    % V& g/ c! x& r/ m. G1 s% }9 h. i
  87.   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
    ! I3 E& N2 s2 f  B
  88.   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
    3 `" e4 M+ g& q) J0 I8 q
  89.   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;- m7 S  Y3 U! r3 T4 d1 @: Q4 q
  90.   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
    ! Y# K" j+ e; J- k+ {
  91.   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;1 q) |. R, l  b2 O" N, P8 U' s* O
  92.   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
    ; B# n5 Z" U1 h, q- p; v
  93.   /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
    5 b* h& T' J7 b- o
  94.   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
    1 B7 Z' f- n  i" a: E' e1 p
  95. }</font></div><font face="Tahoma" color="#000000">
    9 n9 I- N5 s9 k" j, _6 J, I
  96. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**
    # G& Z; `7 F; N8 \* C: x/ ?( K
  97.   * @brief  Initializes the LCD.' y& H$ H: Y7 {; g
  98.   * @param  None
    , T; v& a- y4 w- x: B; S3 l/ Z
  99.   * @retval None- N; y/ q! k  f$ q0 F. h: v, Z
  100.   */
      T  N; M. R+ [4 o; R% ]
  101. void IzLCDDisplayInit(void)- b" X) w- q2 B
  102. {</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
  103.   LCDFSMCConfig();
    # q1 v! s2 E" {9 T- m

  104. , w- z* r2 a9 V* h# R6 E$ t0 ^
  105.   DelayLoop(5); /* delay 50 ms */
    5 |" Y3 R; _2 u( d3 |8 Q, A
  106.   //LCD_SetFont(&LCDDEFAULTFONT);8 l8 s0 j; q- Y1 k# u3 m. _: ^
  107.   LCDSetFont(&LCDDEFAULTFONT);" ^; o9 X2 g7 m9 x- ?
  108.   InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">3 J2 l( E; t- z6 D' z' w
  109. }</font></div>
复制代码
" V$ |8 ^1 v; j" X
收藏 评论0 发布时间:2022-1-29 01:04

举报

0个回答

所属标签

相似技术帖

官网相关资源

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