Documentos de Académico
Documentos de Profesional
Documentos de Cultura
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.
1.2.
5.
6.
7.1
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
2.
MSP430G2553
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.
1.2.
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
1000
unsigned
unsigned
unsigned
unsigned
char tempMode;
char calibrateUpdate = 0;
char tempPolarity = TEMP_SAME;
int TXByte;
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);
void main(void)
{
unsigned int uartUpdateTimer = UART_UPDATE_INTERVAL;
unsigned char i;
WDTCTL = WDTPW + WDTHOLD;
// Stop WDT
InitializeClocks();
InitializeButton();
InitializeLeds();
PreApplicationMode();
// Enable interrupts.
tempAverage += tempMeasured[i];
tempAverage >>= 3;
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();
}
LED_OUT |= LED0;
LED_OUT &= ~LED1;
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;
}
// 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 );
// 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);
}
void InitializeButton(void)
{
BUTTON_DIR &= ~BUTTON;
BUTTON_OUT |= BUTTON;
BUTTON_REN |= BUTTON;
BUTTON_IES |= BUTTON;
BUTTON_IFG &= ~BUTTON;
BUTTON_IE |= 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
3.
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.
#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
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.
#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.
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.
5.
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif
TIMERA1_VECTOR
TIMERA0_VECTOR
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;
}
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
//
//
//
//
//
//
//
#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
20
6.
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif
TIMERA1_VECTOR
TIMERA0_VECTOR
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;
}
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
void ConfigLEDs(void)
21
{
P1DIR = BIT6 + BIT0;
P1OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}
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.
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
TIMERA1_VECTOR
22
#define TIMER0_A0_VECTOR
#endif
TIMERA0_VECTOR
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;
}
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);
}
void ConfigLEDs(void)
23
{
P1DIR = BIT6 + BIT0;
P1OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}
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
TIMERA1_VECTOR
TIMERA0_VECTOR
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;
}
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);
}
void ConfigLEDs(void)
{
P1DIR = BIT6 + BIT0;
P1OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}
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.
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif
TIMERA1_VECTOR
TIMERA0_VECTOR
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;
}
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);
}
27
void ConfigPins(void)
{
P1DIR = ~BIT3;
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}
//
//
//
//
//
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
#include <msp430g2553.h>
#ifndef TIMER0_A1_VECTOR
#define TIMER0_A1_VECTOR
#define TIMER0_A0_VECTOR
#endif
TIMERA1_VECTOR
TIMERA0_VECTOR
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);
29
}
void ConfigPins(void)
{
P1DIR = ~BIT3;
P1OUT = 0;
P2SEL = ~(BIT6 + BIT7);
P2DIR |= BIT6 + BIT7;
P2OUT = 0;
}
void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0;
}
//
//
//
//
//
#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]
31