Está en la página 1de 31

INSTITUTO TECNOLOGICO DE QUERTARO

Departamento de Ingeniera Elctrica- Electrnica.


Ingeniera Electrnica
Microcontroladores ETD1022
WorkShop
Hernndez Cortes Mauricio 12140755
Castellanos Galindo Jos Joaqun
31 de Agosto de 2016

Resumen
En este documento presento la instalacin de el software necesario para la programacin del MSP430G255 de
Texas Instruments, adems de los cdigos que nos proporciona el fabricante como ejemplo para cargar
cdigos en el mismo micro controlador, con el propsito de familiarizarnos con el IDE para dicho aparato, asi
como evidencias de su funcionamiento.

ndice
Objetivo: ................................................................................................................................................. 2
Marco Terico ......................................................................................................................................... 2
1.

Micro Controlador....................................................................................................................... 2

2.

MSP430G2553............................................................................................................................. 2

Desarrollo ................................................................................................................................................ 3
1. LAB 1 LAB 2: Code Composer Studio ..................................................................................... 3

3.

1.1.

Instalacion de Code Composer Studio ................................................................................ 3

1.2.

Temperature Sense Demo y Crystal Oscillator ................................................................... 4

Lab3: Initialization and GPIO ..................................................................................................... 11


2.1.

Running the CPU on the Crystal ........................................................................................ 12

2.3 Running the CPU on the DCO and the Crystal......................................................................... 13


2.4.
4.

Lab 4: Analog-to-Digital Converter............................................................................................ 15


4.1.

5.

Test the ADC Conversion Process ..................................................................................... 16

Lab 5: Timer and Interrupts ...................................................................................................... 17


5.1

6.

Running the CPU on the DCO without a Crystal ............................................................... 15

Implement the Delay, ISR.................................................................................................. 18

Lab 6: Low-Power Modes .......................................................................................................... 21


6.1.

Reconfigure the I/O for Low-Power .................................................................................. 22

6.2 Fully Optimized Code for Low-Power .................................................................................... 25


7.

Lab 7: Serial Communications ................................................................................................... 27


1

7.1

Remove Timer_A2 and Add WDT+ as the Interval Timer ................................................. 29

Conclusin ............................................................................................................................................ 31
Bibliografa ........................................................................................................................................... 31

Objetivo:
Conocer la interfaz de desarrollo para la programacin del micro controlador, asi como
comprender la sintaxis de programacin y arquitectura del mismo mediante la lectura y
comprensin de fichas tcnicas para poder implementar cdigos mediante Code Composer
Studio.

Marco Terico
1.

Micro Controlador

Un microcontrolador es un circuito integrado que en su interior contiene una unidad central


de procesamiento (CPU), unidades de memoria (RAM y ROM), puertos de entrada y salida y
perifricos. Estas partes estn interconectadas dentro del microcontrolador, y en conjunto
forman lo que se le conoce como microcomputadora. Se puede decir con toda propiedad que
un microcontrolador es una microcomputadora completa encapsulada en un circuito
integrado. [1]

2.

MSP430G2553

MSP quiere decir Mixed Signal Processor


Los Micro controladores de la serie MSP430 de Texas Instruments, Son procesadores de seal combinada de 16
bits, basados en la arquitectura RISC, que significa Reduced Instruction Set Computer, diseados para tener un
consumo ulta bajo, adems disponen de una cantidad de perifricos muy variados para realizar proyectos muy
diversos. Tiene una velocidad de reloj configurable entre 1 y 16 MHz, Memoria Flash de 16KB, Memoria RAm
de 512 B, Memoria NVM de 56KB, 24 Pines GPIO como mximo, dos temporiadores, Convertidr de ADC de 8
canales, UART, I2C, SPI. [2].

