Question: #include #define MOISTURE _ SENSOR _ PIN INCH _ 0 #define BUZZER _ PIN BIT 1 void initADC ( ) ; void initBuzzer ( )

#include
#define MOISTURE_SENSOR_PIN INCH_0
#define BUZZER_PIN BIT1
void initADC();
void initBuzzer();
void buzz();
int readMoisture();
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
initADC();
initBuzzer();
while (1)
{
int moistureLevel = readMoisture();
if (moistureLevel <500)
{
buzz();
}
__bis_SR_register(LPM0_bits + GIE);
}
}
void initADC()
{
ADC10CTL0= ADC10SHT_3+ ADC10ON;
ADC10CTL1= MOISTURE_SENSOR_PIN;
}
void initBuzzer()
{
P2DIR |= BUZZER_PIN;
}
void buzz()
{
P2OUT |= BUZZER_PIN;
__delay_cycles(100000);
P2OUT &= ~BUZZER_PIN;
}
int readMoisture()
{
ADC10CTL0|= ENC + ADC10SC;
while (ADC10CTL1 & ADC10BUSY);
return ADC10MEM;
}
write the configuration of ports and peripherals for first time use:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!