#include "msp430fg4618.h" void ADC_init(void); void Clock_init(void); unsigned int sample; void main (void){ WDTCTL = WDTPW | WDTHOLD; ADC_init(); for(;;){ ADC12CTL0 |= ADC12SC; // Start conversions while (!(ADC12IFG & 0x8000)); // Conversion done? sample = ADC12MEM15; } } void ADC_init(void){ unsigned int i; /* Configure ADC12 */ P10SEL |= BIT6; // Enable A/D channel A0 ADC12CTL0 &= ~ENC; // Enable conversions ADC12CTL0 = ADC12ON + SHT1_2 + REFON + REF2_5V; ADC12CTL1 = SHS_0 + CONSEQ_2 + CSTARTADD_15; ADC12MCTL15 = INCH_15 + SREF_1; for (i = 0x3600; i; i--); // Delay for needed ref start-up. // See datasheet for details. ADC12CTL0 |= ENC; // Enable the ADC } void Clock_init(void){ /* Set System Clock Frequency to (121+1) * 32786 * 2 = 7.995392Mhz This freq. allows for 2400 - 230400 bit rate UART operation with less than 0.86% error */ FLL_CTL0 = (DCOPLUS | XCAP14PF); //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 14pF SCFI0 = (FLLD_2 | FN_8); //Set Multiplier to 2, and DCO range to 8MHz nominal SCFQCTL = 121; //7.995392Mhz Operation with No Modulation // Loop until 32kHz crystal stabilizes do { IFG1 &= ~OFIFG; // Clear oscillator fault flag _delay_cycles(50000); } while (IFG1 & OFIFG); // Test osc fault flag }