Desarrollo
1. LAB 1 LAB 2: Code Composer Studio
Verificar que tenemos instalado Code Composer Studio, adems de las aplicaciones
o documentos extra que se nos indican descargar para poder tener el control completo
de estas practicas por hacer.
Tambien tenemos que conocer las caractersticas de Code Composer Studio para
poder comunicarnos con el microcontrolador, asi como su interfaz para con el
usuario, que es til para saber como ingresar cdigos en el micro asi como crear
proyectos nuevos.
Ademas de las instrucciones para empezar a trabajar con el micro controlador, se nos
proporciona un cristal con la indicacin de soldarlo a el Launch Pad en el rea de
ejecucin.

1.1.

Instalacion de Code Composer Studio

1.2.

Temperature Sense Demo y Crystal Oscillator

1.2.1. Codigo Temperatura


//Temperatura
#include "msp430g2553.h"
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif

TIMERA1_VECTOR
TIMERA0_VECTOR

#define
#define
#define
#define

LED0
LED1
LED_DIR
LED_OUT

BIT0
BIT6
P1DIR
P1OUT

#define
#define
#define
#define
#define
#define
#define
#define

BUTTON
BUTTON_OUT
BUTTON_DIR
BUTTON_IN
BUTTON_IE
BUTTON_IES
BUTTON_IFG
BUTTON_REN

BIT3
P1OUT
P1DIR
P1IN
P1IE
P1IES
P1IFG
P1REN

#define
#define

TXD
RXD

BIT1
BIT2

#define
#define

APP_STANDBY_MODE
APP_APPLICATION_MODE

0
1

#define
#define
#define
#define

TIMER_PWM_MODE
TIMER_UART_MODE
TIMER_PWM_PERIOD
TIMER_PWM_OFFSET

0
1
2000
20

#define
#define
#define

TEMP_SAME
TEMP_HOT
TEMP_COLD

0
1
2

#define

TEMP_THRESHOLD

//
Conditions for 9600/4=2400 Baud SW UART, SMCLK = 1MHz
#define
Bitime_5
0x05*4
+ small adjustment
#define
Bitime
13*4//0x0D
#define

UART_UPDATE_INTERVAL

// TXD on P1.1
// RXD on P1.2

// ~ 0.5 bit length

1000

unsigned char BitCnt;

unsigned char applicationMode = APP_STANDBY_MODE;


unsigned char timerMode = TIMER_PWM_MODE;

unsigned
unsigned
unsigned
unsigned

char tempMode;
char calibrateUpdate = 0;
char tempPolarity = TEMP_SAME;
int TXByte;

/* Using an 8-value moving average filter on sampled ADC values */


long tempMeasured[8];
unsigned char tempMeasuredPosition=0;
long tempAverage;
long tempCalibrated, tempDifference;

void InitializeLeds(void);
void InitializeButton(void);
void PreApplicationMode(void);
press
void ConfigureAdcTempSensor(void);
void ConfigureTimerPwm(void);
void ConfigureTimerUart(void);
void Transmit(void);
void InitializeClocks(void);

// Blinks LED, waits for button

void main(void)
{
unsigned int uartUpdateTimer = UART_UPDATE_INTERVAL;
unsigned char i;
WDTCTL = WDTPW + WDTHOLD;
// Stop WDT
InitializeClocks();
InitializeButton();
InitializeLeds();
PreApplicationMode();

// Blinks LEDs, waits for button press

/* Application Mode begins */


applicationMode = APP_APPLICATION_MODE;
ConfigureAdcTempSensor();
ConfigureTimerPwm();
__enable_interrupt();

// Enable interrupts.

/* Main Application Loop */


while(1)
{
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);

// Sampling and conversion start


// LPM0 with interrupts enabled

/* Moving average filter out of 8 values to somewhat stabilize sampled ADC */


tempMeasured[tempMeasuredPosition++] = ADC10MEM;
if (tempMeasuredPosition == 8)
tempMeasuredPosition = 0;
tempAverage = 0;
for (i = 0; i < 8; i++)

tempAverage += tempMeasured[i];
tempAverage >>= 3;

// Divide by 8 to get average

if ((--uartUpdateTimer == 0) || calibrateUpdate )
{
ConfigureTimerUart();
if (calibrateUpdate)
{
TXByte = 248;
// A character with high value,
outside of temp range
Transmit();
calibrateUpdate = 0;
}
TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );
Transmit();
uartUpdateTimer = UART_UPDATE_INTERVAL;
ConfigureTimerPwm();
}

