I had bought MSP-EXP430FR4133 to try out some codes and build small products based on it.I did go through the sample codes provided in MSP430ware.
I wanted to do a ADC on P8.1 and then display the Numeric code ( 0 to 1023 ) on to the LCD provided along with the Launchpad.
Apparently the LCD displays random values instead of the 10 Bit ADC one.Can some body help.
Code is as below.
#include <msp430fr4133.h> unsigned int sensor[2]; unsigned int splitchar[4]= { 0,0,0,0 }; unsigned int i; unsigned int j; const char digit[10] ={ 0xFC, // "0" 0x60, // "1" 0xDB, // "2" 0xF3, // "3" 0x67, // "4" 0xB7, // "5" 0xBF, // "6" 0xE4, // "7" 0xFF, // "8" 0xF7 // "9" };
ADC - CODES
// Configure ADC A8 SYSCFG2 |= ADCPCTL8 ; // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; // Configure ADC10 ADCCTL0 |= ADCSHT_1 | ADCMSC | ADCON ; // ADCON, S&H=16 ADC clks ADCCTL1 |= ADCSHP | ADCCONSEQ_0 | ADCDIV_2; // ADCCLK = MODOSC; sampling timer ADCCTL2 |= ADCRES; // 10-bit conversion results ADCIE |= ADCIE0;
LCD CODE
// Configure LCD pins SYSCFG2 |= LCDPCTL; // R13/R23/R33/LCDCAP0/LCDCAP1 pins selected LCDPCTL0 = 0xFFFF; LCDPCTL1 = 0x07FF; LCDPCTL2 = 0x00F0; // L0~L26 & L36~L39 pins selected LCDCTL0 = LCDSSEL_0 | LCDDIV_7; // flcd ref freq is xtclk // LCD Operation - Mode 3, internal 3.08v, charge pump 256Hz LCDVCTL = LCDCPEN | LCDREFEN | VLCD_6 | (LCDCPFSEL0 | LCDCPFSEL1 | LCDCPFSEL2 | LCDCPFSEL3); LCDMEMCTL |= LCDCLRM; // Clear LCD memory LCDCSSEL0 = 0x000F; // Configure COMs and SEGs LCDCSSEL1 = 0x0000; // L0, L1, L2, L3: COM pins LCDCSSEL2 = 0x0000; LCDM0 = 0x21; // L0 = COM0, L1 = COM1 LCDM1 = 0x84; // L2 = COM2, L3 = COM3
WHILE LOOP - CODE
while(1) { ADCMCTL0 |= ADCINCH_8 | ADCSREF_0; ADCCTL0 |= ADCENC | ADCSC ; // Sampling and conversion start while(ADCCTL1 & ADCBUSY); sensor[0] = ADCMEM0; _delay_cycles(10000); sensor[1]=sensor[0]; for (i = 0 ; i<=3 ; i++ ) { splitchar[i] |= sensor[1] % 10; ADCMEM0 = splitchar[i]; sensor[1] |= sensor[1] / 10; _delay_cycles(10000); } LCDMEM[pos6] = digit[(splitchar[0])]; LCDMEM[pos5] = digit[(splitchar[1])]; LCDMEM[pos4] = digit[(splitchar[2])]; LCDMEM[pos3] = digit[(splitchar[3])]; LCDCTL0 |= LCD4MUX | LCDON; // Turn on LCD, 4-mux selected PMMCTL0_H = PMMPW_H; // Open PMM Registers for write PMMCTL0_L |= PMMREGOFF_L; // and set PMMREGOFF }