1323 views|0 replies

1668

Posts

0

Resources
The OP
 

【MSP430】PM2.5 concentration measurement [Copy link]

#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);
}

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list