main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /*
  2. * Copyright(c) 2012-2020 微嵌电子 http://Tonvon.taobao.com
  3. *
  4. * QQ: 30611966 旺旺:twd3621576 Email: [email protected]
  5. *
  6. * 硬件平台:陆航MiniStm32开发板
  7. *
  8. * 硬件连接:
  9. *===========================================文件信息=======================================================
  10. * 文件名称:
  11. * 功 能:
  12. *
  13. * 编译软件:Keil MDK for ARM 4.12
  14. * 当前版本: V5.0.0.0
  15. * 作 者: Tonvdon(a dong)
  16. * 完成日期: 2012-03-03
  17. *
  18. * 取代版本:
  19. * 原作者 :
  20. * 完成日期:
  21. *********************************************************************************************************
  22. */
  23. #include "main.h"
  24. #include "Led.h"
  25. #include "Key.h"
  26. #include "Delay.h"
  27. #include "nokia_5110.h"
  28. //#include "bmp_pixel.h"
  29. #include "ds1302.h"
  30. #include "ds1302_config.h"
  31. #include "wifi9113.h"
  32. #include "wifi_gpio_conf.h"
  33. #include "TEA5767_main.h"
  34. #include "DHT11.h"
  35. #include "YX5200/YX5200_main.h"
  36. #include "YX5200/YX5200_uart.h"
  37. //#include "SPI-SD/Lcd/107_32_Driver_IO16.h"
  38. #include "SPI-SD/SD/sddriver.h"
  39. //#include "SPI-SD/Fatfs/ff.h"
  40. #include "SPI-SD/Lcd/lcd_5110_solution.h"
  41. unsigned int SystemClockFreq;
  42. void GPIO_ConfigurationSYSLed ( void )
  43. {
  44. #if SYSLed_def
  45. GPIO_InitTypeDef GPIO_InitStructure;
  46. RCC_APB2PeriphClockCmd ( LED_RCC_CONFIG , ENABLE );
  47. /**
  48. * LED -> PB1
  49. */
  50. GPIO_InitStructure.GPIO_Pin = LED_PIN_CONFIG;
  51. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  52. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  53. GPIO_Init ( LED_PORT_CONFIG, &GPIO_InitStructure );
  54. #endif
  55. }
  56. void GPIO_ConfigurationSolen ( void )
  57. {
  58. #if Solen_def
  59. GPIO_InitTypeDef GPIO_InitStructure;
  60. RCC_APB2PeriphClockCmd ( SOLEN_RCC_CONFIG , ENABLE );
  61. /**
  62. * Solen -> PE8 PE9
  63. */
  64. GPIO_InitStructure.GPIO_Pin = SOLEN_PIN_CONFIG;
  65. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  66. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  67. GPIO_Init ( SOLEN_PORT_CONFIG, &GPIO_InitStructure );
  68. SOLEN_PE8_HIGH();
  69. SOLEN_PE9_HIGH();
  70. #endif
  71. }
  72. void GpioConfigurationLCD ( void )
  73. {
  74. #if LCD_def
  75. GPIO_InitTypeDef GPIO_InitStructure;
  76. /* Enable the GPIO_LED Clock */
  77. RCC_APB2PeriphClockCmd ( LCD_N5110_RCC, ENABLE );
  78. /* Configure the GPIO_LED pin */
  79. GPIO_InitStructure.GPIO_Pin = LCD_N5110_PIN;
  80. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  81. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  82. GPIO_Init ( LCD_N5110_PORT, &GPIO_InitStructure );
  83. #endif
  84. }
  85. void GpioConfiguration_Pull_up_down ( void )
  86. {
  87. #if Pull_up_down_def
  88. GPIO_InitTypeDef GPIO_InitStructure;
  89. /* Enable the GPIO_LED Clock */
  90. RCC_APB2PeriphClockCmd ( PULL_RCC_CONFIG, ENABLE );
  91. /* Configure the GPIO_LED pin */
  92. GPIO_InitStructure.GPIO_Pin = PULL_PIN_CONFIG;
  93. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  94. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  95. GPIO_Init ( PULL_PORT_CONFIG, &GPIO_InitStructure );
  96. GPIO_SetBits ( PULL_PORT_CONFIG, PULL_UP_PIN );
  97. GPIO_ResetBits ( PULL_PORT_CONFIG, PULL_DOWN_PIN );
  98. #endif
  99. }
  100. void GpioConfigurationDS1302 ( void )
  101. {
  102. #if DS1302_def
  103. GPIO_InitTypeDef GPIO_InitStructure;
  104. RCC_APB2PeriphClockCmd ( DS1302_IORCC, ENABLE );
  105. GPIO_InitStructure.GPIO_Pin = ( DS1302_SCK_PIN | DS1302_IO_PIN | DS1302_CE_PIN );
  106. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  107. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  108. GPIO_Init ( DS1302_PORT, &GPIO_InitStructure );
  109. #endif
  110. }
  111. bool DS1302ReadIO ( void )
  112. {
  113. #if DS1302_def
  114. bool read_res;
  115. GPIO_InitTypeDef GPIO_InitStructure;
  116. RCC_APB2PeriphClockCmd ( DS1302_IORCC, ENABLE );
  117. //切换为输入口
  118. GPIO_InitStructure.GPIO_Pin = DS1302_IO_PIN;
  119. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  120. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  121. GPIO_Init ( DS1302_PORT, &GPIO_InitStructure );
  122. //读取并处理;
  123. read_res = GPIO_ReadInputDataBit ( DS1302_PORT, DS1302_IO_PIN );
  124. //还原成输出口
  125. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  126. GPIO_Init ( DS1302_PORT, &GPIO_InitStructure );
  127. //返回读取的值;
  128. return read_res;
  129. #endif
  130. }
  131. void GpioConfigurationTEA5767 ( void )
  132. {
  133. #if TEA5767_def
  134. GPIO_InitTypeDef GPIO_InitStructure;
  135. RCC_APB2PeriphClockCmd ( TEA5767_RCC_CONFIG, ENABLE );
  136. GPIO_InitStructure.GPIO_Pin = ( TEA5767_PIN_CONFIG );
  137. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  138. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  139. GPIO_Init ( TEA5767_PORT_CONFIG, &GPIO_InitStructure );
  140. #endif
  141. }
  142. bool TEA5767ReadSDA ( void )
  143. {
  144. #if TEA5767_def
  145. bool read_res;
  146. GPIO_InitTypeDef GPIO_InitStructure;
  147. RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOD, ENABLE );
  148. //切换为输入口
  149. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  150. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  151. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  152. GPIO_Init ( GPIOD, &GPIO_InitStructure );
  153. //读取并处理;
  154. read_res = GPIO_ReadInputDataBit ( GPIOD, GPIO_Pin_12 );
  155. //还原成输出口
  156. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  157. GPIO_Init ( GPIOD, &GPIO_InitStructure );
  158. //返回读取的值;
  159. return read_res;
  160. #endif
  161. }
  162. #define SYSTICK_TIME (1000000/1000) //最小10us,推荐1000us
  163. void SYSTICK_Configuration ( void )
  164. {
  165. RCC_ClocksTypeDef RCC_Clocks;
  166. RCC_GetClocksFreq ( &RCC_Clocks );
  167. SystemClockFreq = RCC_Clocks.SYSCLK_Frequency;
  168. if ( SysTick_Config ( SystemClockFreq / SYSTICK_TIME ) )
  169. {
  170. while ( 1 );
  171. }
  172. }
  173. /***************************************************************************************/
  174. //配置结束
  175. /***************************************************************************************/
  176. /**************************************************************************************
  177. 默认72Mh 主频 :
  178. 在文件 system_stm32f10x.c中有定义
  179. #define SYSCLK_FREQ_72MHz 72000000 可根据需要自行修改
  180. ****************************************************************************************/
  181. DHT11_Data_TypeDef DHT11_Data;
  182. char sendDataBuff[50];
  183. void AutoSend_Time_Temp ( void )
  184. {
  185. #if WIFI_Uart1_def
  186. //20s自动发送,time + 温湿度
  187. if ( WifiProcessStep == WIFI_STEP_CHAT )
  188. {
  189. sprintf ( sendDataBuff, "20%02d-%02d-%02d ", DS1302_DateTime.Year, DS1302_DateTime.Month, DS1302_DateTime.Date );
  190. sprintf ( sendDataBuff, "%s%02d:%02d:%02d %02d", sendDataBuff, DS1302_DateTime.Hour, DS1302_DateTime.Minute, DS1302_DateTime.Second, DS1302_DateTime.Day );
  191. sprintf ( sendDataBuff, "%s|%02d%% - %02dC|", sendDataBuff, DHT11_Data.humi_int, DHT11_Data.temp_int );
  192. sendto_server0824 ( AIM_ID, REGMY_ID, ( u8 * ) sendDataBuff, strlen ( sendDataBuff ) );
  193. }
  194. #endif
  195. }
  196. void Get_DS1302_Time ( void )
  197. {
  198. #if DS1302_def
  199. if ( WifiProcessStep != WIFI_STEP_CHAT )
  200. {
  201. //rtc 获取
  202. DS1302_GetDateTime();
  203. sys_rtc_time = Date_TO_Sec ( DS1302_DateTime.Year, DS1302_DateTime.Month, DS1302_DateTime.Date, DS1302_DateTime.Hour, DS1302_DateTime.Minute, DS1302_DateTime.Second );
  204. }
  205. #endif
  206. }
  207. void Get_DHT11_Temp ( void )
  208. {
  209. #if DHT11_def
  210. //温湿度获取
  211. Read_DHT11 ( &DHT11_Data );
  212. #endif
  213. }
  214. void Pri_Sys_Time ( char LinePos )
  215. {
  216. //rtc 200ms刷新
  217. Sec_TO_Date ( sys_rtc_time );
  218. sprintf ( n5110_string[LinePos + 0], "20%02d-%02d-%02d", DS1302_DateTime.Year, DS1302_DateTime.Month, DS1302_DateTime.Date );
  219. sprintf ( n5110_string[LinePos + 1], "%02d:%02d:%02d %02d", DS1302_DateTime.Hour, DS1302_DateTime.Minute, DS1302_DateTime.Second, DS1302_DateTime.Day );
  220. }
  221. void Pri_DHT11_Temp ( char LinePos )
  222. {
  223. #if DHT11_def
  224. sprintf ( n5110_string[LinePos + 0], "%02d%% - %02dC", DHT11_Data.humi_int, DHT11_Data.temp_int );
  225. #endif
  226. }
  227. void Pri_Key_State ( char LinePos )
  228. {
  229. #if key16_def
  230. u8 i;
  231. for ( i = 0; i < 16; i++ )
  232. {
  233. if ( Keys[i].Res != NO_KEY_FLAG )
  234. {
  235. sprintf ( n5110_string[LinePos + 0], "-->K%02d:%1d", i + 1, Keys[i].Res );
  236. }
  237. }
  238. #endif
  239. }
  240. void Pri_Wifi_State ( char LinePos )
  241. {
  242. #if WIFI_Uart1_def
  243. //3.wifi状态显示
  244. if ( if_wifi_msg_come )
  245. {
  246. if_wifi_msg_come = false;
  247. if ( WifiProcessStep == WIFI_STEP_CHECK )
  248. {
  249. sprintf ( n5110_string[LinePos + 0], "%d,%d,%d", WifiProcessStep, WifiCheckStep, WifiTimeReset );
  250. }
  251. else if ( WifiProcessStep == WIFI_STEP_CONNECT )
  252. {
  253. sprintf ( n5110_string[LinePos + 0], "%d,%d,%d", WifiProcessStep, WifiConnectStep, WifiTimeReset );
  254. }
  255. else if ( WifiProcessStep == WIFI_STEP_CHAT )
  256. {
  257. sprintf ( n5110_string[LinePos + 0], "%d,%d,%d", WifiProcessStep, WIFI_LED_FLAG, WifiTimeReset );
  258. }
  259. }
  260. #endif
  261. }
  262. void TEA5767_main ( void )
  263. {
  264. #if TEA5767_def
  265. //UART_Init();//串口初始化
  266. //UART_Send_Str("调频收音机\n");
  267. //radio_write();
  268. //while(1)
  269. {
  270. if ( Keys[11 - 1].Res == SHORT_KEY_FLAG )
  271. {
  272. Keys[11 - 1].Res = NO_KEY_FLAG;
  273. search ( 1 );
  274. radio_read();
  275. sprintf ( n5110_string[4], "FM:%.1fMHz ", frequency * 1.0 / 1000 );
  276. }
  277. if ( Keys[12 - 1].Res == SHORT_KEY_FLAG )
  278. {
  279. Keys[12 - 1].Res = NO_KEY_FLAG;
  280. search ( 0 );
  281. radio_read();
  282. sprintf ( n5110_string[4], "FM:%.1fMHz ", frequency * 1.0 / 1000 );
  283. }
  284. }
  285. #endif
  286. }
  287. void wifi_Handler ( u8 data[] )
  288. {
  289. #if WIFI_Uart1_def
  290. /*
  291. data[3] 应该 = COMMD_TRANSMIT(0x03)
  292. data[4] 应该 = REGMY_ID(0x03)
  293. data[5] 应该 = AIM_ID(0x02) 或其他人
  294. */
  295. if ( ( data[3] == COMMD_TRANSMIT ) && ( data[4] == REGMY_ID ) )
  296. {
  297. BACKLIGHT = 1;//开启背光灯
  298. switch ( data[6] )
  299. {
  300. case 0x01://电磁阀控制
  301. if ( data[7] == 0x01 ) //阀1
  302. {
  303. if ( data[8] == 0 )
  304. SOLEN_PE8_LOW();
  305. else if ( data[8] == 1 )
  306. SOLEN_PE8_HIGH();
  307. }
  308. else if ( data[7] == 0x02 ) //阀2
  309. {
  310. if ( data[8] == 0 )
  311. SOLEN_PE9_LOW();
  312. else if ( data[8] == 1 )
  313. SOLEN_PE9_HIGH();
  314. }
  315. break;
  316. case 0x02://rtc时钟设置
  317. break;
  318. default:
  319. break;
  320. }
  321. }
  322. #endif
  323. }
  324. void sysLed_main ( void )
  325. {
  326. #if SYSLed_def
  327. static bool sysLedOn = false;
  328. //200ms
  329. sysLedOn = !sysLedOn;
  330. if ( sysLedOn )
  331. LED_PC7_LOW();
  332. else
  333. LED_PC7_HIGH();
  334. #endif
  335. }
  336. void If_NoKey_Backlight_Off ( void )
  337. {
  338. #if LCD_def
  339. static u16 LCD_Backlight_AutoOff_Time = LCD_Backlight_AutoOff_Time_DEF;
  340. if ( 0 == LCD_Backlight_AutoOff_Time )
  341. {
  342. if ( BACKLIGHT )
  343. {
  344. LCD_Backlight_AutoOff_Time = LCD_Backlight_AutoOff_Time_DEF;
  345. }
  346. }
  347. else
  348. {
  349. LCD_Backlight_AutoOff_Time--;
  350. if ( 1 == LCD_Backlight_AutoOff_Time )
  351. {
  352. //关闭背光灯
  353. BACKLIGHT = 0;
  354. }
  355. }
  356. #endif
  357. }
  358. void If_KeyDown_Backlight_On ( void )
  359. {
  360. #if LCD_def
  361. u8 i;
  362. for ( i = 0; i < 16; i++ )
  363. {
  364. if ( Keys[i].Res != NO_KEY_FLAG )
  365. {
  366. BACKLIGHT = 1;//开启背光灯
  367. }
  368. }
  369. #endif
  370. }
  371. void Long_key_Change_Function ( void )
  372. {
  373. //切换显示
  374. if ( Keys[11].Res == ONE_HITS_KEY_FLAG )
  375. {
  376. Keys[11].Res = NO_KEY_FLAG;
  377. memset ( n5110_string, 0x20, sizeof ( n5110_string ) );
  378. if ( System_Flag_Prin_Music )
  379. {
  380. System_Flag_Prin_Time_Temp = 1;
  381. System_Flag_Prin_Music = 0;
  382. sprintf ( n5110_string[1], "*************" );
  383. sprintf ( n5110_string[2], "* NORMA *" );
  384. sprintf ( n5110_string[3], "*************" );
  385. }
  386. else
  387. {
  388. System_Flag_Prin_Time_Temp = 0;
  389. System_Flag_Prin_Music = 1;
  390. sprintf ( n5110_string[1], "*************" );
  391. sprintf ( n5110_string[2], "* MUSIC *" );
  392. sprintf ( n5110_string[3], "*************" );
  393. }
  394. }
  395. }
  396. void Key_Random_play_music ( u8 fold )
  397. {
  398. if ( Keys[12].Res == ONE_HITS_KEY_FLAG )
  399. {
  400. Keys[12].Res = NO_KEY_FLAG;
  401. //随机播放
  402. //Random_play_music ( 2 ); //02 TF卡
  403. Let_One_Music_play ( fold, rand() % 12 );
  404. }
  405. }
  406. void key16_main ( void )
  407. {
  408. #if key16_def
  409. //如果有键按下,打开LCD背光灯
  410. If_KeyDown_Backlight_On();
  411. //K0-K9/K0-K5: 数字/播放
  412. //K10: 模式切换
  413. YX5200_Key_handler();
  414. //K11: 切换功能
  415. Long_key_Change_Function();
  416. //K12: 随机播放
  417. Key_Random_play_music(00);//00文件夹
  418. //K14: 复位时间
  419. DS1302_Key_Handler();
  420. #endif
  421. //12秒没有键,关闭LCD背光灯
  422. If_NoKey_Backlight_Off();
  423. }
  424. void ESP8266_main ( void )
  425. {
  426. #if WIFI_Uart1_def
  427. //1.连接服务器
  428. wifi_main();
  429. //2.命令处理
  430. if ( WifiDatCome )
  431. {
  432. WifiDatCome = false;
  433. wifi_Handler ( Wifi_Rec_Buff );
  434. memset ( Wifi_Rec_Buff, 0, TotalRecvBytes );
  435. }
  436. #endif
  437. }
  438. /*
  439. 0-5点不报时
  440. 6-23点报时
  441. */
  442. bool BitH24_0[24]={
  443. 0,0,0,0,0,0,1,1,1,1,1,1,
  444. 1,1,1,1,1,1,1,1,1,1,1,1
  445. };
  446. void Set_time_for_announce_the_hour(void)
  447. {
  448. if ( ( 59 == DS1302_DateTime.Minute ) && \
  449. ( 58 == DS1302_DateTime.Second ) )
  450. {
  451. if ( BitH24_0[DS1302_DateTime.Hour] )
  452. {
  453. Let_One_Music_play ( 24, DS1302_DateTime.Hour + 1 );
  454. }
  455. }
  456. }
  457. typedef struct {
  458. u8 hour;
  459. u8 min;
  460. u8 sec;
  461. }tPlay;
  462. //设置一个定时播放
  463. tPlay PlayList[]={
  464. {6,45,0},
  465. {255,255,255}
  466. };
  467. void Set_time_for_play_music(void)
  468. {
  469. u8 i;
  470. for(i=0; i<sizeof(PlayList)/sizeof(tPlay); i++)
  471. {
  472. if ( ( PlayList[i].hour == DS1302_DateTime.Hour ) && \
  473. ( PlayList[i].min == DS1302_DateTime.Minute ) && \
  474. ( PlayList[i].sec == DS1302_DateTime.Second ) )
  475. {
  476. Let_One_Music_play ( 00, rand() % 12 );
  477. }
  478. }
  479. }
  480. void Announce_the_hour_and_play_music_Task ( void )
  481. {
  482. #if xy5200_Uart2_def
  483. //1.整点报时
  484. Set_time_for_announce_the_hour();
  485. //2.定时闹钟
  486. Set_time_for_play_music();
  487. #endif
  488. }
  489. void Timer_TASK1 ( void )
  490. {
  491. if ( System_Flag_2Ms )
  492. {
  493. System_Flag_2Ms = 0;
  494. //出队列msg
  495. MSG_Task();
  496. //wifi连接服务器
  497. ESP8266_main();
  498. }
  499. if ( System_Flag_10Ms )
  500. {
  501. System_Flag_10Ms = 0;
  502. //按键扫描
  503. KeyHander();
  504. //uart2接收,进队列msg
  505. YX5200_UART_Handler();
  506. }
  507. if ( System_Flag_100Ms )
  508. {
  509. System_Flag_100Ms = 0;
  510. //系统信号灯
  511. sysLed_main();
  512. //按键执行
  513. key16_main();
  514. //LCD刷新
  515. RefreshLCD();
  516. //music 100ms任务
  517. Time_Task();
  518. }
  519. if ( System_Flag_200Ms )
  520. {
  521. System_Flag_200Ms = 0;
  522. }
  523. if ( System_Flag_500Ms )
  524. {
  525. System_Flag_500Ms = 0;
  526. }
  527. if ( System_Flag_1s )
  528. {
  529. System_Flag_1s = 0;
  530. //报时任务
  531. Announce_the_hour_and_play_music_Task();
  532. if ( System_Flag_Prin_Time_Temp )
  533. {
  534. //显示系统时间
  535. Pri_Sys_Time ( 0 ); //0-1
  536. //显示温湿度
  537. Pri_DHT11_Temp ( 3 ); //3-3
  538. }
  539. //显示按下的按键
  540. Pri_Key_State ( 4 ); //4-4
  541. //显示wifi状态
  542. Pri_Wifi_State ( 5 ); //5-5
  543. }
  544. if ( System_Flag_8s )
  545. {
  546. System_Flag_8s = 0;
  547. //获取温湿度
  548. Get_DHT11_Temp();
  549. //获取时间日期
  550. Get_DS1302_Time();
  551. }
  552. if ( System_Flag_20s )
  553. {
  554. System_Flag_20s = 0;
  555. //自动发送系统信息到控制端
  556. AutoSend_Time_Temp();
  557. }
  558. }
  559. extern u32 T1_Val;
  560. extern u32 T2_Val;
  561. extern u32 T3_Val;
  562. extern u32 T4_Val;
  563. int main ( void )
  564. {
  565. SystemInit();
  566. //sysTick
  567. SYSTICK_Configuration();
  568. //定时器2
  569. //TIM2_Configuration();
  570. //TIM2_NVIC_Configuration();
  571. //测试延时,精确
  572. sys_ms = 0;
  573. T1_Val = 0;
  574. delay_us(1000);
  575. sys_ms = 0;
  576. T1_Val = 0;
  577. delay_us(5000);
  578. //上下拉一些端口
  579. GpioConfiguration_Pull_up_down();
  580. //4*4按键扫描
  581. GPIO_ConfigurationKey();
  582. //电磁阀初始化
  583. GPIO_ConfigurationSolen();
  584. //LED D4 -> GPIOC7
  585. GPIO_ConfigurationSYSLed();
  586. //RTC初始化
  587. GpioConfigurationDS1302();
  588. DS1302_Init();
  589. //初始化液晶
  590. GpioConfigurationLCD();
  591. InitLcd();
  592. //初始化wifi :led、硬复位、UART1
  593. Configuration_WifiLed();
  594. Configuration_WIFI_Usart1();
  595. NVIC_Configuration_WIFI_USART1();
  596. //Configuration_ResetWifi();
  597. //WifiHardReset();
  598. //MP3解码器
  599. Configuration_YX5200_Usart2();
  600. NVIC_Configuration_YX5200_USART2();
  601. //1.SPI1-DMA SD
  602. //SPI1_GPIO_Configuration();
  603. //2.SPI2-DMA
  604. if(!SD_Init()){
  605. GUI_Put(0,0, "SD Init OK!", RED, BLACK); // BLUE
  606. delay_ms(500);
  607. GUI_Put(0,0, "故人西辞黄鹤楼", RED, BLACK); // BLUE
  608. GUI_Put(0,1, "烟花三月下扬州", RED, BLACK); // BLUE
  609. GUI_Put(0,2, "孤帆远影碧空尽", RED, BLACK); // BLUE
  610. GUI_Put(0,3, "唯见长江天际流", RED, BLACK); // BLUE
  611. }
  612. else{
  613. GUI_Put(0,0, "SD Init Fail!", RED, BLACK); // BLUE
  614. }
  615. //写入初始化电台频率
  616. //GpioConfigurationTEA5767();
  617. //IIC_Init();
  618. //Set_Frequency(101800); //设置电台频率为101.8MHz
  619. //radio_write();
  620. System_Flag_Prin_Time_Temp = 1;
  621. #if (UART1_SD_def&&SPI1_DMA_SD_def)
  622. //printf("\n\rThe SPI-Flash ID:0x%04X\r\n",SPI_Flash_ReadID());
  623. #endif
  624. LcdClearAll();
  625. while ( 1 )
  626. {
  627. Timer_TASK1();
  628. }
  629. }