ec20 stm32 阿里云
單片機源程序如下:
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- #include "dma.h"
- #include "i2c.h"
- #include "rtc.h"
- #include "spi.h"
- #include "tim.h"
- #include "usart.h"
- #include "gpio.h"
- /* Private includes ----------------------------------------------------------*/
- /* USER CODE BEGIN Includes */
- #include "EC20.h"
- #include <string.h>
- #include <stdlib.h>
- #include "LCD.h"
- #include "485.h"
- #include "w25qxx.h"
- #include <time.h>
- /* USER CODE END Includes */
- /* Private typedef -----------------------------------------------------------*/
- /* USER CODE BEGIN PTD */
- /* USER CODE END PTD */
- /* Private define ------------------------------------------------------------*/
- /* USER CODE BEGIN PD */
- /* USER CODE END PD */
- /* Private macro -------------------------------------------------------------*/
- /* USER CODE BEGIN PM */
- /* USER CODE END PM */
- /* Private variables ---------------------------------------------------------*/
- /* USER CODE BEGIN PV */
- /* Private variables ---------------------------------------------------------*/
- extern USART_RECEIVETYPE UsartType1;
- extern USART_RECEIVETYPE UsartType2;
- extern USART_RECEIVETYPE UsartType3;
- extern uint8_t EC20_SEND_STATUS;
- extern uint16_t TIM3_Count;
- uint8_t TIM3_Count_flag=0;
- uint8_t PageState=0;
- uint8_t Forflag=0;
- extern uint8_t ErrorSendcount;
- extern _Meassage Meassage;
- uint16_t Count0fSwitch=0;
- extern uint16_t CountLCD;
- extern uint8_t EC20State;
- extern uint16_t Count0f485;
- uint16_t Count0fLUX=0;
- uint16_t Count0fPage=0;
- uint16_t W25QID=0;
- uint8_t Mytimecount;
- //extern UART_HandleTypeDef huart1;
- //extern UART_HandleTypeDef huart2;
- //extern UART_HandleTypeDef huart3;
- uint8_t TxBuffer[]="\r\n***UART**\r\n";
- uint8_t Rseponse=0;
- uint8_t Rseponse1=0;
- uint8_t ErrorSendflag=0;
- uint8_t Gettimeflag=0;
- uint32_t Gettimeflagcount=0;
- char TimeCode[15];
- tSysParam nowSysParam;
- EC20Param nowEC20Param;
- #define BEEP_H() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
- #define BEEP_L() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
- #define EC20PowerON HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
- #define EC20PowerOFF HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
- #define EC20RsTON HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
- #define EC20RsTOFF HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- static void MX_NVIC_Init(void);
- /* USER CODE BEGIN PFP */
- /* Private function prototypes -----------------------------------------------*/
- /* USER CODE END PFP */
- /* Private user code ---------------------------------------------------------*/
- /* USER CODE BEGIN 0 */
- #if 1
- #pragma import(__use_no_semihosting)
- //標準庫需要的支持函數(shù)
- struct __FILE
- {
- int handle;
- };
- FILE __stdout;
- //定義_sys_exit()以避免使用半主機模式
- void _sys_exit(int x)
- {
- x = x;
- }
- //重定義fputc函數(shù)
- int fputc(int ch, FILE *f)
- {
- while((USART1->SR&0X40)==0);//循環(huán)發(fā)送,直到發(fā)送完畢
- USART1->DR = (uint8_t) ch;
- return ch;
- }
- #endif
- ///////////////////////////////////////////////////////////////
- void Usart1SendData_DMA(uint8_t *pdata, uint16_t Length)
- {
- // while( huart1.gState != HAL_UART_STATE_READY);
-
- //while(UsartType1.dmaSend_flag == USART_DMA_SENDING);
- UsartType1.dmaSend_flag = USART_DMA_SENDING;
- HAL_UART_Transmit_DMA(&huart1, pdata, Length);
-
- }
- void Usart2SendData_DMA(uint8_t *pdata, uint16_t Length)
- {
- //while( huart2.gState != HAL_UART_STATE_READY);
-
- //while(UsartType2.dmaSend_flag == USART_DMA_SENDING);
- UsartType2.dmaSend_flag = USART_DMA_SENDING;
- HAL_UART_Transmit_DMA(&huart2, pdata, Length);
-
- }
-
- void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
- {
- __HAL_DMA_DISABLE(huart->hdmatx);
- UsartType1.dmaSend_flag = USART_DMA_SENDOVER;
- UsartType2.dmaSend_flag = USART_DMA_SENDOVER;
- UsartType3.dmaSend_flag = USART_DMA_SENDOVER;
- }
- void START_TIM3()
- {
- #ifdef EN_WD
- IDWG_FEED();
- #endif
- //TIM3_Count=0;
- HAL_TIM_Base_Start_IT(&htim3);
- }
- void END_TIM3()
- {
- HAL_TIM_Base_Stop_IT(&htim3);
- }
- //uint8_t END_TIM3(uint16_t n)
- //{
- // if(n==0)
- // {
- // HAL_TIM_Base_Stop_IT(&htim3);
- // return 1;
- // }
- // else
- // {
- // if(n<TIM3_Count)
- // {
- // HAL_TIM_Base_Stop_IT(&htim3);
- // TIM3_Count=0;
- // return 1;
- // }
- // }
- // return 0;
- //}
- void GetMeassage(char *LMeassage)
- {
- char *ret;
- char buf[20];
- uint16_t i=0;
- uint16_t j=0;
- memset(&buf,0,20);
-
- // j=0;i=0;ret=NULL;
- // ret=strstr(LMeassage,"+QMTSTAT: 0,");
- //
- // if(ret!=NULL)
- // {
- //
- // }
-
- ///////////////////////////////////////////////////Switch1
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"Switch1");
- if(ret!=NULL)
- {
- Rseponse=1;
- if(ret[9]=='1')
- OPEN(0);
- else
- {
- CLOSE(0);
- }
- }
- ///////////////////////////////////////////////////Switch2
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"Switch2");
- if(ret!=NULL)
- {
- Rseponse=1;
- if(ret[9]=='1')
- OPEN(1);
- else
- {
- CLOSE(1);
- }
- }
- ///////////////////////////////////////////////////Switch3
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"Switch3");
- if(ret!=NULL)
- {
- Rseponse=1;
- if(ret[9]=='1')
- OPEN(2);
- else
- {
- CLOSE(2);
- }
- }
- ///////////////////////////////////////////////////Switch4
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"Switch4");
- if(ret!=NULL)
- {
- Rseponse=1;
- if(ret[9]=='1')
- OPEN(3);
- else
- {
- CLOSE(3);
- }
- }
- ///////////////////////////////////////////////////Switch5
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"Switch5");
- if(ret!=NULL)
- {
- Rseponse=1;
- if(ret[9]=='1')
- OPEN(4);
- else
- {
- CLOSE(4);
- }
- }
- ///////////////////////////////////////////////////Switch6
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"Switch6");
- if(ret!=NULL)
- {
- Rseponse=1;
- if(ret[9]=='1')
- OPEN(5);
- else
- {
- CLOSE(5);
- }
- }
-
- ///////////////////////////////////////////////////找QRcode
- j=0;i=0;ret=NULL;
- ret=strstr(LMeassage,"QRcode");
- if(ret!=NULL)
- {
- if(UsartType2.rx_len>1024)
- {
- Meassage.Error_Code=53;//設置二維碼error
- }
- //printf("%s",ret+9);
- else
- {
- if(ret[8]=='"')
- {
- memset(Meassage.QRcode,0,sizeof(Meassage.QRcode));
-
-
- for(i=0;i<UsartType2.rx_len;i++)
- {
- if(ret[9+i]=='"')break;
- Meassage.QRcode[j]=ret[i+9];
- j++;
- }
- nowSysParam.saveFlag=0x55;
- memcpy(&nowSysParam.saveData,&Meassage.QRcode,sizeof(Meassage.QRcode)); //????????????
- w25q_eraseSector(0x0000);
- w25q_writeNoCheck((uint8_t *)&nowSysParam,0x0000,sizeof(nowSysParam));//???????flash?
-
- Meassage.Error_Code=52;//設置二維碼成功
- // printf("Meassage.QRcode:%s\r\n",Meassage.QRcode);
-
- }
- else
- {
- Meassage.Error_Code=53;//設置二維碼成功失敗
- }
- }
- Rseponse=1;
- }
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
sunctrl.7z
(2.95 MB, 下載次數(shù): 120)
2020-6-5 16:50 上傳
點擊文件名下載附件
ec20 stm32 阿里云 下載積分: 黑幣 -5
|