|
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
#include "LCD_Display.h"
#include "dht11.h"
#include "ADC.h"
#include <math.h>
extern u8 TIM2CH2_CAPTURE_STA; //输入捕获状态
extern u16 TIM2CH2_CAPTURE_VAL;
extern u8 time;
int main(void)
{
u8 temperature = 0;
u8 humidity = 0;
u8 ch_Ultrasonic[15]=" "; //转换显示数组
u8 ch_Temperature[15]=" ";
u8 ch_Humidity[15]=" ";
u8 ch_Roll[15]=" ";
u8 ch_Pitch[15]=" ";
u8 ch_Yaw[15]=" ";
float Roll = 0; //ADXL三个参数
float Pitch = 0;
float Yaw = 0;
float Ultrasonic_Data=0;
float X = 0;
float Y = 0;
float Z = 0;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
LED_Init();
DHT11_Init();
ADC1_MultiChannel_Configuration();
//TIM3_PWM_Init(899,0);
TIM2_Cap_Init(0XFFFF,72-1);
TIM3_Int_Init(5000,71);
Stm32_Clock_Init();
STM3210F_LCD_Init();
LCD_Clear(White);
while(1)
{
delay_ms(10);
LCD_SetTextColor(Black);
LCD_DisplayStringLine(Line1,ch_Ultrasonic);
LCD_DisplayStringLine(Line2,ch_Temperature);
LCD_DisplayStringLine(Line3,ch_Humidity);
Roll = Read_ADC1_MultiChannel(12);
Pitch = Read_ADC1_MultiChannel(13);
Yaw = Read_ADC1_MultiChannel(15);
//Roll=(float)(((atan2(Y,X)*180)/3.14159265)+180);
sprintf(ch_Roll,"X = %.3lf",Roll);
LCD_DisplayStringLine(Line4,ch_Roll);
//Pitch=(float)(((atan2(Y,Z)*180)/3.14159265)+180);
sprintf(ch_Pitch,"Y = %.3lf ",Pitch);
LCD_DisplayStringLine(Line5,ch_Pitch);
//Yaw=(float)(((atan2(X,Z)*180)/3.14159265)+180);
sprintf(ch_Yaw,"Z = %.3lf",Yaw);
LCD_DisplayStringLine(Line6,ch_Yaw);
if(TIM2CH2_CAPTURE_STA&0X80)
{
Ultrasonic_Data=TIM2CH2_CAPTURE_STA&0X3F;
Ultrasonic_Data*=65536;
Ultrasonic_Data+=TIM2CH2_CAPTURE_VAL;
Ultrasonic_Data=170*Ultrasonic_Data*1.0/10000;
TIM2CH2_CAPTURE_STA=0;
}
if(time%5 == 0)
{
UltrasonicWave_StartMeasure();
}
if(time%10 == 0)
{
DHT11_Read_Data(&temperature,&humidity);
time = 0;
}
//printf("%.2lf\r\n",temp);//′òó¡×üμĸßμãƽ걼ä
sprintf(ch_Ultrasonic,"U = %.2lf cm",Ultrasonic_Data);
sprintf(ch_Temperature,"T = %d ",temperature);
sprintf(ch_Humidity,"H = %d%%",humidity);
}
}
|
|