|
ADC初始化代码如下
P2SEL |= BIT3; // Set for Timer A1
P2DIR |= BIT3;
// TACCR0 = 7; // Init TACCR0 w/ sample prd=CCR0+1
// TACCR1 = 4; // Trig for ADC12 sample & convert
// TACCTL1 = OUTMOD_3; // Set/reset
// TACTL = TACLR | MC_1 | TASSEL_1; // ACLK, clear TAR, up mode
TACCR0 = SYS_CLK/ADC_FREQ -1; // Init TACCR0 w/ sample prd=CCR0+1
TACCR1 = SYS_CLK/ADC_FREQ/2; // Trig for ADC12 sample & convert
TACCTL1 = OUTMOD_3; // Set/reset
TACTL = TACLR | MC_1 | TASSEL_2; // SMCLK, clear TAR, up mode
P6SEL = 0x0b; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+MSC+SHT0_8+REF2_5V+REFON; // Turn on ADC12, extend sampling time
//ADC12CTL1 = SHP+CONSEQ_3+SHS_1; // Use sampling timer, repeated sequence
ADC12CTL1 = CONSEQ_3+SHS_1;
ADC12MCTL0 = INCH_0+SREF_5; // ref+=ref+, channel = A0
ADC12MCTL1 = INCH_1+SREF_6; // ref+=veref+, channel = A1
//ADC12MCTL1 = INCH_2+SREF_5; //测试霍尔传感器使用
//ADC12MCTL1 = INCH_1+SREF_5; //测试加速度使用
ADC12MCTL2 = INCH_3+SREF_5+EOS; // ref+=ref+, channel = A3
//ADC12MCTL3 = INCH_4+SREF_5; // ref+=ref+, channel = A4
//ADC12MCTL4 = INCH_5+SREF_5+EOS; // ref+=ref+, channel = A5, end seq.
ADC12IE = (1<<2); // Enable ADC12IEG.4,按顺序,最后一个时允许中断
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC; // Start conversion
MCLK = SMCLK = 8M
有经验的朋友帮忙看看,谢谢! |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|