tempDifference = tempAverage - tempCalibrated;


if (tempDifference < -TEMP_THRESHOLD)
{
tempDifference = -tempDifference;
tempPolarity = TEMP_COLD;
LED_OUT &= ~ LED1;
}
else
if (tempDifference > TEMP_THRESHOLD)
{
tempPolarity = TEMP_HOT;
LED_OUT &= ~ LED0;
}
else
{
tempPolarity = TEMP_SAME;
TACCTL0 &= ~CCIE;
TACCTL1 &= ~CCIE;
LED_OUT &= ~(LED0 + LED1);
}
if (tempPolarity != TEMP_SAME)
{
tempDifference <<= 3;
tempDifference += TIMER_PWM_OFFSET;
TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) :
(TIMER_PWM_PERIOD-1) );
TACCTL0 |= CCIE;
TACCTL1 |= CCIE;
}
}
}
void PreApplicationMode(void)
{
LED_DIR |= LED0 + LED1;

LED_OUT |= LED0;
LED_OUT &= ~LED1;

// To enable the LED toggling effect

BCSCTL1 |= DIVA_1;
BCSCTL3 |= LFXT1S_2;

// ACLK/2
// ACLK = VLO

TACCR0 = 1200;
TACTL = TASSEL_1 | MC_1;
TACCTL1 = CCIE + OUTMOD_3;
TACCR1 = 600;
__bis_SR_register(LPM3_bits + GIE);

//
// TACLK = SMCLK, Up mode.
// TACCTL1 Capture Compare
// LPM0 with interrupts enabled

}
void ConfigureAdcTempSensor(void)
{
unsigned char i;
/* Configure ADC Temp Sensor Channel */
ADC10CTL1 = INCH_10 + ADC10DIV_3;
// Temp Sensor ADC10CLK/4
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
__delay_cycles(1000);
// Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);
// LPM0 with interrupts enabled
tempCalibrated = ADC10MEM;
for (i=0; i < 8; i++)
tempMeasured[i] = tempCalibrated;
tempAverage = tempCalibrated;
}

void ConfigureTimerPwm(void)
{
timerMode = TIMER_PWM_MODE;
TACCR0 = TIMER_PWM_PERIOD;
TACTL = TASSEL_2 | MC_1;
TACCTL0 = CCIE;
TACCTL1 = CCIE + OUTMOD_3;
TACCR1 = 1;

//
// TACLK = SMCLK, Up mode.
// TACCTL1 Capture Compare

}
void ConfigureTimerUart(void)
{
timerMode = TIMER_UART_MODE;
CCTL0
TACTL
P1SEL
P1DIR

= OUT;
= TASSEL_2 + MC_2 + ID_3;
|= TXD + RXD;
|= TXD;

// Configure TimerA0_0 UART TX


// TXD Idle as Mark
// SMCLK/8, continuous mode
//
//

}
// Function Transmits Character from TXByte
void Transmit()
{
BitCnt = 0xA;
// Load Bit counter, 8data + ST/SP
while (CCR0 != TAR)
// Prevent async capture
CCR0 = TAR;
// Current state of TA counter

CCR0 += Bitime;
TXByte |= 0x100;
TXByte = TXByte << 1;
CCTL0 = CCIS0 + OUTMOD0 + CCIE;
while ( CCTL0 & CCIE );

// Some time till first bit


// Add mark stop bit to TXByte
// Add space start bit
// TXD = mark = idle
// Wait for TX completion

// Timer A0 interrupt service routine


#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
if (timerMode == TIMER_UART_MODE)
{
CCR0 += Bitime;
if (CCTL0 & CCIS0)
{
if ( BitCnt == 0)
CCTL0 &= ~ CCIE;
interrupt
else
{
CCTL0 |= OUTMOD2;
if (TXByte & 0x01)
CCTL0 &= ~ OUTMOD2;
TXByte = TXByte >> 1;
BitCnt --;
}
}
}
else
{
if (tempPolarity == TEMP_HOT)
LED_OUT |= LED1;
if (tempPolarity == TEMP_COLD)
LED_OUT |= LED0;
TACCTL0 &= ~CCIFG;
}
}

