fmt0371.c 7.1 KB

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