Jump to content

Recommended Posts



I'm new to MSP430,  I'm using a MSP430G2553 in a project and need help with an in depth understanding of programming the ADC10 inputs of the MCU. I'm using a potentiometer in order to light one of 3 LEDs. 


For example, LED1 lights up when input voltage is 1V or less, LED2 lights up between 1V and 2V and LED3 lights up when the input voltage is greater than or equal to 2V. I have attached my code below but I am not clear on how to read, convert and store a voltage so that I can use the IF statements to light the respective LEDs.


#include <msp430g2553.h>

void indicator_LED();


int main(void) {

unsigned int i;


    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

    P1DIR = 0x00;

    P2DIR = 0xff;

    P1OUT = 0x00;

    P2OUT = 0x00;




    while(1) // keep looping



       ADC10CTL1 = CONSEQ_2 + INCH_0;                                             // Repeat single channel, A0

       ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;                          // Sample & Hold Time + ADC10 ON + Interrupt Enable

       ADC10DTC1 = 0x0A;                                                          // 10 conversions

       ADC10AE0 |= 0x01;                                                          // P1.0 ADC option select



       ADC10CTL0 |= ENC + ADC10SC;                                                // Sampling and conversion start


       __low_power_mode_0();                                                      //__bis_SR_register (CPUOFF + GIE);// LPM0, ADC10_ISR will force exit


       if (ADC10MEM <= 0x228 && ADC10MEM > 0x1D6)


               P2OUT = P2OUT | BIT1;



       else if (ADC10MEM <= 0x1D6)


               P2OUT = P2OUT | BIT2;



       else if (ADC10MEM > 0x228)


               P2OUT = P2OUT | BIT0;





               P2OUT = ~P2OUT;





Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now