MSP430 adc模数转换程序
/*************
参考电压2.5V,给6.0i/o口电压(不超过3.3v)
查看adc12mem0中的值,2.5/4096*adc12mem0,即为真实电压
*************/
#include <msp430f5529.h>
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; //关闭开门狗
P6SEL |= 0x01; //使能A0输入通道,此为外围模块
REFCTL0 &= ~REFMSTR; //复位控制位以控制寄存器
ADC12CTL0 = ADC12ON+ADC12SHT02+ADC12REFON+ADC12REF2_5V; //打开ADC12,设置采样间隔,打开电压参考电压发生器,设置参考电压为2.5V
ADC12CTL1 = ADC12SHP; //采样保持触发信号,选择采样定时器
ADC12MCTL0 = ADC12SREF_1; //Vr+=Vref+,Vr—=AVss
for(i=0;i<0x30;i++); //延迟使参考电压稳定
ADC12CTL0 |= ADC12ENC; //使能A/D转换
while(1)
{
ADC12CTL0 |= ADC12SC; //开始转换
while((!ADC12IFG & BIT0));
__no_operation(); //可设置断点查看
}
} |