#include <msp430g2231.h>
#include <intrinsics.h>
long volCalibrated,volMeasured[8],volAverage;
unsigned char volMeasuredPosition = 0;
unsigned char i,j;
void main(void)
{
//unsigned char i;
//float average_AD;
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL0 = SREF_1 + ADC10SHT_0 + ADC10ON + REFON;
ADC10CTL0 |= REF2_5V;
ADC10CTL1 = INCH_1+CONSEQ_0+ADC10DIV_0+ADC10SSEL_2;
ADC10AE0 |= BIT1;
P1DIR = 0x75;
__delay_cycles(1000);
ADC10CTL0 |= ENC + ADC10SC;
volCalibrated = ADC10MEM;
for(i = 0;i < 8;i++)
volMeasured
= volCalibrated;
volAverage = volCalibrated;
while(1)
{
ADC10CTL0 |= ENC + ADC10SC;
volMeasured[volMeasuredPosition++] = ADC10MEM;
if(volMeasuredPosition == 8)
volMeasuredPosition = 0;
volAverage = 0;
for(j = 0;j < 8;j++)
{
volAverage += volMeasured[j];
}
volAverage >>= 3;
if(volAverage<0x019A)
P1OUT = BIT0;
else if(0x019A<=volAverage<0x0267)
P1OUT = BIT2;
else if(0x0267<=volAverage<0x0334)
P1OUT = BIT4;
else if(0x0334<=volAverage<0x0400)
P1OUT = BIT5;
else
P1OUT = BIT6;
}
}
想实现 当P1.1引脚的电压U<1.0V时,LED1亮
当P1.1引脚的电压1.0V<=U<1.5V时,LED3亮
当P1.1引脚的电压1.5V<=U<2.0V时,LED4亮
当P1.1引脚的电压2.0V<=U<2.5V时,LED5亮
当P1.1引脚的电压U>2.5V时,LED2亮
下载到DEMO板上后实际的情况是
当P1.1引脚的电压U<1.0V时,LED1亮
当P1.1引脚的电压U>1.0V时,LED3亮
是为什么呢?
此帖出自小平头技术问答
不好意思,现在才看到。
还没仔细看,扫了一眼,说错了别见怪,没道理我再看看想想学学其它原因因素
转换需要一定时间吧?一般在中断中处理或者等待询问AD模块转换完成的标志位吧?
建议在论坛之类的帖源码,最好在一些设置语句后面或者前面添加配置注释,除非整天设计用msp430的,可能很多人是记不住那些配置符号的含义的
不过您改过的还是冗余呀
再说我之前提的是不是还是要注意?
[ 本帖最后由 wangfuchong 于 2012-5-30 22:46 编辑 ]
一周热门 更多>