Bootstrap

MSP430笔记5——ADC的使用

一、DTC的初始化设置

SREFx 设置基准电压
INCH 选择ADC输入通道

/*设置ADC,采集电压*/
void InitADC(void)
{
   
	  /*设置ADC时钟MCLK*/
	  ADC10CTL1 |= ADC10SSEL_2;
	  /*ADC 2分频*/
	  ADC10CTL1 |= ADC10DIV_0;
	  /*设置ADC基准源*/
	  ADC10CTL0 |= SREF_1;  
	  /*设置ADC采样保持时间64CLK*/
	  ADC10CTL0 |= ADC10SHT_3;
	  /*设置ADC采样率200k*/
	  ADC10CTL0 &= ~ADC10SR;
	  /*ADC基准选择2.5V*/
	  ADC10CTL0 |= REF2_5V;
	  /*开启基准*/
	  ADC10CTL0 |= REFON;
	  /*选择ADC输入通道A0*/
	  ADC10CTL1 |= INCH_0;
	  /*允许A0模拟输入*/
	  ADC10AE0 |= 0x0001;
	  /*开启ADC*/
	  ADC10CTL0 |= ADC10ON;
}
/*ADC的转换(模拟->数字)*/
uint16_t GetADCValue(void)
{
   
	  /*开始转换*/
	  ADC10CTL0 |
;