这几个关系没有搞清楚void main(void){ WDTCTL = WDTPW | WDTHOLD; // Disable the Watchdog. ADC_Init(); // Initialize ADC12 ADC12CTL0 |= ENC; // Start conversion
//看别人写的程序在这一般都是加一句ADC12CTL0 |= ADC12SC; //但是这里没有这句话, _BIS_SR(LPM0_bits); // Enter LPM0}
void ADC_Init(void){ P1DIR = 0xff; // set port to outputs P1OUT = 0; // reset port outputs P6SEL |= 0x01; // select A0 input ADC12CTL0 = ADC12ON+SHT0_1+REF2_5V+REFON; // Setup ADC12 ADC12CTL1 = SHP+CONSEQ_2+SHS_1; // Timer triggers sampling ADC12MCTL0 = INCH_0 + SREF_1; ADC12IE = 0x0001; // Enable ADC12IFG.0
TACCR0 = 1500; // Delay to allow Ref to settle TACCTL0 |= CCIE; // Compare-mode interrupt. TACTL = TASSEL_1 | MC_1; // TACLK = ACLK, Up mode. _BIS_SR(LPM3_bits + GIE); // Wait for delay, Enable interrupts TACCTL0 &= ~CCIE; // Disable timer
P2SEL |= BIT3; // Set for Timer A1 P2DIR |= 0x08; 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}
// Timer_A0 Interrupt Service Routine#pragma vector=TIMERA0_VECTOR__interrupt void ta0_isr(void){ TACTL = 0; LPM3_EXIT; // Exit LPM3 on return}
// ADC12 Interrupt Service Routine#pragma vector=ADC_VECTOR__interrupt void ADC12ISR (void){ static unsigned int index = 0;
results[index++] = ADC12MEM0; // Move results
if (index == 512) { ADC12CTL0 &= ~ENC; // Stop conversion index = 0; P1OUT |= 0x01; _BIS_SR(LPM3_bits); // Enter LPM3 }}
此帖出自
小平头技术问答
ADC12ENC这一位相当于一个开关,打开此位后就允许ADC工作
ADC12SC是ADC开始采样转换的一个命令,置位后就为进行一次采样。如果选择的单次模式,采样一次后若还需要再次采样则还需要手动置位触发这个命令。
当然ADC12除了使用ADC12SC进行触发之外,还可以选择使用TimerA或TimerB进行触发。
这个时候它的触发源就是TimerA,当设定的时间一到,则ADC12自动启动转换
这个过程就跟ADC12SC无关了~
一周热门 更多>