O'Reilly logo

Microcontroller Programming and Interfacing Texas Instruments MSP430 by Daniel J. Pack, Steven F. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

264 8. ANALOG PERIPHERALS
#include "msp430xG46x.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop WDT
ADC12CTL0 = REF2_5V + REFON; //Internal 2.5V ref on
TACCR0 = 13600; //Delay to allow Ref to settle
TACCTL0 |= CCIE; //Compare-mode interrupt.
TACTL = TACLR + MC_1 + TASSEL_2; //up mode, SMCLK
__bis_SR_register(LPM0_bits + GIE); //Enter LPM0, enable interrupts
TACCTL0 &= ˜CCIE; //Disable timer interrupt
__disable_interrupt(); //Disable Interrupts
DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC; // Int ref gain 1
DAC12_0DAT = 0x0666; //1.0V
__bis_SR_register(LPM0_bits + GIE); //Enter LPM0
}
//***********************************************************************
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
TACTL = 0; //Clear Timer_A control registers
__bic_SR_register_on_exit(LPM0_bits);//Exit LPMx, interrupts enabled
}
//***********************************************************************
8.7 LABORATORY EXERCISE
In this section, your task is to program both the ADC12 and DAC12 converters to perform two
smart home functions. How many times have you been told by your parents to turn off lights as
you were growing up? Or if you are a parent, how many times did you have to remind your children
to turn off lights when they leave their rooms? In the smart home of our choice, we will solve this
problem once and for all. We will do so using the MSP430 controller’s analog-to-digital converters.
To that end, suppose that we installed infrared sensors at each room of the house to detect
human locations. A precise location of each human is measured using multiple infrared sensors, and
based on the locations of humans, in the house, lights will automatically be turned on and turned
off. An infrared sensor consists of a transmitter and a receiver. The transmitter sends out an infrared
signal and waits for any reflection of the transmitted signal. If a human is in the path of the signal,
the signal is reflected back to the receiver. By measuring the amount of reflection of the light, we can
compute the distance of a human from the particular sensor. By placing these sensors at appropriate

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required