MSP430 ADC Sample Code
MSP430 ADC Sample Code
by Brandon Cerge
The code below will continuously sample a voltage on channel A0 on the MSP430 and display the 10-bit result in 16-bit format (ie, 0x00000x03FF) on the LCD screen. See UF_LCD tutorial for wiring of the LCD screen.
#include <msp430x22x2.h> #include <UF_LCD.h> void main(void){ WDTCTL = WDTPW + WDTHOLD; DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; ADC10CTL1 |= CONSEQ1; ADC10CTL0 |= ADC10SHT_2 + ADC10ON + MSC; ADC10AE0 |= 0x01; ADC10CTL0 |= ADC10SC + ENC; lcd_init(); lcd_char('0'); lcd_char('x'); // disable watch dog timer // set internal oscillator at 16MHz // set internal oscillator at 16MHz //continuous sample mode, MUST BE SET FIRST! //sample and hold time, adc on, cont. sample // select channel A0 // start conversions //get the lcd booted up // only need to write this once //only need to write this once
while(42){ //infinite loop (with meaning) lcd_byte((ADC10MEM >> 8) & 0x0003); //write upper byte lcd_byte(ADC10MEM & 0x00FF); //write lower byte lcd_command(0x82); //place cursor back at position 2 } }