I am using an msp430g2553 as my microcontroller. The program i am using for codi
ID: 2085599 • Letter: I
Question
I am using an msp430g2553 as my microcontroller. The program i am using for coding is IAR Embedded Workbench IDE. I have connected the DHt11 to my msp430g2553. The output pin is P1.0. I have found the following codes online that might work. Please guide me with exact steps on how to create a new project on IAR and also provide the finalized code. The code can be in assembly language or C++. If you are using any library or anything,guide me on how to use that too.Here are some useful resources:
http://forum.43oh.com/topic/1825-interfacing-with-dht11-humidty-temp-sensor/
https://sites.google.com/site/simulation314e/home/msp430/msp430dht11
https://www.youtube.com/watch?v=Qj69qfneNzI
https://www.chegg.com/homework-help/questions-and-answers/need-code-either-assembly-language-c--please-give-correct-code-correct-setup-everything-al-q23582953
Use a microcontroller to record the measurements of a DHT11 temperature and humidity Sensor. BER 1 a 1.GND:ground 2.VCC: 3.3V-5VDC 3.OUTPUT LAExplanation / Answer
Please keep the following in mind:
1. The slave will be controlled at the datasheet indicated voltage level might be other than the master. Here, DHT is associated with 5V and the MSP is on the 3V3
2. Associate the draw up resistor of 5K on the Data line
3. If it's not too much trouble guarantee you have the capacitor associated with maintain a strategic distance from any voltage dropouts
4. For DHT11, you need to permit adequate holes previously you would re be able to start another arrangement of information from the sensor. if it's not too much trouble experience the datasheet of the slave altogether before you utilize it.
//////////////////////////DHT11 handler/////////////////////////////////////////
bool dht11(void)
{
volatile int lost_time=0,bit_cnt;
volatile unsigned char temperature;
bool data_validity = false;
P1DIR |= DHT11; // this will Makes the pin OUTput
P1OUT &= ~DHT11;//THE Start condition will generate for DHT11
_delay_cycles(2000); // delays 1 ms for each scanning
P1OUT |= DHT11;// Start condition will give for DHT11
P1DIR &= ~DHT11; // will create the pin input
P1IFG &= ~DHT11; // Clears pin flag, if the value is high
while((P1IN&DHT11)==DHT11); // we have wait till the slave pulls the pin low
///////////////// DHT11 has responded /////////////////////////////
do {
elapsed_time++; // check if the lost time = 80 micro Seconds
} while ((P1IN&DHT11)==0);
if(lost_time <=10)
{
lost_time = 0;
do {
lost_time++; // we have to look if the lost time = 80 micro seconds
} while ((P1IN&DHT11)==DHT11);
if(lost_time <=10)// we have to look if the lost time = 80 microseconds
{
///////// humidity integer/////////////
for(bitcountnt=0;bitcountnt <8;bitcountnt++) // for the humidity 1st byte
{
while ((P1IN&DHT11)==0); // skip for less than 50 microseconds
lost_time = 0;
do {
lost_time++; // look if the lost time = 80 microseconds
} while ((P1IN&DHT11)==DHT11);
if(lost_time >5)
{
humidity_int |= 0x01;
humidity_int <<= 1;
}
else
{
humidity_int &= ~0x01;
humidity_int <<= 1;
}
}
///////// humidity decimal/////////////
for(bit_cnt=0;bit_cnt <8;bit_cnt++) // for humidity 1st byte
{
while ((P1IN&DHT11)==0); // skip for less than 50 microseconds
loast_time = 0;
do {
lost_time++; // look if the lost time = 80 microseconds
} while ((P1IN&DHT11)==DHT11);
if(lost_time >5)
{
humidity_decimals |= 0x01;
humidity_decimals <<= 1;
}
else
{
humidity_decimals &= ~0x01;
humidity_decimals <<= 1;
}
}
///////// temperature integer/////////////
for(bit_cnt=0;bit_cnt <8;bit_cnt++) // for the humidity 1st byte
{
while ((P1IN&DHT11)==0); // skip the lower 50 microsecond
lost_time = 0;
do {
lost_time++; // check if the lost time = 80 microseconds
} while ((P1IN&DHT11)==DHT11);
if(lost_time >5)
{
temperature_int |= 0x01;
temperature_int <<= 1;
}
else
{
temperature_int &= ~0x01;
temperature_int <<= 1;
}
}
///////// temperature decimal/////////////
for(bit_count=0;bit_count <8;bit_count++) // for humidity 1st byte
{
while ((P1IN&DHT11)==0); // skip the lower 50 microsecond
lost_time = 0;
do {
lost_time++; // check if the lost time = 80 microsecond
} while ((P1IN&DHT11)==DHT11);
if(lost_time >5)
{
temperature_decimals |= 0x01;
temperature_decimals <<= 1;
}
else
{
temperature_decimals &= ~0x01;
temperature_decimals <<= 1;
}
}
/////////Parity/////////////
for(bit_count=0;bit_count <8;bit_count++) // for humidity 1st byte
{
while ((P1IN&DHT11)==0); // skip the lower 50 microsecond
lost_time = 0;
do {
lost_time++; // check if the lost time = 80 microsecond
} while ((P1IN&DHT11)==DHT11);
if(elapsed_time >5)
{
parity = 0x01;
parity <<= 1;
}
else
{
parity &= ~0x01;
parity <<= 1;
}
}
}
}
parity_calculation = humidity_int+humidity_decimals+temperature_int+temperature_decimals;
// if(humidity_int<=0x4C)
// {
// humidity_low= true;
// }
// else
// {
// humidity_high= true;
// }
if(parity_calculation == parity)
{
data_validity = true;
}
return data_validity;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.