// This program reads from 2 A/D channels (channels 7 and 10). // Channel 7 is connected to a potentiometer on the E5 I/O board, // if the voltage is greater than half the maximum, an LED lights. // Channel 10 is connected to a temperature sensor on the chip. // // If you run the program and turn the pot, the LED goes on and off. // If you pause the program, you can examine the current values of // the two A/D channels in the variables adval_7 and adval_10. // // You don't have to worry about the details of the code that drives // the A/D conversion sequence. #include "msp430F2012.h" void main(void){ int adval_7, adval_10; // Initialization (don't worry about this block of code). WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_1MHZ; // Set clock to 1 MHZ DCOCTL = CALDCO_1MHZ; //Turn ADC on, slow sample for temp sensor, 2.5V ref; ADC10CTL0 = ADC10ON + ADC10SHT_3 + SREF_1 + REF2_5V + REFON; P1DIR |= BIT0; // Make bit 0 an output. while (1) { ADC10CTL0 &= ~ENC; // Disable conversions ADC10CTL1 = INCH_7; // Set to channel 7 (Potentiometer) ADC10CTL0 |= ENC + ADC10SC; // Enable and Start conversion while (ADC10CTL1 & ADC10BUSY); // Wait for conversion to finish adval_7 = ADC10MEM; // Get A/D conversion result // If A/D result > 50% (i.e., 1.25V), turn on LED, else turn it off. if (adval_7 > 0x1FF) P1OUT |= BIT0; else P1OUT &= ~0x01; ADC10CTL0 &= ~ENC; // Disable conversions ADC10CTL1 = INCH_10; // Set to channel 10 (Temp) ADC10CTL0 |= ENC + ADC10SC; // Enable and Start conversion while (ADC10CTL1 & ADC10BUSY); // Wait for conversion to finish adval_10 = ADC10MEM; // Get A/D conversion result } }