Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
154 views

MSP430 ADC Sample Code

This code continuously samples the voltage on the A0 channel of an MSP430 microcontroller. It displays the 10-bit analog-to-digital conversion result as a 16-bit number on an LCD screen. The code configures the ADC, samples the input, and writes the upper and lower bytes of the result to the LCD within an infinite loop.

Uploaded by

Khanh Nam
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views

MSP430 ADC Sample Code

This code continuously samples the voltage on the A0 channel of an MSP430 microcontroller. It displays the 10-bit analog-to-digital conversion result as a 16-bit number on an LCD screen. The code configures the ADC, samples the input, and writes the upper and lower bytes of the result to the LCD within an infinite loop.

Uploaded by

Khanh Nam
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sample Code: A/D Converter for MSP430

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 } }

*note: lcd_byte(char) is a function that must be written by the programmer!!

You might also like