完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
我用ad12设置多通道单次转换,但是6个通道得到的结果是有问题的。 通道1、2在空接的状况下(就算接了也是)得到的电压转化值为2.500和0.004 其余通道一直为1.8xx 我的参考电压为2.5v,但是我不知道为什么他们空接转换的值如此不能理解。下面是我的程序。 /******************************************************************** //DM430-L型开发板1602液晶显示ADC转换结果程序,显示输入到ADC的电压转换后的数字量和模拟电压大小 //MSP430单片机内部12位ADC,采用内部2.5V基准,单通道单次转换,中断模式,有精度误差 //通过杜邦线将需要转换的电压加入到ADC0,也就是P6,可以更改输入电压,最大显示量4095和2.5V //调试环境:EW430 V5.30 //作者:ls //时间:2018.09.21 ********************************************************************/ #include #include "Config.h" //开发板配置头文件,主要配置IO端口信息 #include "1602.c" #define unsing char=uchar; static uchar Flag=0; //标志变量 uint number0,number1,number2,number3,number4,number5; //ADC值暂存变量 uint A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12; uint v[6];//定义的变量,显示数据处理 //*********************************************************************** // 显示采集到的ADC数值 //*********************************************************************** void LCD_DisplayADC1() { LCD_write_char(0x0b,0,0x30+A1); LCD_write_char(0x0c,0,0x30+'.'); LCD_write_char(0x0d,0,0x30+A2); LCD_write_char(0x0e,0,0X30+A3); LCD_write_char(0x0f,0,0X30+A4); } void LCD_DisplayADC2() { LCD_write_char(0x0b,1,0x30+A9); LCD_write_char(0x0c,1,'.'); LCD_write_char(0x0d,1,0x30+A10); LCD_write_char(0x0e,1,0X30+A11); LCD_write_char(0x0f,1,0X30+A12); } //************************************************************************* // 数字量显示处理函数 //************************************************************************* void data1(uint temp_d) { uint temp_1,temp_2; A1=temp_d/1000; //分出千,百,十,和个位 temp_1=temp_d%1000; A2=temp_1/100; temp_2=temp_1%100; A3=temp_2/10; A4=temp_2%10; } void data2(uint temp_d) { uint temp_1,temp_2; A9=temp_d/1000; //分出千,百,十,和个位 temp_1=temp_d%1000; A10=temp_1/100; temp_2=temp_1%100; A11=temp_2/10; A12=temp_2%10; } //************************************************************************* // 电压数据显示处理函数 //************************************************************************* void Voltage_do(uint temp_d) { uint temp_1,temp_2; ulong temp_3; temp_3=(ulong)(temp_d)*2500; //转换公式,ADC数字量转换为电压大小,注意数据类型 temp_d=temp_3/4095; //12位精度,除以4095 A5=temp_d/1000; //分出百,十,和个位 temp_1=temp_d%1000; A6=temp_1/100; temp_2=temp_1%100; A7=temp_2/10; A8=temp_2%10; } //串口// void uartInit(){ P3DIR|=BIT4+BIT5; P3SEL|=BIT4+BIT5; ME1 |= UTXE0 + URXE0; // 使能USART0收发 UCTL0 |= CHAR; // 8-bit 数据,一位停止位 UTCTL0 |= SSEL0; // 选择时钟,UCLK = ACLK,32768 UBR00 = 0x03; // 32k/9600 UBR10 = 0x00; // UMCTL0 = 0x4a; // Modulation UCTL0 &= ~SWRST; // 初始化UART0状态机,一般要设置好串口之后才复位 } //发送// void stringsend(int g) { unsigned char s[] = "0000"; unsigned char *p; int one=0,two = 0,three= 0,four= 0; one = g/1000; two =g%1000/100; three = g%100/10; four = g%10; s[0]=one+'0'; s[1]=two+'0'; s[2]=three+'0'; s[3]=four+'0'; p = s; while(*p!=' |
