This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR6989: float value to lcd

Part Number: MSP430FR6989
Other Parts Discussed in Thread: MSP-EXP430FR6989

I need to get the voltage on the LCD but it dosen't work.

#include <msp430.h>
#include <string.h>
#include <stdlib.h>
#include "driverlib.h"
#include "hal_LCD.h"
#define STARTUP_MODE         0

volatile unsigned char mode = STARTUP_MODE;

// rezultate ADC - matrice cu 10 masuratori
int ADC_results [10][4];
// index ADC în matricea ADC_resuts; initializare cu 0
volatile unsigned short usiButton1 = 0;
unsigned int index_ADC = 0;
int ind_ADC;
char disp_ADC [50];
char sample1_ADC [5];
char sample2_ADC [5];
char sample3_ADC [5];
char sample4_ADC [5];
int value=0;

int vol1;

int main(void) {
    int j,k;


    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    for (j= 0; j<10; j++)
        for (k= 0; j<4; j++)
            ADC_results [j][k] = 0;

    GPIO_setAsInputPinWithPullUpResistor( GPIO_PORT_P1, GPIO_PIN1 );



    ADC12_B_initParam initParam = {0};
    initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
    initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
    initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
    initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
    initParam.internalChannelMap = ADC12_B_NOINTCH;
    ADC12_B_init(ADC12_B_BASE, &initParam);


    ADC12_B_setupSamplingTimer(ADC12_B_BASE,
    ADC12_B_CYCLEHOLD_64_CYCLES,
    ADC12_B_CYCLEHOLD_64_CYCLES,
    ADC12_B_MULTIPLESAMPLESENABLE);

    //Enable the ADC12 B module
    ADC12_B_enable(ADC12_B_BASE);

    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE0, 0, 0);
    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE1, 0, 0);
    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE2, 0, 0);
    ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE3, 0, 0);

    ADC12_B_configureMemoryParam configureMemoryParam = {0};
    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A4;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_1;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A5;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_2;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A6;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_3;
    configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A7;
    configureMemoryParam.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
    configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
    configureMemoryParam.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;
    configureMemoryParam.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;
    ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

    ADC12_B_startConversion(ADC12_B_BASE,
    ADC12_B_MEMORY_0,
    ADC12_B_REPEATED_SEQOFCHANNELS);


   Init_LCD();
   PMM_unlockLPM5();

    __bic_SR_register(GIE);
    __bis_SR_register(GIE);
    while (1)
    {
        __bic_SR_register(GIE);

        if (index_ADC == 0)
            ind_ADC= 9;
        else
            ind_ADC= index_ADC-1;

       ltoa((long) ADC_results[ind_ADC][0], sample1_ADC);
       ltoa((long) ADC_results[ind_ADC][1], sample2_ADC);
       ltoa((long) ADC_results[ind_ADC][2], sample3_ADC);
       ltoa((long) ADC_results[ind_ADC][3], sample4_ADC);

       usiButton1 = GPIO_getInputPinValue ( GPIO_PORT_P1, GPIO_PIN1 );

               if ( usiButton1 == GPIO_INPUT_PIN_LOW ) {
                  value=value+1;}



if(value==1){
       strcpy(disp_ADC, "1 ");
       strcat(disp_ADC, sample1_ADC);
       displayScrollText(disp_ADC);

}

if(value==2){
       strcpy(disp_ADC, "2 ");
       strcat(disp_ADC, sample2_ADC);
       displayScrollText(disp_ADC);

}

if(value==3){
       strcpy(disp_ADC, "3 ");
       strcat(disp_ADC, sample3_ADC);
       displayScrollText(disp_ADC);

}

if(value==4){
       strcpy(disp_ADC, "4 ");
       strcat(disp_ADC, sample4_ADC);
       displayScrollText(disp_ADC);

}
if(value==4)
value=0;
__bis_SR_register(GIE);
    }



}


// intreruperilor pt ADC12MEM0 (ADC12_B_MEMORY_0) pana la ADC12MEM3
// cele 4 locatii de mem asociate canalelor ADC 4, 5, 6, 7

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
  {
    case ADC12IV_NONE:        break;        // Vector  0:  No interrupt
    case ADC12IV_ADC12OVIFG:  break;        // Vector  2:  ADC12MEMx Overflow
    case ADC12IV_ADC12TOVIFG: break;        // Vector  4:  Conversion time overflow
    case ADC12IV_ADC12HIIFG:  break;        // Vector  6:  ADC12BHI
    case ADC12IV_ADC12LOIFG:  break;        // Vector  8:  ADC12BLO
    case ADC12IV_ADC12INIFG:  break;        // Vector 10:  ADC12BIN

    case ADC12IV_ADC12IFG0:                 // Vector 12:  ADC12MEM0 Interrupt
          ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG0);
          index_ADC++;
      if (index_ADC == 10)                   //
          index_ADC=0;
      int volt;
      volt=(float)(ADC12MEM0*3.3/4096)*1000;
      ADC_results [index_ADC][0]= volt;
//      __bic_SR_register_on_exit(LPM0_bits);       // Exit active CPU
      break;                                        // Clear CPUOFF bit from 0(SR)
    case ADC12IV_ADC12IFG1:                         // Vector 14:  ADC12MEM1
            ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG1);
        ADC_results [index_ADC][1]= ADC12MEM1;
        break;
    case ADC12IV_ADC12IFG2:                         // Vector 16:  ADC12MEM2
            ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG2);
        ADC_results [index_ADC][2]= ADC12MEM2;
        break;

    case ADC12IV_ADC12IFG3:                         // Vector 18:  ADC12MEM3
           ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG3);
        ADC_results [index_ADC][3]= ADC12MEM3;
        break;


    default: break;
  }
}




**Attention** This is a public forum