<< Chapter < Page | Chapter >> Page > |
source_code/iar_v4.11/lab_ezwsn.eww
with IAR. The project corresponding to this section is called
led_button
. .#include "io430.h"
#include "in430.h"int main( void )
{WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x03;P1DIR&= ~0x04;
P1REN |= 0x04;P1IE |= 0x04;
__bis_SR_register(GIE);while(1);
}#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void){
P1IFG&= ~0x04;
P1OUT ^= 0x03;}
Toggle LEDs state using the button
Some keys for understanding the code:
P1.0
and
P1.1
as outputs (for the LEDs), and
P1.2
as input
(for the button);P1.2
. This is needed for a button for the
signal to be cleaner when the button is pressed; i.e. otherwise, the
P1.2
constantly
floats between high and low state. This is only needed for buttons.P1.2
.PORT1_VECTOR
happens; the name
Port_1
chosen has no importance.As such, the board sits idle while waiting for an interrupt to happen with the MSP430 on (which continuously executed line 11). After measuring this current,you will change the code so as to enter low-power mode instead of sitting idle.
__bis_SR_register(GIE+LPM0_bits);
. This instructs
the MSP430 to enable the interrupts globally, and to enter LPM0 modeimmediately. Only an interrupt can wake the MSP430.You should obtain results close to:
Active mode (active: CPU and all clock) | 3.28mA |
LPM0 mode (active: SMCLK, ACLK; disabled: CPU, MCLK) | 2.88mA |
LPM3 mode (active: ACLK; disabled: CPU, MCLK, SMCLK) | 2.72mA |
LPM4 mode (disabled: CPU and all clock) | 2.72mA |
Note that, because we are not using any clock in this example, we should use LPM4 as it is the most energy-efficient.
Notification Switch
Would you like to follow the 'Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500' conversation and receive update notifications?