永发信息网

msp430测量电压程序但是实际测的电压不对!不知道为什么

答案:2  悬赏:50  手机版
解决时间 2021-03-14 02:05
  • 提问者网友:浮克旳回音
  • 2021-03-13 22:57
#include
#include"12864.h"
#include"12864.c"
#define uchar unsigned char
#define uint unsigned int
uint result[64];
uint bai,shi,ge;
unsigned long dianya,average=0;
uchar a=0,i;
uchar shuzi[] = {"0123456789."};
uint ptr[5];
void turn_value();
void main()
{
WDTCTL = WDTPW + WDTHOLD;
LCD_Init();
LCD_WriteString(0,0,"msp430f149-ADC12");
LCD_WriteString(1,0,"XXX");
LCD_WriteString(2,0,"电压值: ");
P6SEL |= BIT0; //通道A0
ADC12CTL0 = ADC12ON + MSC + SHT0_7;
ADC12CTL1 = SHP + CONSEQ_2;
ADC12IE = 0x01;
ADC12CTL0 |= ENC;
ADC12CTL0 |= ADC12SC;
_EINT();
while(1)
{
LPM0;
}
}
#pragma vector = ADC_VECTOR
__interrupt void ADC12ISR(void)
{
LPM0_EXIT;
result[a++]= ADC12MEM0;
if(a == 63)
{
for(i=0;i<63;i++)
{
average += result[i];
}
average >>= 6; (除以64求平均值)
a = 0;
turn_value();
}
}
void turn_value()
{
dianya = average;
dianya = (dianya << 6) + (dianya<<5) +(dianya<<2); //乘以100
dianya = (dianya << 5) + average; //dianya = a * 33
dianya = (dianya << 3) + (dianya << 1); //dianya = dianya * 10(再次扩大了100倍,三位数)
dianya = dianya >> 12; //dianya = dianya / 4095 (2的十二次方)
ptr[0]=dianya/10000;
ptr[1]=dianya/1000%10;
ptr[2]=dianya/100%10;
ptr[3]=dianya%100/10;
ptr[4]=dianya%100%10;
//在液晶上显示变换后的结果
write_com(0x8C);
write_dat(ptr[0]+0x30);
write_dat(0x2e);
write_dat(ptr[1]+0x30);
write_dat(ptr[2]+0x30);
write_dat(ptr[3]+0x30);
write_dat(ptr[4]+0x30);
write_word("V");
}
最佳答案
  • 五星知识达人网友:由着我着迷
  • 2021-03-13 23:55
我觉得你得设置一下电压基准。例如这样的句子
ADC12CTL0=ADC12ON+ADC12REFON;
ADC12CTL0|=ADC12REF2_5V; //参考电压为2.5V
// ADC12CTL0&=~ADC12REF2_5V; //参考电压为1.5V
全部回答
  • 1楼网友:杯酒困英雄
  • 2021-03-14 00:50
首先确定你的io口配置为输入了。 其次你可以看器件手册,io口高电平应该大于vcc-0.25(端口最大电流-1ma时)或vcc-0.6(端口最大电流-6ma时)。比如你3v供电,io口电平高于2.75v才会认为是高电平。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