// Add Offset to CCR0


// TX on CCI0B?

// All bits TXed, disable

// TX Space
// TX Mark

#pragma vector=TIMER0_A1_VECTOR
__interrupt void ta1_isr(void)
{
TACCTL1 &= ~CCIFG;
if (applicationMode == APP_APPLICATION_MODE)
LED_OUT &= ~(LED0 + LED1);
else
LED_OUT ^= (LED0 + LED1);
}
void InitializeClocks(void)
{
BCSCTL1 = CALBC1_1MHZ;

// Set range

DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3);

// SMCLK = DCO / 8 = 1MHz

}
void InitializeButton(void)
{
BUTTON_DIR &= ~BUTTON;
BUTTON_OUT |= BUTTON;
BUTTON_REN |= BUTTON;
BUTTON_IES |= BUTTON;
BUTTON_IFG &= ~BUTTON;
BUTTON_IE |= BUTTON;
}

// Configure Push Button

void InitializeLeds(void)
{
LED_DIR |= LED0 + LED1;
LED_OUT &= ~(LED0 + LED1);
}
/* *************************************************************
* Port Interrupt for Button Press
* 1. During standby mode: to exit and enter application mode
* 2. During application mode: to recalibrate temp sensor
* *********************************************************** */
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
BUTTON_IFG = 0;
BUTTON_IE &= ~BUTTON;
/* Debounce */
WDTCTL = WDT_ADLY_250;
IFG1 &= ~WDTIFG;
/* clear interrupt flag */
IE1 |= WDTIE;
if (applicationMode == APP_APPLICATION_MODE)
{
tempCalibrated = tempAverage;
calibrateUpdate = 1;
}
else
{
applicationMode = APP_APPLICATION_MODE; // Switch from STANDBY to APPLICATION
MODE
__bic_SR_register_on_exit(LPM3_bits);
}
}
#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR(void)
{
IE1 &= ~WDTIE;
IFG1 &= ~WDTIFG;
WDTCTL = WDTPW + WDTHOLD;
BUTTON_IE |= BUTTON;
}

/*
/*
/*
/*

disable interrupt */
clear interrupt flag */
put WDT back in hold state */
Debouncing complete */

10

// ADC10 interrupt service routine


#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF);
}

// Return to active mode

Codigo Crystal Oscillator


#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // watchdog timer setup
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If cal constants erased, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
P1DIR = 0x41; // I/O setup
P1OUT = 0x01;
BCSCTL3 |= LFXT1S_0 + XCAP_3; // clock system setup
while(IFG1 & OFIFG) // wait for OSCFault to clear
{
IFG1 &= ~OFIFG;
_delay_cycles(100000);
}
P1OUT = 0; // both LEDs off
//_bis_SR_register(SCG1 + SCG0); // clock system setup
BCSCTL2 |= SELM_0 + DIVM_3;
while(1)
{
P1OUT = 0x40; // LED on
_delay_cycles(100);
P1OUT = 0; // LED off
_delay_cycles(5000);
}
}

3.

Lab3: Initialization and GPIO

En esta practica, Se introduce el manejo de el Sistema de reloj, adems de El watchdog que nos permite evitar
perder de control al micro en caso de que las instrucciones sean errneas, asi como usar en los cdigos varias
fuentes de reloj.[3]

11

