找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2444|回复: 1
打印 上一主题 下一主题
收起左侧

ec20 4g传输光照度、温湿度至阿里云平台 STM32源程序

[复制链接]
跳转到指定楼层
#
ID:770044 发表于 2020-6-5 09:57 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
ec20 stm32 阿里云

单片机源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "main.h"
  3. #include "dma.h"
  4. #include "i2c.h"
  5. #include "rtc.h"
  6. #include "spi.h"
  7. #include "tim.h"
  8. #include "usart.h"
  9. #include "gpio.h"

  10. /* Private includes ----------------------------------------------------------*/
  11. /* USER CODE BEGIN Includes */
  12. #include "EC20.h"
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include "LCD.h"
  16. #include "485.h"
  17. #include "w25qxx.h"
  18. #include <time.h>


  19. /* USER CODE END Includes */

  20. /* Private typedef -----------------------------------------------------------*/
  21. /* USER CODE BEGIN PTD */

  22. /* USER CODE END PTD */

  23. /* Private define ------------------------------------------------------------*/
  24. /* USER CODE BEGIN PD */

  25. /* USER CODE END PD */

  26. /* Private macro -------------------------------------------------------------*/
  27. /* USER CODE BEGIN PM */

  28. /* USER CODE END PM */

  29. /* Private variables ---------------------------------------------------------*/

  30. /* USER CODE BEGIN PV */
  31. /* Private variables ---------------------------------------------------------*/
  32. extern USART_RECEIVETYPE UsartType1;
  33. extern USART_RECEIVETYPE UsartType2;
  34. extern USART_RECEIVETYPE UsartType3;
  35. extern        uint8_t        EC20_SEND_STATUS;
  36. extern uint16_t TIM3_Count;
  37. uint8_t TIM3_Count_flag=0;
  38. uint8_t PageState=0;
  39. uint8_t Forflag=0;
  40. extern uint8_t ErrorSendcount;
  41. extern _Meassage Meassage;
  42. uint16_t Count0fSwitch=0;
  43. extern uint16_t CountLCD;
  44. extern uint8_t EC20State;
  45. extern uint16_t Count0f485;
  46. uint16_t Count0fLUX=0;
  47. uint16_t Count0fPage=0;
  48. uint16_t W25QID=0;
  49. uint8_t  Mytimecount;
  50. //extern        UART_HandleTypeDef huart1;
  51. //extern        UART_HandleTypeDef huart2;
  52. //extern        UART_HandleTypeDef huart3;
  53. uint8_t TxBuffer[]="\r\n***UART**\r\n";
  54. uint8_t Rseponse=0;
  55. uint8_t Rseponse1=0;
  56. uint8_t ErrorSendflag=0;
  57. uint8_t Gettimeflag=0;
  58. uint32_t Gettimeflagcount=0;

  59. char TimeCode[15];
  60. tSysParam nowSysParam;
  61. EC20Param nowEC20Param;



  62. #define  BEEP_H()                    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
  63. #define  BEEP_L()                    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
  64. #define  EC20PowerON                  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
  65. #define  EC20PowerOFF          HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
  66. #define  EC20RsTON       HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
  67. #define  EC20RsTOFF      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
  68. /* USER CODE END PV */

  69. /* Private function prototypes -----------------------------------------------*/
  70. void SystemClock_Config(void);
  71. static void MX_NVIC_Init(void);
  72. /* USER CODE BEGIN PFP */
  73. /* Private function prototypes -----------------------------------------------*/

  74. /* USER CODE END PFP */

  75. /* Private user code ---------------------------------------------------------*/
  76. /* USER CODE BEGIN 0 */

  77. #if 1
  78. #pragma import(__use_no_semihosting)            
  79. //标准库需要的支持函数                 
  80. struct __FILE
  81. {
  82.         int handle;
  83. };

  84. FILE __stdout;      
  85. //定义_sys_exit()以避免使用半主机模式   
  86. void _sys_exit(int x)
  87. {
  88.         x = x;
  89. }
  90. //重定义fputc函数
  91. int fputc(int ch, FILE *f)
  92. {         
  93.         while((USART1->SR&0X40)==0);//循环发送,直到发送完毕   
  94.         USART1->DR = (uint8_t) ch;      
  95.         return ch;
  96. }
  97. #endif

  98. ///////////////////////////////////////////////////////////////



  99. void Usart1SendData_DMA(uint8_t *pdata, uint16_t Length)
  100. {
  101.         // while( huart1.gState != HAL_UART_STATE_READY);
  102.         
  103.         //while(UsartType1.dmaSend_flag == USART_DMA_SENDING);
  104.         UsartType1.dmaSend_flag = USART_DMA_SENDING;
  105.         HAL_UART_Transmit_DMA(&huart1, pdata, Length);
  106.         
  107. }
  108. void Usart2SendData_DMA(uint8_t *pdata, uint16_t Length)
  109. {
  110.          //while( huart2.gState != HAL_UART_STATE_READY);
  111.         
  112.         //while(UsartType2.dmaSend_flag == USART_DMA_SENDING);
  113.         UsartType2.dmaSend_flag = USART_DMA_SENDING;
  114.         HAL_UART_Transmit_DMA(&huart2, pdata, Length);
  115.         
  116. }


  117. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
  118. {
  119.          __HAL_DMA_DISABLE(huart->hdmatx);
  120.         UsartType1.dmaSend_flag = USART_DMA_SENDOVER;
  121.         UsartType2.dmaSend_flag = USART_DMA_SENDOVER;
  122.         UsartType3.dmaSend_flag = USART_DMA_SENDOVER;
  123. }

  124. void        START_TIM3()
  125. {
  126.         #ifdef        EN_WD
  127.         IDWG_FEED();
  128.         #endif
  129.         //TIM3_Count=0;
  130.         HAL_TIM_Base_Start_IT(&htim3);
  131. }
  132. void END_TIM3()
  133. {
  134.         HAL_TIM_Base_Stop_IT(&htim3);
  135. }
  136. //uint8_t        END_TIM3(uint16_t        n)
  137. //{
  138. //        if(n==0)
  139. //        {
  140. //                HAL_TIM_Base_Stop_IT(&htim3);
  141. //                return        1;
  142. //        }
  143. //        else
  144. //        {
  145. //                if(n<TIM3_Count)
  146. //                {
  147. //                        HAL_TIM_Base_Stop_IT(&htim3);
  148. //                        TIM3_Count=0;
  149. //                        return        1;
  150. //                }
  151. //        }
  152. //        return 0;
  153. //}

  154. void GetMeassage(char *LMeassage)
  155. {

  156.                         char *ret;
  157.                         char buf[20];
  158.                         uint16_t i=0;
  159.                         uint16_t j=0;
  160.                         memset(&buf,0,20);
  161.         
  162. //                j=0;i=0;ret=NULL;
  163. //                ret=strstr(LMeassage,"+QMTSTAT: 0,");
  164. //        
  165. //                        if(ret!=NULL)
  166. //                        {
  167. //                                
  168. //                        }

  169.         

  170. ///////////////////////////////////////////////////Switch1
  171.                   j=0;i=0;ret=NULL;
  172.                         ret=strstr(LMeassage,"Switch1");
  173.                         if(ret!=NULL)
  174.                         {
  175.                                 Rseponse=1;
  176.                                 if(ret[9]=='1')
  177.                                         OPEN(0);
  178.                                 else
  179.                                         {
  180.                                                 CLOSE(0);
  181.                                         }
  182.                         }
  183.                         ///////////////////////////////////////////////////Switch2
  184.                   j=0;i=0;ret=NULL;
  185.                         ret=strstr(LMeassage,"Switch2");
  186.                         if(ret!=NULL)
  187.                         {
  188.                                 Rseponse=1;
  189.                                 if(ret[9]=='1')
  190.                                         OPEN(1);
  191.                                 else
  192.                                         {
  193.                                                 CLOSE(1);
  194.                                         }
  195.                         }
  196.                         ///////////////////////////////////////////////////Switch3
  197.                   j=0;i=0;ret=NULL;
  198.                         ret=strstr(LMeassage,"Switch3");
  199.                         if(ret!=NULL)
  200.                         {
  201.                                 Rseponse=1;
  202.                                 if(ret[9]=='1')
  203.                                         OPEN(2);
  204.                                 else
  205.                                         {
  206.                                                 CLOSE(2);
  207.                                         }
  208.                         }
  209.                         ///////////////////////////////////////////////////Switch4
  210.                   j=0;i=0;ret=NULL;
  211.                         ret=strstr(LMeassage,"Switch4");
  212.                         if(ret!=NULL)
  213.                         {
  214.                                 Rseponse=1;
  215.                                 if(ret[9]=='1')
  216.                                         OPEN(3);
  217.                                 else
  218.                                         {
  219.                                                 CLOSE(3);
  220.                                         }
  221.                         }
  222.                         ///////////////////////////////////////////////////Switch5
  223.                   j=0;i=0;ret=NULL;
  224.                         ret=strstr(LMeassage,"Switch5");
  225.                         if(ret!=NULL)
  226.                         {
  227.                                 Rseponse=1;
  228.                                 if(ret[9]=='1')
  229.                                         OPEN(4);
  230.                                 else
  231.                                         {
  232.                                                 CLOSE(4);
  233.                                         }
  234.                         }
  235.                         ///////////////////////////////////////////////////Switch6
  236.                   j=0;i=0;ret=NULL;
  237.                         ret=strstr(LMeassage,"Switch6");
  238.                         if(ret!=NULL)
  239.                         {
  240.                                 Rseponse=1;
  241.                                 if(ret[9]=='1')
  242.                                         OPEN(5);
  243.                                 else
  244.                                         {
  245.                                                 CLOSE(5);
  246.                                         }
  247.                         }
  248.                         
  249. ///////////////////////////////////////////////////找QRcode
  250.                         j=0;i=0;ret=NULL;
  251.                         ret=strstr(LMeassage,"QRcode");
  252.                 if(ret!=NULL)
  253.                 {
  254.                                                 if(UsartType2.rx_len>1024)
  255.                                                 {
  256.                                                         Meassage.Error_Code=53;//设置二维码error
  257.                                                 }
  258.                                                 //printf("%s",ret+9);
  259.                                                 else
  260.                                                 {
  261.                                                         if(ret[8]=='"')
  262.                                                         {
  263.                                                                 memset(Meassage.QRcode,0,sizeof(Meassage.QRcode));
  264.                                                                
  265.                                                                
  266.                                                                 for(i=0;i<UsartType2.rx_len;i++)
  267.                                                                 {
  268.                                                                         if(ret[9+i]=='"')break;
  269.                                                                         Meassage.QRcode[j]=ret[i+9];
  270.                                                                         j++;
  271.                                                                 }
  272.                                                                 nowSysParam.saveFlag=0x55;
  273.                                                                 memcpy(&nowSysParam.saveData,&Meassage.QRcode,sizeof(Meassage.QRcode)); //????????????
  274.                                                                 w25q_eraseSector(0x0000);
  275.                                                                 w25q_writeNoCheck((uint8_t *)&nowSysParam,0x0000,sizeof(nowSysParam));//???????flash?
  276.                                 
  277.                                                                 Meassage.Error_Code=52;//设置二维码成功
  278.                                                         //        printf("Meassage.QRcode:%s\r\n",Meassage.QRcode);
  279.                                                         
  280.                                                         }
  281.                                                         else
  282.                                                         {
  283.                                                                 Meassage.Error_Code=53;//设置二维码成功失败
  284.                                                         }
  285.                                                 }
  286.                                                         Rseponse=1;
  287.                 }
  288. ……………………

  289. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
sunctrl.7z (2.95 MB, 下载次数: 107)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

楼主
ID:1076325 发表于 2024-4-10 23:08 | 只看该作者
你好,可以提供原理图参考学习一下吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表