#include <msp430.h>
#include <stdint.h>
#include <stdbool.h>
uint16_t dat;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0xff; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
ADC12MCTL1 |=0x01;
P6SEL |= 0xff; // P6.0 ADC option select
P1DIR |= 0x01; // P1.0 output
while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}
#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: dat=0; // Vector 6: ADC12IFG0
dat=ADC12MEM0;
__bic_SR_register_on_exit(LPM0_bits);
case 8: dat=0;
dat=ADC12MEM0;
__bic_SR_register_on_exit(LPM0_bits); // 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;
}
}
我的P6^0端口烧掉了,所以我想把AD通道从A0通道换成A1通道,也就是换成端口P6^1输入,但是我把寄存器改了后还是不能读取从通道A1输入的值,中断函数里的switch中的ADC12IV寄存器里的数一直都是6,我不是很明白,希望熟悉这个的帮我解惑一下,小弟不胜感激
此帖出自
小平头技术问答
一周热门 更多>