#include "msp430g2553.h"
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // watchdog timer setup
P1DIR = 0x40; // I/O setup
P1OUT = 0;
BCSCTL3 |= LFXT1S_2; // clock system setup
IFG1 &= ~OFIFG;
_bis_SR_register(SCG1 + SCG0);
BCSCTL2 |= SELM_3 + DIVM_3;
while(1)
{
P1OUT = 0x40; // LED on
_delay_cycles(100);
P1OUT = 0; // LED off
_delay_cycles(5000);
}
}

2.1.

Running the CPU on the Crystal

#include "msp430g2553.h"
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // watchdog timer setup

12

P1DIR = 0x41; // I/O setup


P1OUT = 0x01;
BCSCTL3 |= LFXT1S_0 + XCAP_3; // clock system setup
while(IFG1 & OFIFG) // wait for OSCFault to clear
{
IFG1 &= ~OFIFG;
_delay_cycles(100000);
}
P1OUT = 0; // both LEDs off
_bis_SR_register(SCG1 + SCG0); // clock system setup
BCSCTL2 |= SELM_3 + DIVM_3;
while(1)
{
P1OUT = 0x40; // LED on
_delay_cycles(100);
P1OUT = 0; // LED off
_delay_cycles(5000);
}
}

2.3 Running the CPU on the DCO and the Crystal


#include "msp430g2553.h"
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // watchdog timer setup
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If cal constants erased,

13

} // trap CPU!!
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
P1DIR = 0x41; // I/O setup
P1OUT = 0x01;
BCSCTL3 |= LFXT1S_0 + XCAP_3; // clock system setup
while(IFG1 & OFIFG) // wait for OSCFault to clear
{
IFG1 &= ~OFIFG;
_delay_cycles(100000);
}
P1OUT = 0; // both LEDs off
// _bis_SR_register(SCG1 + SCG0); // clock system setup
BCSCTL2 |= SELM_0 + DIVM_3;
while(1)
{
P1OUT = 0x40; // LED on
_delay_cycles(100);
P1OUT = 0; // LED off
_delay_cycles(5000);
}
}

14

2.4.

Running the CPU on the DCO without a Crystal

#include "msp430g2553.h"
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // watchdog timer setup
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If cal constants erased,
} // trap CPU!!
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
P1DIR = 0x40; // I/O setup
P1OUT = 0;
BCSCTL3 |= LFXT1S_2; // clock system setup
IFG1 &= ~OFIFG;
// _bis_SR_register(SCG1 + SCG0);
BCSCTL2 |= SELM_0 + DIVM_3;
while(1)
{
P1OUT = 0x40; // LED on
_delay_cycles(100);
P1OUT = 0; // LED off
_delay_cycles(5000);
}
}

4.

Lab 4: Analog-to-Digital Converter

Probar el funcionamiento del chip analogico digital integrado en el micro controlador

15

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
void FaultRoutine(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR = 0x41; // P1.0&6 outputs
P1OUT = 0; // LEDs off
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If cal data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8
while(1)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(5); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling & conversion start
P1OUT = 0x40; // green LED on
_delay_cycles(100);
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON);
tempRaw = ADC10MEM;
P1OUT = 0; // green LED off
_delay_cycles(125000);
}
}
void FaultRoutine(void)
{
P1OUT = 0x01; // red LED on
while(1); // TRAP }

4.1.

Test the ADC Conversion Process


16

5.

Lab 5: Timer and Interrupts

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif

TIMERA1_VECTOR
TIMERA0_VECTOR

volatile long tempRaw;


void
void
void
void
void

FaultRoutine(void);
ConfigWDT(void);
ConfigClocks(void);
ConfigLEDs(void);
ConfigADC10(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigLEDs();
ConfigADC10();
while(1)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(5);
// Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion start
P1OUT = 0x40;
// P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC;
// Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON);
// Ref and ADC10 off
tempRaw = ADC10MEM;
// Read conversion value
P1OUT = 0;
// green LED off
_delay_cycles(125000);
// delay 1 second
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD;
}

// Stop watchdog timer

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)

