msp430f5529adc
时间: 2023-08-04 09:03:50 浏览: 171
按键简易计算器_msp430f5529_
5星 · 资源好评率100%
msp430f5529adc采样程序可以参考以下代码:
#include <msp430.h>
#define ADC_CHANNELS 8
volatile unsigned int adc_values[ADC_CHANNELS];
void init_adc(void)
{
ADC12CTL = ADC12ON + ADC12MSC + ADC12SHT_8 + ADC12REFON; // ADC12ON, ADC12MSC, ADC12SHT_8, ADC12REFON
ADC12CTL1 = ADC12SHP + ADC12CONSEQ_3; // ADC12SHP, ADC12CONSEQ_3
ADC12CTL2 = ADC12RES_2; // ADC12RES_2
ADC12MCTL = ADC12INCH_; // ADC12INCH_
ADC12MCTL1 = ADC12INCH_1; // ADC12INCH_1
ADC12MCTL2 = ADC12INCH_2; // ADC12INCH_2
ADC12MCTL3 = ADC12INCH_3; // ADC12INCH_3
ADC12MCTL4 = ADC12INCH_4; // ADC12INCH_4
ADC12MCTL5 = ADC12INCH_5; // ADC12INCH_5
ADC12MCTL6 = ADC12INCH_6; // ADC12INCH_6
ADC12MCTL7 = ADC12INCH_7 + ADC12EOS; // ADC12INCH_7, ADC12EOS
ADC12IE = x80; // Enable ADC12IFG.7
ADC12CTL |= ADC12ENC; // Enable conversions
}
#pragma vector=ADC12_VECTOR
__interrupt void adc_isr(void)
{
static unsigned int i = ;
adc_values[i++] = ADC12MEM;
adc_values[i++] = ADC12MEM1;
adc_values[i++] = ADC12MEM2;
adc_values[i++] = ADC12MEM3;
adc_values[i++] = ADC12MEM4;
adc_values[i++] = ADC12MEM5;
adc_values[i++] = ADC12MEM6;
adc_values[i++] = ADC12MEM7;
if (i == ADC_CHANNELS) {
i = ;
}
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P6SEL |= xFF; // Enable A/D channel inputs
init_adc();
__enable_interrupt();
while (1) {
// Do something with adc_values
}
return ;
}
阅读全文