fmt0371.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include "fmt0371.h"
  2. #include "stm32f10x.h"
  3. #define FSMC_GPIO_CONFIG
  4. //static void delay_ms(unsigned int dt)
  5. //{
  6. // volatile unsigned int u;
  7. // for (u=0;u<dt*30;u++);
  8. //}
  9. static void FSMC_Init(void)
  10. {
  11. FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
  12. FSMC_NORSRAMTimingInitTypeDef p;
  13. //
  14. //#ifdef FSMC_GPIO_CONFIG
  15. // GPIO_InitTypeDef GPIO_InitStructure;
  16. //
  17. // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE |
  18. // RCC_APB2Periph_GPIOF, ENABLE);
  19. //
  20. // /*-- GPIO Configuration ------------------------------------------------------*/
  21. // /* SRAM Data lines configuration */
  22. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
  23. // GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
  24. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  25. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  26. // GPIO_Init(GPIOD, &GPIO_InitStructure);
  27. //
  28. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
  29. // GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
  30. // GPIO_Pin_15;
  31. // GPIO_Init(GPIOE, &GPIO_InitStructure);
  32. //
  33. // /* SRAM Address lines configuration */
  34. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  35. // GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
  36. // GPIO_Pin_14 | GPIO_Pin_15;
  37. // GPIO_Init(GPIOF, &GPIO_InitStructure);
  38. //
  39. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  40. // GPIO_Pin_4 | GPIO_Pin_5;
  41. // GPIO_Init(GPIOG, &GPIO_InitStructure);
  42. //
  43. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  44. // GPIO_Init(GPIOD, &GPIO_InitStructure);
  45. //
  46. // /* NOE and NWE configuration */
  47. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
  48. // GPIO_Init(GPIOD, &GPIO_InitStructure);
  49. //
  50. // /* NE2 configuration */
  51. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
  52. // GPIO_Init(GPIOG, &GPIO_InitStructure);
  53. //
  54. // /* NBL0, NBL1 configuration */
  55. // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  56. // GPIO_Init(GPIOE, &GPIO_InitStructure);
  57. //#endif
  58. /*-- FSMC Configuration ------------------------------------------------------*/
  59. p.FSMC_AddressSetupTime = 2; // safe value 2
  60. p.FSMC_AddressHoldTime = 1; // safe value 2
  61. p.FSMC_DataSetupTime = 3; // safe value 5
  62. p.FSMC_BusTurnAroundDuration = 0;
  63. p.FSMC_CLKDivision = 0;
  64. p.FSMC_DataLatency = 0;
  65. p.FSMC_AccessMode = FSMC_AccessMode_A;
  66. FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2;
  67. FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  68. FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  69. FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  70. FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  71. FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  72. FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  73. FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  74. FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  75. FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  76. FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  77. FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  78. FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  79. FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
  80. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  81. /* Enable FSMC Bank1_SRAM Bank */
  82. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE);
  83. }
  84. void ftm0371_port_init(void)
  85. {
  86. // GPIO_InitTypeDef GPIO_InitStructure;
  87. //
  88. // RCC_APB2PeriphClockCmd(LCD_RST_RCC, ENABLE);
  89. // GPIO_InitStructure.GPIO_Pin = LCD_RST_PIN;
  90. // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  91. // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  92. // GPIO_Init(LCD_RST_PORT, &GPIO_InitStructure);
  93. // LCD_RST_0; // reset the lcd
  94. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  95. FSMC_Init();
  96. }
  97. //初始化函数
  98. void ftm0371_init(void)
  99. {
  100. // LCD_RST_1;
  101. // delay_ms(1000);
  102. //initializing funciton 1
  103. LCD_WR_REG(0xA1);
  104. LCD_WR_DATA8(0x00);
  105. LCD_WR_REG(0xA0);
  106. LCD_WR_DATA8(0x00);
  107. LCD_WR_CMD(0,0x70,0xC8);
  108. LCD_WR_CMD(0,0x72,0xA3);
  109. LCD_WR_CMD(0,0x73,0x04);
  110. LCD_WR_CMD(0,0x75,0x45);
  111. LCD_WR_CMD(0,0x76,0x23);
  112. LCD_WR_CMD(0,0x77,0x08);
  113. LCD_WR_CMD(0,0x78,0x08);
  114. LCD_WR_CMD(0,0x79,0x00);
  115. LCD_WR_CMD(0,0x7F,0xF0);
  116. LCD_WR_CMD(0,0x71,0x81); //
  117. LCD_WR_CMD(0,0x0D,0x23);
  118. LCD_WR_CMD(0,0x11,0x00);
  119. LCD_WR_CMD(0,0x12,0x00);
  120. LCD_WR_CMD(0,0x21,0x37);
  121. LCD_WR_CMD(0,0x22,0x02);
  122. LCD_WR_CMD(0,0x23,0x24);
  123. LCD_WR_CMD(0,0x24,0x13);
  124. LCD_WR_CMD(0,0x25,0x0A);
  125. LCD_WR_CMD(0,0x26,0x82);
  126. LCD_WR_CMD(0,0x27,0x01);
  127. LCD_WR_CMD(0,0x1E,0x25);
  128. LCD_WR_CMD(0,0x1F,0x59);
  129. //GAMMA设置
  130. LCD_WR_CMD(1,0x30,0x0777);
  131. LCD_WR_CMD(1,0x31,0x0444);
  132. LCD_WR_CMD(1,0x32,0x0555);
  133. LCD_WR_CMD(1,0x33,0x0444);
  134. LCD_WR_CMD(1,0x34,0x0333);
  135. LCD_WR_CMD(1,0x35,0x0333);
  136. LCD_WR_CMD(1,0x36,0x0333);
  137. LCD_WR_CMD(1,0x37,0x0333);
  138. LCD_WR_CMD(1,0x38,0x0444);
  139. LCD_WR_CMD(1,0x39,0x0555);
  140. LCD_WR_CMD(1,0x3A,0x0666);
  141. LCD_WR_CMD(1,0x3B,0x0666);
  142. LCD_WR_CMD(1,0x3C,0x0777);
  143. LCD_WR_CMD(1,0x3D,0x0777);
  144. LCD_WR_CMD(1,0x3E,0x0777);
  145. LCD_WR_CMD(1,0x3F,0x0777);
  146. LCD_WR_CMD(1,0x40,0x0777);
  147. LCD_WR_CMD(1,0x41,0x0777);
  148. LCD_WR_CMD(1,0x42,0x0777);
  149. LCD_WR_CMD(1,0x43,0x0777);
  150. LCD_WR_CMD(1,0x44,0x0777);
  151. LCD_WR_CMD(1,0x45,0x0777);
  152. LCD_WR_CMD(1,0x46,0x0777);
  153. LCD_WR_CMD(1,0x47,0x0777);
  154. LCD_WR_CMD(1,0x48,0x0777);
  155. LCD_WR_CMD(1,0x49,0x0777);
  156. LCD_WR_CMD(1,0x4A,0x0777);
  157. LCD_WR_CMD(1,0x4B,0x0777);
  158. LCD_WR_CMD(1,0x4C,0x0777);
  159. LCD_WR_CMD(1,0x4D,0x0666);
  160. LCD_WR_CMD(1,0x4E,0x0666);
  161. LCD_WR_CMD(1,0x4F,0x0666);
  162. LCD_WR_CMD(0,0x00,0x04); //扫描方向控制
  163. LCD_WR_CMD(0,0x01,0x07); //扫描方向控制
  164. LCD_WR_CMD(0,0x02,0x00); //X
  165. LCD_WR_CMD(1,0x03,0x0000); //Y
  166. //面板大小设置
  167. LCD_WR_CMD(0,0x04,0xEF); //结束列数(0~239)
  168. LCD_WR_CMD(1,0x05,0x013F); //结束行数(0~319)
  169. //窗口设置
  170. LCD_WR_CMD(0,0x06,0x00); //水平起始位置
  171. LCD_WR_CMD(1,0x07,0x0000); //垂直起始位置
  172. LCD_WR_CMD(0,0x08,0xEF); //水平结束位置
  173. LCD_WR_CMD(1,0x09,0x013F); //垂直结束位置
  174. LCD_WR_CMD(0,0x0A,0x00);
  175. LCD_WR_CMD(0,0x0B,0x00);
  176. LCD_WR_CMD(0,0x0C,0x00);
  177. LCD_WR_CMD(0,0x14,0x00);
  178. LCD_WR_CMD(0,0x15,0x00);
  179. LCD_WR_CMD(0,0x16,0x00);
  180. LCD_WR_CMD(1,0x17,0x01FF);
  181. LCD_WR_CMD(1,0x18,0x01FF);
  182. LCD_WR_CMD(0,0x13,0x00);
  183. LCD_WR_CMD(1,0x19,0x01FF);
  184. LCD_WR_CMD(1,0x1B,0x01FF);
  185. LCD_WR_CMD(1,0x1C,0x01FF);
  186. LCD_WR_CMD(1,0x1A,0x01FF);
  187. LCD_WR_CMD(0,0x1D,0x0E);
  188. LCD_WR_CMD(0,0x10,0x06); //开显示
  189. LCD_WR_REG(0x0E);
  190. }