17

FaultRoutine();
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
BCSCTL3 |= LFXT1S_2;
IFG1 &= ~OFIFG;
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;
}
void FaultRoutine(void)
{
P1OUT = 0x01;
while(1);
}
void ConfigLEDs(void)
{
P1DIR = 0x41;
P1OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}

5.1

//
//
//
//
//
//
//

If calibration data is erased


run FaultRoutine()
Set range
Set DCO step + modulation
LFXT1 = VLO
Clear OSCFault flag
MCLK = DCO/8, SMCLK = DCO/8

// P1.0 on (red LED)


// TRAP

// P1.6 and P1.0 outputs


// LEDs off

// Temp Sensor ADC10CLK

Implement the Delay, ISR

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR TIMERA1_VECTOR
#define TIMER0_A0_VECTOR TIMERA0_VECTOR
#endif
volatile long tempRaw;
volatile unsigned int i;
void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigLEDs(void);
void ConfigADC10(void);

18

void ConfigTimerA2(void);
void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigLEDs();
ConfigADC10();
ConfigTimerA2();
_BIS_SR(GIE);
while(1)
{
P1OUT |= BIT0;
for (i = 100; i > 0; i--);
P1OUT &= ~BIT0;
for (i = 5000; i > 0; i--);
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}
void ConfigLEDs(void)
{
P1DIR = BIT6 + BIT0; // P1.6 and P1.0 outputs
P1OUT = 0; // LEDs off
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
}
void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 12000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR;
__interrupt void Timer_A (void)
{

19

ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;


_delay_cycles(5); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
P1OUT |= BIT6; // P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
tempRaw = ADC10MEM; // Read conversion value
P1OUT &= ~BIT6; // green LED off
CCR0 +=12000; // add 12 seconds to the timer
}

20

6.

Lab 6: Low-Power Modes

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif

TIMERA1_VECTOR
TIMERA0_VECTOR

volatile long tempRaw;


volatile unsigned int i;
void
void
void
void
void
void

FaultRoutine(void);
ConfigWDT(void);
ConfigClocks(void);
ConfigLEDs(void);
ConfigADC10(void);
ConfigTimerA2(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigLEDs();
ConfigADC10();
ConfigTimerA2();
_BIS_SR(GIE);
while(1)
{
P1OUT |=
for (i =
P1OUT &=
for (i =
}

BIT0;
100; i > 0; i--);
~BIT0;
5000; i > 0; i--);

}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD;
}

// Stop watchdog timer

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine();
erased
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
modulation
BCSCTL3 |= LFXT1S_2;
IFG1 &= ~OFIFG;
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;
}
void FaultRoutine(void)
{
P1OUT = BIT0;
while(1);
}

// If calibration data is
// run FaultRoutine()
// Set range
// Set DCO step +

// LFXT1 = VLO
// Clear OSCFault flag
// MCLK = DCO/8, SMCLK = DCO/8

// P1.0 on (red LED)


// TRAP

void ConfigLEDs(void)

21

{
P1DIR = BIT6 + BIT0;
P1OUT = 0;
}

// P1.6 and P1.0 outputs


// LEDs off

void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}

// Temp Sensor ADC10CLK

void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 12000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(5);
// Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion
start
P1OUT |= BIT6;
// P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC;
// Disable ADC
conversion
ADC10CTL0 &= ~(REFON + ADC10ON);
// Ref and ADC10 off
tempRaw = ADC10MEM;
// Read conversion
value
P1OUT &= ~BIT6;
// green LED off
CCR0 +=12000;
// add 1 second
to the timer
}

6.1.

Reconfigure the I/O for Low-Power

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR

TIMERA1_VECTOR

22

#define TIMER0_A0_VECTOR
#endif

TIMERA0_VECTOR

volatile long tempRaw;


volatile unsigned int i;
void
void
void
void
void
void

