请问一下 我用的是MSP430F2012,然后我需要对1.8V到3.3V左右的电压分成4段采样,每一段电压用一个IO口输出高电平表示,请问有没有简单的例程序啊
gaoyang9992006:
你自己不是心理已经有数了吗?分成4段测,那你是用一路ADC检测,输出结果分为4段?用4个IO表示这四段,比如点亮不同的LED,是这样吧?你测量到ADC数据后,判断是哪个段的不就可以了?
user5095863:
回复 gaoyang9992006:
对 我是用一路ADC测 然后分成4段 然后我现在在看TI的示例(msp430x20x2_adc10_02)
#include <msp430.h>
int main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop WDT ADC10CTL1 = INCH_3 + CONSEQ_1; // A3/A2/A1, single sequence ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; ADC10DTC1 = 0x03; // 3 conversions ADC10AE0 |= 0x0E; // P1.3,2,1 ADC10 option select P1DIR |= 0x01; // Set P1.0 output
for (;;) { ADC10CTL0 &= ~ENC; while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ADC10SA = 0x200; // Data buffer start P1OUT |= 0x01; // P1.0 = 1 ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit P1OUT &= ~0x01; // P1.0 = 0 }}
// ADC10 interrupt service routine#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)#pragma vector=ADC10_VECTOR__interrupt void ADC10_ISR(void)#elif defined(__GNUC__)void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)#else#error Compiler not supported!#endif{ __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)}
这部分里面 我只要把FOR里面的那个改下就可以了吗 改成
if (ADC10MEM <2.2V, ADC10MEM >1.8)V P1OUT |= 0x01; else if (ADC10MEM <2.6V, ADC10MEM >2.2V) P1OUT |= 0x02;
else if (ADC10MEM <3.0V, ADC10MEM >2.6V) P1OUT |= 0x02;
else if (ADC10MEM <3.3V, ADC10MEM >2.6V) P1OUT |= 0x02;
这样??