main.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #ifndef __MAIN_H_
  2. #define __MAIN_H_
  3. #include "stm32f10x_conf.h"
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdbool.h>
  7. #include <string.h>
  8. #include <math.h>
  9. #include "sys.h"
  10. //功能配置
  11. #if defined (STM32F10X_VET6_DEF)
  12. #define SYSLed_def (1)
  13. #define key16_def (0)
  14. #define Solen_def (1)
  15. #define LCD_def (1)
  16. #define Pull_up_down_def (0)
  17. #define DS1302_def (1)
  18. #define TEA5767_def (0)
  19. #define DHT11_def (1)
  20. #define WIFI_Uart1_def (1)
  21. #define xy5200_Uart2_def (1)
  22. #define SPI1_DMA_SD_def (1)
  23. #define UART1_SD_def (0)
  24. #define SPI2_DMA_SD_def (0)
  25. //wifi注册ID\服务器ID\目标ID
  26. #define SERVER_ID 0x00
  27. #define REGMY_ID 0x03
  28. #define AIM_ID 0x02
  29. #elif defined (STM32F10X_C8T6_DEF)
  30. #define SYSLed_def (0)
  31. #define key16_def (0)
  32. #define Solen_def (1)
  33. #define LCD_def (1)
  34. #define Pull_up_down_def (0)
  35. #define DS1302_def (0)
  36. #define TEA5767_def (0)
  37. #define DHT11_def (1)
  38. #define WIFI_Uart1_def (1)
  39. #define xy5200_Uart2_def (0)
  40. #define SPI1_DMA_SD_def (1)
  41. #define UART1_SD_def (0)
  42. #define SPI2_DMA_SD_def (0)
  43. //wifi注册ID\服务器ID\目标ID
  44. #define SERVER_ID 0x00
  45. #define REGMY_ID 0x04
  46. #define AIM_ID 0x02
  47. #endif
  48. /*SYSLed_def*/
  49. #define LED_RCC_CONFIG (RCC_APB2Periph_GPIOC)
  50. #define LED_PORT_CONFIG (GPIOC)
  51. #define LED_PIN_CONFIG (GPIO_Pin_7)
  52. //GPIO_Pin_6已经 用作wifi信号led
  53. #define LED_PC7_LOW() (GPIO_ResetBits(LED_PORT_CONFIG, LED_PIN_CONFIG))
  54. #define LED_PC7_HIGH() (GPIO_SetBits(LED_PORT_CONFIG, LED_PIN_CONFIG))
  55. /*key16_def*/
  56. #define KEY16_RCC_CONFIG (RCC_APB2Periph_GPIOA)
  57. #define KEY16_PORT_CONFIG (GPIOA)
  58. #define KEY16_OUTPIN_CONFIG (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3)
  59. #define KEY16_INPIN_CONFIG (GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7)
  60. /*Solen_def*/
  61. //E8 E9 ->B2
  62. #if defined (STM32F10X_VET6_DEF)
  63. #define SOLEN_RCC_CONFIG (RCC_APB2Periph_GPIOE)
  64. #define SOLEN_PORT_CONFIG (GPIOE)
  65. #define SOLEN_PIN_CONFIG (GPIO_Pin_8|GPIO_Pin_9)
  66. #define SOLEN_PE8_LOW() (GPIO_ResetBits(SOLEN_PORT_CONFIG, GPIO_Pin_8))
  67. #define SOLEN_PE8_HIGH() (GPIO_SetBits(SOLEN_PORT_CONFIG, GPIO_Pin_8))
  68. #define SOLEN_PE9_LOW() (GPIO_ResetBits(SOLEN_PORT_CONFIG, GPIO_Pin_9))
  69. #define SOLEN_PE9_HIGH() (GPIO_SetBits(SOLEN_PORT_CONFIG, GPIO_Pin_9))
  70. #elif defined (STM32F10X_C8T6_DEF)
  71. #define SOLEN_RCC_CONFIG (RCC_APB2Periph_GPIOB)
  72. #define SOLEN_PORT_CONFIG (GPIOB)
  73. #define SOLEN_PIN_CONFIG (GPIO_Pin_2)
  74. #define SOLEN_PE8_LOW() (GPIO_ResetBits(SOLEN_PORT_CONFIG, SOLEN_PIN_CONFIG))
  75. #define SOLEN_PE8_HIGH() (GPIO_SetBits(SOLEN_PORT_CONFIG, SOLEN_PIN_CONFIG))
  76. #define SOLEN_PE9_LOW() //(GPIO_ResetBits(SOLEN_PORT_CONFIG, GPIO_Pin_9))
  77. #define SOLEN_PE9_HIGH() //(GPIO_SetBits(SOLEN_PORT_CONFIG, GPIO_Pin_9))
  78. #endif
  79. /*LCD_def*/
  80. #if defined (STM32F10X_VET6_DEF)
  81. #define LCD_N5110_RCC (RCC_APB2Periph_GPIOE)
  82. #define LCD_N5110_PORT (GPIOE)
  83. #define LCD_N5110_PIN (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5)
  84. #define BACKLIGHT (PEout(0))
  85. #define LCD_RST (PEout(1))
  86. #define LCD_CE (PEout(2))
  87. #define LCD_DC (PEout(3))
  88. #define SDIN (PEout(4))
  89. #define SCLK (PEout(5))
  90. #elif defined (STM32F10X_C8T6_DEF)
  91. #define LCD_N5110_RCC (RCC_APB2Periph_GPIOB)
  92. #define LCD_N5110_PORT (GPIOB)
  93. #define LCD_N5110_PIN (GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15)
  94. #define BACKLIGHT (PBout(10))
  95. #define LCD_RST (PBout(11))
  96. #define LCD_CE (PBout(12))
  97. #define LCD_DC (PBout(13))
  98. #define SDIN (PBout(14))
  99. #define SCLK (PBout(15))
  100. #endif
  101. /*Pull_up_down_def*/
  102. #define PULL_RCC_CONFIG (RCC_APB2Periph_GPIOE)
  103. #define PULL_PORT_CONFIG (GPIOE)
  104. #define PULL_PIN_CONFIG (GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11)
  105. #define PULL_UP_PIN (GPIO_Pin_8 | GPIO_Pin_10)
  106. #define PULL_DOWN_PIN (GPIO_Pin_9 | GPIO_Pin_11)
  107. /*DS1302_def*/
  108. #define DS1302_IORCC (RCC_APB2Periph_GPIOB) //DS18B20对应IO的时钟
  109. #define DS1302_PORT (GPIOB)
  110. #define DS1302_SCK_PIN (GPIO_Pin_2) //定义DS18B20对应的IO口
  111. #define DS1302_IO_PIN (GPIO_Pin_1)
  112. #define DS1302_CE_PIN (GPIO_Pin_0)
  113. /*TEA5767_def*/
  114. #define TEA5767_RCC_CONFIG (RCC_APB2Periph_GPIOD)
  115. #define TEA5767_PORT_CONFIG (GPIOD)
  116. #define TEA5767_PIN_CONFIG (GPIO_Pin_12 | GPIO_Pin_13)
  117. #define TEA5767_SCL (PDout(13))
  118. #define TEA5767_SDA (PDout(12))
  119. #define TEA5767_SDA_VALUE (TEA5767ReadSDA())
  120. /*DHT11_def*/
  121. //C4->B0
  122. #if defined (STM32F10X_VET6_DEF)
  123. #define DHT11_IORCC (RCC_APB2Periph_GPIOC) //DHT11对应IO的时钟
  124. #define DHT11_PORT (GPIOC)
  125. #define DHT11_DATA_PIN (GPIO_Pin_4) //定义DHT11对应的IO口
  126. #define DHT11_Out (PCout(4))
  127. #define DHT11_In (PCin(4))
  128. #elif defined (STM32F10X_C8T6_DEF)
  129. #define DHT11_IORCC (RCC_APB2Periph_GPIOB) //DHT11对应IO的时钟
  130. #define DHT11_PORT (GPIOB)
  131. #define DHT11_DATA_PIN (GPIO_Pin_0) //定义DHT11对应的IO口
  132. #define DHT11_Out (PBout(0))
  133. #define DHT11_In (PBin(0))
  134. #endif
  135. /*WIFI_Uart1_def*/
  136. //UART1
  137. #define Wifi_SEL_UART (1)
  138. #if(Wifi_SEL_UART == 1)
  139. /****** RCC 配置******/
  140. /* APB2: USART1
  141. ** APB1: USART2\3\4\5
  142. */
  143. #define Wifi_RCC_GPIO_CONFIG() (RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE))
  144. #define Wifi_RCC_UART_CONFIG() (RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE))
  145. //波特率
  146. #define Wifi_UART_BAUD (115200)
  147. /****** GPIO 配置******/
  148. //UART端口号
  149. #define Wifi_GPIO (GPIOA)
  150. #define Wifi_Tx (GPIO_Pin_9)
  151. #define Wifi_Rx (GPIO_Pin_10)
  152. //串口号
  153. #define Wifi_UART (USART1)
  154. /****** UART优先级******/
  155. #define Wifi_NVIC_Group (NVIC_PriorityGroup_0)
  156. #define Wifi_NVIC_Interrupt (USART1_IRQn) //uart1中断号
  157. #define Wifi_NVIC_Pre (0)
  158. #define Wifi_NVIC_Sub (1)
  159. #endif
  160. //复位脚 PB10
  161. #define Reset_IORCC (RCC_APB2Periph_GPIOB) //Reset对应IO的时钟
  162. #define Reset_PORT (GPIOB)
  163. #define Reset_Pin (GPIO_Pin_4)
  164. //信号脚 PB15
  165. //C6->C13
  166. #if defined (STM32F10X_VET6_DEF)
  167. #define WifiLed_IORCC (RCC_APB2Periph_GPIOC) //Reset对应IO的时钟
  168. #define WifiLed_PORT (GPIOC)
  169. #define WifiLed_Pin (GPIO_Pin_6)
  170. #define WifiLedOn (GPIO_SetBits(WifiLed_PORT, WifiLed_Pin))
  171. #define WifiLedOff (GPIO_ResetBits(WifiLed_PORT, WifiLed_Pin))
  172. #elif defined (STM32F10X_C8T6_DEF)
  173. #define WifiLed_IORCC (RCC_APB2Periph_GPIOC) //Reset对应IO的时钟
  174. #define WifiLed_PORT (GPIOC)
  175. #define WifiLed_Pin (GPIO_Pin_13)
  176. #define WifiLedOn (GPIO_SetBits(WifiLed_PORT, WifiLed_Pin))
  177. #define WifiLedOff (GPIO_ResetBits(WifiLed_PORT, WifiLed_Pin))
  178. #endif
  179. /*YX5200*/
  180. //UART2
  181. #define YX5200_SEL_UART (2)
  182. #if(YX5200_SEL_UART == 2)
  183. /****** RCC 配置******/
  184. /* APB2: USART1
  185. ** APB1: USART2\3\4\5
  186. */
  187. #define YX5200_RCC_GPIO_CONFIG() (RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE))
  188. #define YX5200_RCC_UART_CONFIG() (RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE))
  189. #define YX5200_RCC_Remap_CONFIG() (GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE))
  190. //波特率
  191. #define YX5200_UART_BAUD (9600)
  192. /****** GPIO 配置******/
  193. //UART端口号
  194. #define YX5200_GPIO (GPIOD)
  195. #define YX5200_Tx (GPIO_Pin_5)
  196. #define YX5200_Rx (GPIO_Pin_6)
  197. //串口号
  198. #define YX5200_UART (USART2)
  199. /****** UART优先级******/
  200. #define YX5200_NVIC_Group (NVIC_PriorityGroup_0)
  201. #define YX5200_NVIC_Interrupt (USART2_IRQn) //uart1中断号
  202. #define YX5200_NVIC_Pre (0)
  203. #define YX5200_NVIC_Sub (2)
  204. #endif
  205. #define LCD_Backlight_AutoOff_Time_DEF (12000/100) //12s,在100ms扫描函数里
  206. //配置函数
  207. extern bool DS1302ReadIO ( void );
  208. extern bool TEA5767ReadSDA ( void );
  209. #endif