FaultRoutine(void);
ConfigWDT(void);
ConfigClocks(void);
ConfigLEDs(void);
ConfigADC10(void);
ConfigTimerA2(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigLEDs();
ConfigADC10();
ConfigTimerA2();
_BIS_SR(GIE);
while(1)
{
P1OUT |=
for (i =
P1OUT &=
for (i =
}

BIT0;
100; i > 0; i--);
~BIT0;
5000; i > 0; i--);

}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD;
}

// Stop watchdog timer

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine();
// If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ;
// Set range
DCOCTL = CALDCO_1MHZ;
// Set DCO step + modulation
BCSCTL3 |= LFXT1S_2;
// LFXT1 = VLO
IFG1 &= ~OFIFG;
// Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;
// MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0;
while(1);
}

// P1.0 on (red LED)


// TRAP

void ConfigLEDs(void)

23

{
P1DIR = BIT6 + BIT0;
P1OUT = 0;

// P1.6 and P1.0 outputs


// LEDs off

}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}

// Temp Sensor ADC10CLK

void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 36000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(5);
// Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion start
P1OUT |= BIT6;
// P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC;
// Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON);
// Ref and ADC10 off
tempRaw = ADC10MEM;
// Read conversion value
P1OUT &= ~BIT6;
// green LED off
CCR0 +=36000;
// add 1 second to the timer
}

24

6.2 Fully Optimized Code for Low-Power


#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif

TIMERA1_VECTOR
TIMERA0_VECTOR

volatile long tempRaw;


volatile unsigned int i;
void
void
void
void
void
void

FaultRoutine(void);
ConfigWDT(void);
ConfigClocks(void);
ConfigLEDs(void);
ConfigADC10(void);
ConfigTimerA2(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigLEDs();
ConfigADC10();
ConfigTimerA2();
_BIS_SR(GIE);
while(1)
{
P1OUT |=
for (i =
P1OUT &=
for (i =
}

BIT0;
100; i > 0; i--);
~BIT0;
5000; i > 0; i--);

}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD;
}

// Stop watchdog timer

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine();
// If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ;
// Set range
DCOCTL = CALDCO_1MHZ;
// Set DCO step + modulation
BCSCTL3 |= LFXT1S_2;
// LFXT1 = VLO
IFG1 &= ~OFIFG;
// Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;
// MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{

25

P1OUT = BIT0;
while(1);

// P1.0 on (red LED)


// TRAP

}
void ConfigLEDs(void)
{
P1DIR = BIT6 + BIT0;
P1OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}

// P1.6 and P1.0 outputs


// LEDs off

// Temp Sensor ADC10CLK

void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 36000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE ;
_delay_cycles(4); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
CCR0 +=36000; // add 12 seconds to the timer
_bic_SR_register_on_exit(LPM3_bits);
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10 (void)
{
ADC10CTL0 &= ~ADC10IFG; // clear interrupt flag
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
tempRaw = ADC10MEM; // Read conversion value
_bic_SR_register_on_exit(LPM3_bits);
}

26

7.

Lab 7: Serial Communications

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif

TIMERA1_VECTOR
TIMERA0_VECTOR

//volatile long tempRaw;


void
void
void
void
void
void

FaultRoutine(void);
ConfigWDT(void);
ConfigClocks(void);
ConfigPins(void);
ConfigADC10(void);
ConfigTimerA2(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2();
while(1)
{
_bis_SR_register(LPM3_bits + GIE);
}
}
void ConfigWDT(void)
{
WDTCTL = WDTPW + WDTHOLD;
}

// Stop watchdog timer

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine();
// If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ;
// Set range
DCOCTL = CALDCO_1MHZ;
// Set DCO step + modulation
BCSCTL3 |= LFXT1S_2;
// LFXT1 = VLO
IFG1 &= ~OFIFG;
// Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0;
while(1);
}

// P1.0 on (red LED)


// TRAP

27

void ConfigPins(void)
{
P1DIR = ~BIT3;
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}

