#include <msp430x14x.h>
#include "BoardConfig.h"
#define uint unsigned int
#define uchar unsigned char
uchar static adc_flag=0;
uchar static count=0;
void int_clk()
{
uchar i;
BCSCTL1&=~XT2OFF;
BCSCTL2|SELM1+SELS;
do
{
IFG1&=~OFIFG;
for(i=0;i<100;i++)
_NOP;
}
while((IFG1&OFIFG)!=0);
IFG1&~OFIFG;
}
int_adc()
{
P6SEL|=0x01;
ADC12CTL0=ADC12ON+MSC+SHT0_2+REF2_5V+REFON;
ADC12CTL1=SHP+CONSEQ_2;
ADC12MCTL0=0x10;
ADC12IE=0x01;
ADC12CTL0|=ENC;
}
#pragma vector = TIMERA0_VECTOR
__interrupt void ADC12ISR (void)
{
uint results[10];
adc_flag=1;
results[count]=ADC12MEM0;
count++;
}
int main(void)
{
WDTCTL=WDTPW+WDTHOLD;
BoardConfig(0xb8); //关闭数码管、流水灯和电平转换
int_clk();
int_adc();
_EINT();
ADC12CTLO|=ADC12SC;
while(1);
}
只是单通道多次转换模式的程序,请教:转设来存放转换结果的数组只有11位,每次转换完地结果存放在数组中,当数组用完之后呢?转换会自动停止吗?会的话是在哪里设置的?还有为什么不用清理中断标志?
此帖出自
小平头技术问答
#pragma vector = TIMERA0_VECTOR
__interrupt void ADC12ISR (void)
{
results[count]=ADC12MEM0; //当访问ADC12MEM0, ADC12IFG.0就自动清零了,不用软件清零
count++;
if(count==12)
{
count=0;
下面是数组求和再求平均值的语句,就不写了
}
}
一周热门 更多>