|
#include "msp430x54x.h"
unsigned int T1;
/********************************************
函数名称:Init_ADC
功 能:初始化ADC
参 数:无
返回值 :无
********************************************/
void Init_ADC(void)
{
P6SEL |= 0x01; // 使能ADC通道
ADC12CTL0 = ADC12ON+ADC12SHT0_2+ADC12REFON+ADC12REF2_5V+ADC12MSC;//打开ADC12模块,设置采样时间,转换使能,打开内部参考电压且选择2.5V
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_2; // 使用采样定时器,选择单通道多次转换模式
ADC12CTL0 |= ADC12ENC; // 使能转换,由SAMPCON上升沿启动首次转换
ADC12MCTL0 =ADC12SREF_1+ADC12INCH_0;//参考电压源选择内参考,采样通道选择A0
ADC12CTL0 |= ADC12SC; // 开始转换,启动AD
ADC12IE = 0x01; // 使能ADC中断
}
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // 关闭看门狗
Init_ADC();
_EINT();
while (1)
{
__no_operation(); // SET BREAKPOINT HERE
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
T1= ADC12MEM0;
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
为什么每次采样总是少0.2V啊 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|