//
//
//
//
//

P1.3 input, others output


clear output pins
P2.6 and 7 GPIO
P2.6 and 7 outputs
clear output pins

// Temp Sensor ADC10CLK

void ConfigTimerA2(void)
{
CCTL0 = CCIE;
CCR0 = 36000;
TACTL = TASSEL_1 + MC_2;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(5);
// Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion start
P1OUT |= BIT6;
// P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC;
// Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON);
// Ref and ADC10 off
// tempRaw = ADC10MEM;
// Read conversion value
P1OUT &= ~BIT6;
// green LED off
CCR0 +=36000;
// add 12 seconds to the timer
_bic_SR_register_on_exit(LPM3_bits);
}

28

7.1

Remove Timer_A2 and Add WDT+ as the Interval Timer

#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif

TIMERA1_VECTOR
TIMERA0_VECTOR

//volatile long tempRaw;


void
void
void
void
void

FaultRoutine(void);
ConfigWDT(void);
ConfigClocks(void);
ConfigPins(void);
ConfigADC10(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();

while(1)
{
_bis_SR_register(LPM3_bits + GIE);
}
}
void ConfigWDT(void)
{
WDTCTL = WDT_ADLY_250;
IE1 |= WDTIE;
}
void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine();
// If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ;
// Set range
DCOCTL = CALDCO_1MHZ;
// Set DCO step + modulation
BCSCTL3 |= LFXT1S_2;
// LFXT1 = VLO
IFG1 &= ~OFIFG;
// Clear OSCFault flag
BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK = DCO/8, SMCLK = DCO/8
}
void FaultRoutine(void)
{
P1OUT = BIT0;
while(1);

// P1.0 on (red LED)


// TRAP

29

}
void ConfigPins(void)
{
P1DIR = ~BIT3;
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}

//
//
//
//
//

P1.3 input, others output


clear output pins
P2.6 and 7 GPIO
P2.6 and 7 outputs
clear output pins

// Temp Sensor ADC10CLK

#pragma vector=WDT_VECTOR
__interrupt void WDT (void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(5);
// Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC;
// Sampling and conversion start
P1OUT |= BIT6;
// P1.6 on (green LED)
_delay_cycles(100);
ADC10CTL0 &= ~ENC;
// Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON);
// Ref and ADC10 off
// tempRaw = ADC10MEM;
// Read conversion value
P1OUT &= ~BIT6;
// green LED off
// CCR0 +=36000;
// add 12 seconds to the timer
_bic_SR_register_on_exit(LPM3_bits);
}

30

Conclusin
Trabajar con cdigos ya establecidos nos ayuda a observar el funcionamiento de la tarjeta,
mediante la implementacin de LEDs como salidas, lamentablemente en las fotografas
adquiridas no pude capturar los momentos en los que se lleva a cabo intercambios en el
encendico de los LEDs, pero es muy interesante ver como podemos variar el tiempo de
encendido de cada uno de ellos, asi como la frecuencia de encendido, y el retardo para cada
uno de ellos.
Es interesante como se manejan las distintas funciones del micro controlador, como los
temporizadores, asi como la memoria para almacenar los datos, hacer operaciones, cuentas
regresivas, me parece que esta manera de trabajar, simplifica demasiado trabajo permitiendo
mas funcionalidades y nuevos niveles de tecnologa, que bien me parece han llevado la
tecnologa de nuestros das hasta donde esta.

Bibliografa
[1]
[2]
[3]

S.A. (S.F.). Qu es un microcontrolador? Consulta realizada el 30 de Agosto de


2016, en http://www.electronicaestudio.com/microcontrolador.htm
S.A. (S.F.) El microcontrolador MSP430G2553 Consulta realizada el 30 de Agosto de
2016, en http://bibing.us.es/proyectos/abreproy/12159/fichero/4.pdf
MSP430 workshop. Texas Instruments. Revisin 2.22a. Julio, 2013

31

También podría gustarte