Hi I'm Bharath relatively new to MSP430 and TI's products.
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. While I made sure the ADC working fine by toggling a LED so that works but only if all LCD codes are commented out.
I tried just displaying 'Test - 1' ,'Test - 2' and 'Test-3' part it works.
Its the transfer of ADC to LCD that does not work , there are some problems in the code which I'm unable to sort out after freakishly debugging.Some extra hands might be useful.
#include <msp430fr4133.h>
#define pos1 4 // Digit A1 - L4
#define pos2 6 // Digit A2 - L6
#define pos3 8 // Digit A3 - L8
#define pos4 10 // Digit A4 - L10
#define pos5 2 // Digit A5 - L2
#define pos6 18 // Digit A6 - L18
#define LEDR BIT0
#define LEDG BIT0
unsigned int sensor[1];
unsigned int splitchar[3];
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"
};
int main( void )
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= LEDR; // Set P1.0/LED to output direction
P1OUT &= ~LEDR; // P1.0 LED off
P4DIR |= LEDG; // Set P4.0/LED to output direction
P4OUT &= ~LEDG;
// Configure Clock
P4SEL0 |= BIT1 | BIT2; // P4.2~P4.1: crystal pins
/* do
{
CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1 & OFIFG); // Test oscillator fault flag
*/
CSCTL6 = (CSCTL6 & ~(XT1DRIVE_3)) | XT1DRIVE_2; // Higher drive strength and current consumption for XT1 oscillator
// Configure ADC A8 + A9 pins and
SYSCFG2 |= ADCPCTL8 ;
// Configure XT1 oscillator
// 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;
// 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(1) {
ADCMCTL0 |= ADCINCH_8 | ADCSREF_0;
ADCCTL0 |= ADCENC | ADCSC ; // Sampling and conversion start
while(ADCCTL1 & ADCBUSY);
sensor[0] = ADCMEM0;
_delay_cycles(10000);
if (sensor[0] > 0x1FF)
P1OUT |= LEDR; // Set P1.0 LED on
else
P1OUT &= ~LEDR; // Clear P1.0 LED off
_delay_cycles(10000);
sensor[1]=sensor[0];
for (i = 0 ; i<=3 ; i++ ) {
splitchar[i] |= sensor[1] % 10;
_delay_cycles(10000);
sensor[1] |= sensor[1] / 10;
_delay_cycles(10000);
}
LCDMEM[pos6] = digit[(splitchar[0])];
_delay_cycles(50000);
LCDMEM[pos5] = digit[(splitchar[1])];
_delay_cycles(50000);
LCDMEM[pos4] = digit[(splitchar[2])];
_delay_cycles(50000);
LCDMEM[pos3] = digit[(splitchar[3])];
_delay_cycles(50000);
/* Test- 1
splitchar[0] |= 3;
splitchar[1] |= 4;
splitchar[2] |= 8;
splitchar[3] |= 9;
LCDMEM[pos6] = digit[(splitchar[0])];
_delay_cycles(10000);
LCDMEM[pos5] = digit[(splitchar[1])];
_delay_cycles(10000);
LCDMEM[pos4] = digit[(splitchar[2])];
_delay_cycles(10000);
LCDMEM[pos3] = digit[(splitchar[3])];
_delay_cycles(10000);
*/
/* Test - 2
for(i=1;i<=4;i++) {
LCDMEM[pos6] = digit[(splitchar[i])];
_delay_cycles(100000);
LCDMEM[pos5] = digit[(splitchar[i])];
_delay_cycles(100000);
LCDMEM[pos4] = digit[(splitchar[i])];
_delay_cycles(100000);
LCDMEM[pos3] = digit[(splitchar[i])];
_delay_cycles(100000);
}
*/
/* Test - 3
LCDMEM[pos1] = digit[1];
LCDMEM[pos2] = digit[2];
LCDMEM[pos3] = digit[3];
LCDMEM[pos4] = digit[4];
LCDMEM[pos5] = digit[5];
LCDMEM[pos6] = digit[6];
*/
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
// __bis_SR_register(LPM3_bits | GIE); // Enter LPM3.5
// __no_operation(); // For debugger
}
}