27
Finally, it allows interrupts and enters the main loop. At the end of each execution of the
main loop, the program enters the Low-Power Mode 0. Only the interrupts force to leave
the LPM0.
The main loop contains a routine for the pressure sensor because it regularly needs to
be checked its status. If the pressure does not answer (for example if it was removed
and placed again), it is reset.
As a demonstration code, the main.c gives access to the following global variables:
switch1 and switch2: 1 byte numbers counting the number of impulses on SW1
PIEZO1 and PIEZO2.
adc12_3V3: adc value of the 3.3V line.
adc12_bat: adc value of the battery level.
adc12_pot1 and adc12_pot2: adc values of the POT1 and POT2.
sensor1..3: pressure value in mbar of SENSOR1, SENSOR2 and SENSOR3
when available.
sensTp1..3: temperature value in °C of SENSOR1, SENSOR2 and SENSOR3
when available.
Timer
The timer.c and timer.h only contain two initialization functions that configure the TimerA
to count timer based on the XT1 32,768 Hz. It generates 8 TimerA overflow interrupts
per second that are handled in interrupt.c.
The second initialization function sets the DCO to a precise 19,988,840 Hz. MCLK is set
to 19,988,840 Hz and SMCLK is set to MCLK/2. This is the function to be modified if
you need to change the MSP430’s frequency.
LEDs
The led source and header files contain simple functions to set and clear the LED 1 to 4. They
allow to move up or down their positions or to display a lighting effect for start-up.
PowerManager
The power manager sets and clears the enable pin EN_REG2 for the main regulator of
the board. At start-up, the power manager sets EN_REG2 high. If EN_REG1 goes low
after start-up, then the power manager controls when the whole board will shut down.