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

【经验分享】STM32 FSMC TFT LCD

[复制链接]
STMCU小助手 发布时间:2022-1-29 01:04
STM32+SSD1963+TFT(FSMC)已调试通过的代码。
其中要注意的两点:
1.外部访问地址需加volatile,否则keil MDK 优化会将部分代码优化掉,造成错误。
 volatile关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编译器未知的因素更改,比如:操作系统、硬件或者其它线程等。遇到这个关键字声明的变量,编译器对访问该变量的代码就不再进行优化,从而可以提供对特殊地址的稳定访问。
; p5 ?$ Q* J3 D( g' c2. FSMC内部地址和外部实际地址有区别。如A18连线对应内部地址是A19。
  1. <div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">// ssd1963 #d/c   -------- STM32F103VCT6 A18: e# n* p4 o# M! O6 O: d
  2. </font></div><font face="Tahoma" color="#000000">' b( [( Y! s4 j: p% V6 j+ i
  3. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">#define LCD_COMM_ADD  *((volatile u16 *)0X60000000)
      f" }% Z, p+ Q# P2 [/ r; U
  4. #define LCD_DATA_ADD  *((volatile u16 *)0X60080000)' i6 t1 j& [/ \+ N7 N
  5. </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000"> #define WriteCommand(cmd) {LCD_COMM_ADD = cmd;}
    6 n! \! E3 }3 }7 |+ i: W
  6. #define WriteData(data)  {LCD_DATA_ADD = data;}</font></div><font face="Tahoma" color="#000000">. r2 K( Z2 H2 |, \5 W: N  B
  7. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">void LCDFSMCConfig(void). a5 q. Y8 T' a' C$ N. d
  8. {0 I8 h+ n  j% \) i' L6 I; Z
  9.   FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;4 x/ B7 P) r, |# B0 W
  10.   FSMC_NORSRAMTimingInitTypeDef  p;& q: B+ a) Y4 n  A9 g  w
  11.   GPIO_InitTypeDef GPIO_InitStructure;- [4 |9 ]; {& ^8 w
  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 */; N% m7 H% u1 J! x& G& W: R) }
  13.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
    1 s: C$ p+ V" m% S( \7 ]2 C. e
  14.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
    # P! x9 B2 k0 O4 B$ S  j8 i! Q
  15.              RCC_APB2Periph_AFIO, ENABLE);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/*===========GPIO For the LCD_Bus========================*/ / U4 O. C! L( ^8 i
  16.   /*  Data /Address lines configuration */8 U. l2 g* e: ]& ?; F& Y3 t
  17.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |$ i) ]# N4 Y) [, h# I
  18.           GPIO_Pin_14 | GPIO_Pin_15;
    6 R; |# w* O* n
  19.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    7 U" F# \0 ~# a% M, a- U9 u# A) ]
  20.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    ' K7 H7 m# U7 |0 s
  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 |
    ; _  [! E4 Z8 b. t% f  F
  22.           GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;1 t+ o+ X- s  X$ U- W$ ?/ j
  23.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;- ^5 ^/ e- Z% F( s" a4 `
  24.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    ) d8 G; `4 B6 {1 [* e2 G
  25.   GPIO_Init(GPIOE, &GPIO_InitStructure);</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">  /*  Address lines configuration: A18*/0 M1 \7 O7 t$ l) r* b
  26.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
    % S( n$ j  s8 Q2 P
  27.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    1 ]* s. |: }, i# ^) B# H
  28.   GPIO_Init(GPIOD, &GPIO_InitStructure); </font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">  /*===========GPIO For the Control========================*/
    . B, N6 Z* S, n7 M. A
  29. /*!< NOE and NWE configuration */
    " b9 p: g. V7 X! y5 C, A
  30. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
    + P1 h& n. Z+ C2 S* E; P- P  Z

  31. / B1 U' A6 S. a1 x7 K1 d7 z
  32. GPIO_Init(GPIOD, &GPIO_InitStructure);
    : ~6 p5 G9 t( u5 _3 D
  33. $ d2 W' U, x5 v
  34. /*!< NE1 configuration */
    4 |# R7 U. S' w. R1 J( a& R- T
  35.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    . m! s! U/ F' E6 m4 g
  36.     GPIO_Init(GPIOD, &GPIO_InitStructure);
    4 Y' L6 W, J) i) a8 e8 y/ q6 ?
  37. 7 F3 b7 B: a6 ]. e( j
  38. /*!< NADV configuration */; p+ O7 i# S: w+ `: d' Q
  39. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    ! {% h0 t, ]7 f; W- w8 m2 V
  40. // GPIO_Init(GPIOB, &GPIO_InitStructure);, n- `3 n$ @- E8 t
  41. #ifdef LCD_USE_TE
      d7 F, m, x0 t6 n& V
  42. /*TE :busy*/. v, e+ f3 e( O6 ~
  43.    GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LCD_TE;
    * `3 A6 K2 {! p' q7 I0 U
  44.    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    , |1 B2 |# C: `
  45.    GPIO_Init(GPIO_PORT_LCD_TE, &GPIO_InitStructure);
    9 O5 K, C3 i5 K+ z8 c/ o/ X4 K
  46.     #endif
    ! g) M& \2 r/ m7 l/ a% [% o
  47. /*!< NBL0, NBL1 configuration */
    2 ?" u! o% i" p. m8 L  j
  48. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
    4 [! w5 Q6 c, h$ n1 G. R2 N: U/ O
  49. // GPIO_Init(GPIOE, &GPIO_InitStructure);3 j, p  {$ O* ]9 X9 b8 I
  50.   GPIO_SetBits(GPIOD, GPIO_Pin_7);   //CS=1
    , M; s8 o+ I9 k! F5 H) o
  51.   GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);   
    % V- q2 d: y- q+ V* ^
  52.   GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);  
    3 D) T( G' F. M5 B. z. ]7 L
  53.   GPIO_ResetBits(GPIOE, GPIO_Pin_0);! r3 q; H# e' [* B
  54.   GPIO_ResetBits(GPIOE, GPIO_Pin_1);   //RESET=05 K0 m* D& E! t6 O# u0 Z  p$ w
  55.   GPIO_SetBits(GPIOD, GPIO_Pin_4);      //RD=1
    7 i& x/ V8 T6 W& v9 ~: v) ]
  56.   GPIO_SetBits(GPIOD, GPIO_Pin_5);   //WR=1    / G0 x  K9 _/ E1 }
  57. /*-- FSMC Configuration ------------------------------------------------------*/. b7 {: q* T$ V' A% p) g7 C
  58. " K; w' Q% D( M, ?( L
  59. /*----------------------- SRAM Bank 1----------------------------------------*/3 r- e# d+ |, `( {  |
  60.   /* FSMC_Bank1_NORSRAM1 configuration */3 l8 ]0 ~% ~( {/ n9 S- P9 ^
  61.   p.FSMC_AddressSetupTime = 0x02;//1;
    - y: F7 g9 v6 _( u5 }+ R4 {
  62.   p.FSMC_AddressHoldTime = 0x00;//0;" D9 L: b7 E. v/ T3 _
  63.   p.FSMC_DataSetupTime = 0x05;//5//2;% V: [/ g4 q9 m+ A$ n  c
  64.   p.FSMC_BusTurnAroundDuration = 0;+ R; G- v& W2 J. d5 O8 C# p3 g# f
  65.   p.FSMC_CLKDivision = 0;& l' r" y% T3 i0 i# P$ d
  66.   p.FSMC_DataLatency = 0;9 }; y" z- p; D" _" _% k7 }& Q
  67.   p.FSMC_AccessMode = FSMC_AccessMode_B;//FSMC_AccessMode_A;) e/ ^$ n3 T' Y; ^# P6 y
  68.   /* Color LCD configuration ------------------------------------
    & E$ E. [% E$ r( t6 Y' l/ p
  69.      LCD configured as follow:
    8 T: s. s( r4 x. t
  70.         - Data/Address MUX = Enable, d; q% h  D3 a( b. l
  71.         - Memory Type = SRAM
    & X9 ^/ P$ Y# f3 _
  72.         - Data Width = 16bit9 G+ L8 Z4 C' O4 u' x5 M" n
  73.         - Write Operation = Enable# D) V: S/ w+ `9 P3 g+ |% W) ^. \* w
  74.         - Extended Mode = Enable
    7 `$ {% X) z( v) G0 H
  75.         - Asynchronous Wait = Disable */
    8 `8 ^; C/ l1 q  W# c
  76.   FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;! o+ K0 O; M  i; a: ~
  77.   FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;  //hy@
    " L& u# Y0 l7 W$ b
  78. // FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Enable;  //hy@ - f" S; C6 c. n% ]6 v* p
  79. // FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;//FSMC_MemoryType_NOR;//FSMC_MemoryType_SRAM;//
    1 e/ R/ l; m# s
  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;- \, K0 T6 K7 ~; Q
  81.   FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
    2 c3 B, W3 r( }+ ^' n3 C; z
  82. //  FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; 0 X4 w0 h. `8 `; S& q
  83.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;; f: g) _4 L/ I2 b6 t+ b! f
  84.   FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
    ; U) b- ~4 R( x7 t
  85.   FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
    $ R7 t- T1 s3 e# r8 S4 \
  86.   FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;: [$ X1 E0 Q5 s( ]5 A" s. B
  87.   FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
    / ^' n* r% m9 A/ X" ?
  88.   FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
    ' N0 m& `9 l- U% p; u
  89.   FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
    " z& \# `. Q+ r7 |, K5 A/ L
  90.   FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;) ^* f2 q7 W; o( r! b
  91.   FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
    - T; D, e+ E: I5 `+ O$ z$ v
  92.   FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
    3 X3 M4 l7 E6 _/ I3 g
  93.   /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
    $ W7 {% J5 X4 x& i6 f$ x* L
  94.   FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);, g; T( P# K( o' [5 o/ B6 ?
  95. }</font></div><font face="Tahoma" color="#000000">
    & X* J! m1 j1 u+ J: ~7 I
  96. </font><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/**8 A, S& L1 I5 U' _0 U* N
  97.   * @brief  Initializes the LCD.
    1 D$ w  ?/ L# z9 p* ?9 b
  98.   * @param  None
    2 {, N3 R% y$ ^( o8 L: }
  99.   * @retval None
    . e8 d% V! z2 l: B/ l6 R% N) [
  100.   */
    " m3 O, R' l# A  @1 l- j0 w
  101. void IzLCDDisplayInit(void)2 ~8 X, |; v& t& y3 ^& N) _
  102. {</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">/* Configure the FSMC Parallel interface -------------------------------------*/
    % G4 \% P0 ^+ M. ?3 u: }" c, n" W! v. x
  103.   LCDFSMCConfig();. x8 s) Z! g  R9 ?8 H

  104. 4 l& ^5 H- X3 j/ G: `. v8 V
  105.   DelayLoop(5); /* delay 50 ms */2 b! V& U9 j) `" r6 A; M/ t
  106.   //LCD_SetFont(&LCDDEFAULTFONT);
    7 F4 h# M/ W% I: x6 U7 d6 L
  107.   LCDSetFont(&LCDDEFAULTFONT);
    - z: n$ @1 {+ f- \. W: W0 V
  108.   InitSSD1963();</font></div><div align="left"><font style="font-size: 13px" face="Tahoma" color="#000000">7 W( H7 ~* Y, I% B
  109. }</font></div>
复制代码
. u. U- ^5 A3 J4 j
赞 收藏 评论0 发布时间:2022-1-29 01:04

举报

0个回答

所属标签

相似技术帖

官网相关资源

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