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

326 10. SYSTEM LEVEL DESIGN
There are 16 different LEDs to drive for the wind speed indicator. Rather than use 16 micro-
controller pins, the binary value of the LED for illumination is provided to the 74HCT154 4-to-16
decoder. The decoder provides a “one cold output as determined by the binary code provided on
port P4[3:0]. For example, when A
16
is provided to the 74HCT154 input, output /Y10 is asserted
low, while all other outputs remain at logic high. An interface circuit is required for each LED as
shown in the figure.
The system also includes an MMC/SD flash memory card as a data logger. The card is
interfaced to the MSP430 via the serial peripheral interface (SPI). The interface and programming
of the MMC/SD is covered in considerable detail in Interfacing the MSP430 with MMC/SD flash
memory card [slaa281b].” This information will not be duplicated here. We leave the interface of
the MMC/SD flash memory card to the MSP430 as a homework assignment.
10.2.4 UML ACTIVITY DIAGRAMS
The UML activity diagram for the main program is provided in Figure 10.8. After initializing the
subsystems, the program enters a continuous loop where temperature and wind direction is sensed
and displayed on the LCD and the LED display. The sensed values are then transmitted via the SPI
to the MMC/SD card. The system then enters a delay to set how often the temperature and wind
direction parameters are updated. We have you construct the individual UML activity diagrams for
each function as an end of chapter exercise.
10.2.5 MICROCONTROLLER CODE
Provided below is the code for the weather station. Here are some items of interest related to the
code:
Portions of the code were adapted from an example provided by Texas Instruments and written
by Smertneck and Goh.
The code has been compartmentalized into reusable functions.
Each subsystem will be initialized within its own function.
Bit names to set register values are defined in the msp430x54x.h header file.
//include file****************************************************
#include "msp430x54x.h"
//function prototypes*********************************************
void hold_watchdog(void);
void initialize_ports(void);
void temperature_to_LCD(unsigned int ADCValue);
void readADC12(unsigned char);
10.2. WEATHER STATION 327
weather vane
Vcc = 3.3 V
P7.5
LM34
Vcc = 5 V
temperature sensor
75
1uF
P7.4
SerLCD V2.5 command set
RX to TX: P3.4
Vcc = 3.3 VDC
N
S
E
W
LED0
LED4
LED8
LED12
74HCT154
4:16
decoder
(17)Y15
LED15
E0(18)
E1(19)
(1)Y0
(2)Y1
(3)Y2
Vcc = 3.3 VDC
(24)
LED0
LED1
LED2
A0(23)
A1(22)
A2(21)
A3(20)
(12)
pin 1
reset
JP4
JP5
LCD
crystal
joystick
accelerometer
5.0
6.7
7.5
7.7
3.4
3.6
4.0
4.2
4.5
4.7
5.5
8.5
5.1
7.4
7.6
Gnd
3.5
3.7
4.1
4.3
4.6
5.4
7.3
8.6
V
DD
= 3.3 VDC
R
+
74LVC04
I
P4.0
P4.1
P4.2
P4.3
Clear display
Move cursor right
Move cursor left
Scroll right
Scroll left
Display on
Display off
Underline cursor on
Underline cursor off
Blinking cursor on
Blinking cursor off
Set cursor position
0x01
0x14
0x10
0x1C
0x18
0x0C
0x08
0x0E
0x0C
0x0D
0x0C
0x80+
SerLCD V2.5
MMC card
CS
DI
VSS
SCK
CD
D0
Figure 10.7: Circuit diagram for weather station.
328 10. SYSTEM LEVEL DESIGN
include files
global variables
function prototypes
initialize ADC
initialize USART
initialize LCD
while(1)
convert temp
convert wind direction
display temp &
wind direction on LCD
display wind direction
on LED
transmit results
via USART
delay(desired_update_time)
Figure 10.8: Weather station UML activity diagram.
10.2. WEATHER STATION 329
void putChar(unsigned char);
void putcommand(unsigned char);
void display_data(void);
void InitUART_A0(void);
void UART_TX_A0(unsigned char data);
void convert_wind_direction(unsigned int);
void delay_15_min(void);
//Global Variables*************************************************
unsigned int temperature, wind_direction;
unsigned int binary_weighted_voltage_low, binary_weighted_voltage_high;
unsigned char dir_tx_data;
void main(void)
{
hold_watchdog();
initialize_ports();
InitUART_A0();
while(1)
{
//temp data:read->display->transmit
readADC12(0x04); //Read Temp - LM34
temperature = ADC12MEM4;
temperature_to_LCD (temperature); //Convert and display temp on LCD
readADC12(0x05); //Read wind direction
wind_direction = ADC12MEM5;
convert_wind_direction(wind_direction); //Convert wind direction
delay_15_min(); //delay 15 minutes
}
}
//***********************************************************************
void hold_watchdog(void)
{
WDTCTL = WDTPW + WDTHOLD; //hold Watchdog Timer
330 10. SYSTEM LEVEL DESIGN
}
//***********************************************************************
void initialize_ports()
{
//Port P4 - output for 74HCT154
P4DIR = 0xFF; //configure port P4 (0:input, 1:output)
P4SEL = 0x00; //P4 select (0:digital I/O, 1:alternate func)
P4OUT = 0x00; //P4 out - when input selects resistor
// (0:pulldown, 1: pullup)
P4REN = 0x00; //P4REN - resistor enable
// (0: disable resistor, 1: enable resistor)
//Port P7 - ADC
P7DIR = P7DIR & 0xCF; //configure port P7 (0:input, 1:output)
//P7.4, P7.5 analog inputs, other pins
// unchanged
P7SEL = 0x30; //P4 select (0:digital I/O, 1:alternate func)
//P7.4, P7.5 analog input
P7OUT = 0x00; //P4 out - when input selects resistor
// (0:pulldown, 1: pullup)
P7REN = 0x00; //P4REN - resistor enable
// (0: disable resistor, 1: enable resistor)
}
//***********************************************************************
//readADC12(unsigned char channel) This function provides a single
//ADC conversion on the specified channel.
//
//An external reference is used.
The MSP430F5438 Experimenter Board is
//configured with AVcc, pin 11 connected
to 3.3 VDC and the AVss, pin 12 //connected to ground.
We set VR+ and VR- to these two values
using the //ADC12SREFx bits in the ADC12MCTLx register.
//
//A single conversion is performed on the specified channel passed into
//the function.

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