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

238 7. RESETS AND INTERRUPTS
//
//M Smertneck / W. Goh
//Texas Instruments Inc.
//September 2008
//Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
//***********************************************************************
#include "msp430x54x.h"
void main(void)
{
WDTCTL = WDT_MDLY_32;
//WDT 32ms,SMCLK,interval timer
SFRIE1 |= WDTIE; //Enable WDT interrupt
P1DIR |= 0x01; //Set P1.0 to output direction
__bis_SR_register(LPM0_bits + GIE); //Enter LPM0, enable interrupts
__no_operation(); //For debugger
}
//***********************************************************************
// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR(void)
{
P1OUT ˆ= 0x01; //Toggle P1.0 (LED)
}
//***********************************************************************
It should be noted, if recursive interrupts or nesting interrupts are desired, the GIE bit in
Status Register (SR) should be set inside an ISR. If nesting interrupts are allowed on purpose, a
programmer must be sure that the stack will have enough space to accommodate the number of
consecutive nested interrupts.
7.6 LABORATORY EXERCISE
In many smart homes, electronic appliances are networked together to monitor power usage through-
out the day. The idea is to minimize collective power usage during the peak time and perform tasks
during the low power usage time. For example, a refrigerator can delay generating ice cubes, if it
detects that the electric fan is operating at the same time. An LCD (Liquid Crystal Display) may
turn itself off, it is not being used. Furthermore, assume that some of these electronic systems in
7.6. LABORATORY EXERCISE 239
house are battery operated. In this laboratory exercise, you are to implement the controller for a bat-
tery operated electronic temperature controller for a living room, which must periodically transmit
wirelessly its status (power level) to a central station, check to see whether the temperature is within
a programmed range, and turn on a heater/air conditioner if necessary until the desired temperature
is reached.
While it is not in use, the controller should be in a power saving mode, LPM3.5, and should be
turned on every five minutes to perform the periodic task. It should use its internal clock as the timer
and use the related interrupt system to wake up” and sleep” during and in between consecutive
tasks. Since we have not covered the wireless transmission capabilities of MSP430, simply write
0x01h to Port 1 to indicate that the power level is healthy and 0xFFh to let the central controller
know that the power is below the desired level. Assume that the power level is constantly updated at
memory locations 0x1000h-0x1001h and values above 0x8000 represent sufficient power capacity.
To turn on the heater or the air conditioner, your program must write 0x01 or 0xFF to Port 2,
respectively. Writing 0x00h to Port 2 turns off both systems.
Figure 7.16 shows the setup for your temperature controller.
Temperature
Controller
Window
Living Room
Power Status Signals
Heater/Air-Conditioner
Control Signals
Figure 7.16: Temperature controller for a smart home.

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