|
使用STM32F103C8T6連接阿里云,上傳溫濕度,并包含兩個(gè)開關(guān)控制。
- #include "stm32f10x.h" // Device header
- #include "OLED.H"
- #include <stdio.h>
- #include "Delay.h"
- #include "MyUSART.H"
- #include "AD.H"
- #include "esp.h"
- #include "DHT11.H"
- #include "MySPI.H"
- #include "PWM.H"
- #include "LED.H"
- int Temperature;
- int Shidu;
- uint8_t Lock='0';
- uint8_t Switch2='0';
- extern char RECS[200];
- extern char Data[5];
- uint16_t cnt;
- uint16_t AD;
- float Volatge;
- void Init(void)
- {
- uint8_t Judge=0;
- OLED_Init();
- OLED_ShowString(1,1,"Linking...");
- MyUSART_Init(); //初始化串口
- PWM_Init();
- do
- {
- Judge = esp_Init();
- OLED_ShowString(1,1,"error code: ");
- OLED_ShowNum(2,1,Judge,1);
- }while(Judge); //連接阿里云直到成功
-
- RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA ,ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStructure);
- GPIO_ResetBits(GPIOA,GPIO_Pin_2);//LED初始化為低電平(關(guān))
-
- }
- int main(void)
- {
- Init();
- // AD_Init ();
- OLED_Clear();
- OLED_ShowString (1,1,"Secure");
- OLED_ShowCHinese (1,12,4);
- OLED_ShowCHinese (1,14,5);
- OLED_ShowCHinese (2,1,0);
- OLED_ShowCHinese (2,3,2);
- OLED_ShowCHinese (2,5,3);
- OLED_ShowCHinese (3,1,1);
- OLED_ShowCHinese (3,3,2);
- OLED_ShowCHinese (3,5,3);
- while(1)
- {
- AD=ADC_GetValue();
- Volatge =(float) AD/4055*3.3;
- if(Volatge>=0.2)
- LED_ON();
- cnt++;
- if(cnt%150==0)
- DHT11_GetData(); //約每1s執(zhí)行一次溫濕度采集
- if(cnt==600) //約每6s執(zhí)行一次數(shù)據(jù)上報(bào)
- {
- if(Esp_PUB() == 1)
- {
- OLED_ShowString(1,1,"publish failed");
- Delay_ms(500);
- OLED_Clear();
- }
- cnt=0;
- }
-
- Shidu=Data[0];
- Temperature=Data[2];
- OLED_ShowNum(2,7,Temperature,2);
- OLED_ShowSignedNum(2,12,40,2);
- OLED_ShowNum(3,7,Shidu,2);
- OLED_ShowSignedNum(3,12,60,2);
- CommandAnalyse ();
- if(Lock=='0')
- PWM_SetCompare(5);
- else if(Lock=='1')
- PWM_SetCompare(15);
- if(Switch2=='0')
- GPIO_ResetBits(GPIOA,GPIO_Pin_2);
- else if(Switch2=='1')
- GPIO_SetBits(GPIOA,GPIO_Pin_2);
- }
-
- }
復(fù)制代碼
原理圖: 無(wú)
仿真: 無(wú)
代碼:
STM32F103C8T6阿里云.7z
(184.71 KB, 下載次數(shù): 29)
2024-3-17 21:28 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|