Hello everyone,
I have a problem with programming my MSP430 Launchpad with processor G2553.
I have two programmes, one steers LED diode and the second one makes ADC conversion.
However, I would like to perform both of them (LED steering and ADC conversion) in one cycle in order to decrease power
consumtpion. I've made several trials, but wihtout success. Can anyone help me? Thx in advance.
First program:
#include <msp430g2553.h>
void main(void)
{
volatile unsigned int i; // Volatile to prevent removal
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
__bis_SR_register(SCG1 + SCG0); // Stop DCO
P1DIR = 0xFF; // All P1.x outputs
P1OUT = 0; // All P1.x reset
P2DIR = 0xFF; // All P2.x outputs
P2OUT = 0; // All P2.x reset
for (;;)
{
P1OUT |= 0x01; // P1.0 set
for (i = 0.5; i > 0; i--);
P1OUT &= ~0x01; // P1.0 reset
for (i = 80; i > 0; i--);
}
}
Second program:
#include "msp430g2553.h"
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_1; // input A1
ADC10AE0 |= 0x02; // PA.1 ADC option select
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;)
{
//for (i = 100; i > 0; i--); // Delay 1x
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
if (ADC10MEM < 0x1FF)
P1OUT |= 0x01; // Set P1.0 LED on
else
P1OUT &= ~0x01; // Clear P1.0 LED off
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}