#include "PM2_5.h"
void delay(int i);
void calculateA();
void calculateB();
double timeA,timeB,occupancyA,occupancyB;
int concA,concB;
//----------------Get concentration data----------------------------
void getPM2_5(){
TimerAopen();
TimerBopen();
while(1){
if(secB>=10 || secA>=10){ //Need to change after setting time
secB=0;
secA=0;
break;
}
}
return;
}
//----------------Send concentration data----------------------------
void sendPM2_5(){
int tempA[4];
int tempB[4];
calculateA(); //Calculate duty cycle and concentration
calculateB();
//----------------------------
/*
int temp2[10];
for(int i=0;i<10;i++){
temp2[i]=(int)width%10;
width=width/10;
}
for(int j=9;j>=0;j--){
Uart1_PutByte(temp2[j]+48);
}
*/
//----------------------------
for(int i=10000;i>0;i--);
for(int i=10000;i>0;i--);
for(int i=10000;i>0;i--);
for(int i=10000;i>0;i--);
Send data
for(int i=0;i<4;i++){
tempA[i]=(int)concA%10;
concA=concA/10;
tempB[i]=(int)concB%10;
concB=concB/10;
}
for(int j=3;j>=0;j--){
Uart1_PutByte(tempA[j]+48);
}
//Uart1_PutByte('\t ');
for(int j=3;j>=0;j--){
Uart1_PutByte(tempB[j]+48);
}
//Uart1_PutByte('\n');
widthA=0;
widthB=0;
}
void delay(int i){
for(int x=i;x>0;x--)
for(int j=110;j>0;j--);
}
void calculateA(){
timeA=widthA*0.000001;
occupancyA=timeA*(1.0/10.0)*100; //need to change after setting time
//convert to concentration
concA=(int)(occupancyA*20);
}
void calculateB(){
timeB=widthB*0.000001;
occupancyB=timeB*(1.0/10.0)*100; //need to change after setting time
//convert to concentration
concB=(int)(occupancyB*20);
}
|