//******************************************************************************
// MSP-FET430P140 Demo - ADC12, Using the Internal Reference
//
// Description:
//
//
// MSP430F149
// ---------------
// | |
// Vin -->|P6.0/A0 |
// | |
//
//
// ZhenHua Liu
// NWSUAF.
// 2017,12,05
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include
#include"adc.h"
void DelayXms(unsigned int i); //delay about x ms
void uartInit(); //Init the usart0
void sendChar(char c); //send a char
void sendString(unsigned char *p); //send a string,input must be pointer
void int2charssend(int value); //convert the adc value to string and send it
void main(void)
{
int adcValue1,adcValue2;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
uartInit(); //init the uart
while (1)
{
unsigned int GetAdcValue1(void){
unsigned int value; //digital value
P6SEL |= BIT0+BIT1; // Enable A/D channel A0
ADC12CTL0 = ADC12ON+SHT0_6; // Turn on and set up ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12MCTL0 =INCH_0+ SREF_0; // Vr+=VCC,Vr+=VSS,switch the inch1
ADC12CTL0 |= ENC; // Enable conversions
ADC12MEM0 = 0; //首先对转化结果的寄存器清零
ADC12CTL0 |= ADC12SC; // Start conversion
while ((ADC12IFG & BIT0)==0);
_NOP(); // SET BREAKPOINT HERE
value = ADC12MEM0;
return value;
}
unsigned int GetAdcValue2(void){
unsigned int value; //digital value
P6SEL |= BIT0+BIT1; // Enable A/D channel A0
ADC12CTL0 = ADC12ON+SHT0_6; // Turn on and set up ADC12
ADC12CTL1 = SHP; // Use sampling timer
ADC12MCTL0 =INCH_1+ SREF_0; // Vr+=VCC,Vr+=VSS,switch the inch1
ADC12CTL0 |= ENC; // Enable conversions
ADC12MEM0 = 0; //首先对转化结果的寄存器清零
ADC12CTL0 |= ADC12SC; // Start conversion
while ((ADC12IFG & BIT0)==0);
_NOP(); // SET BREAKPOINT HERE
value = ADC12MEM0;
return value;
}
adc.h如下:
[cpp] view plain copy
#ifndef _ADC_H_
#define _ADC_H_
unsigned int GetAdcValue1(void); //start adc and return a digital value (0-4096)
unsigned int GetAdcValue2(void); //start adc and return a digital value (0-4096)
#endif