我觉得好像是端口设置有问题 #include <msp430x14x.h> #include "cry1602.h" #include "math.h" #define Num_of_Results 32 typedef unsigned char uchar; typedef unsigned int uint; uchar shuzi[]={"0123456789."}; uchar tishi[]={"The temp is:"}; static uint results[Num_of_Results]; //保存ADC转换结果的数组 void Trans_val(uint Hex_Val); /****************主函数******************/ void main(void) { WDTCTL=WDTPW+WDTHOLD; //关闭看门狗 LcdReset(); //复位1602 DispNChar(2,0,12,tishi); //显示提示信息 DisplChar(11,1,'C'); //显示电压单位 P6SEL|=BIT1;//p6.0做为模拟信号输入端口 ADC12MCTL1=INCH_1; ADC12CTL0=ADC12ON+SHT0_8+MSC; //打开ADC,设置采样时间 ADC12CTL1=SHP+CONSEQ_2;//使用采样定时 ADC12IE=0x01; //ADCIE=0x01; //使能ADC中断 ADC12CTL0|=ENC; //使能转换 ADC12CTL0|=ADC12SC; //开始转换 _EINT(); LPM0; } /****************中断服务函数********************* 用途;多次平均计算P60口的模拟电压数值************/ #pragma vector=ADC_VECTOR __interrupt void ADC12ISR(void) { static uint index=0; results[index++]=ADC12MEM0; //移动结果 if(index==Num_of_Results) { uchar i; unsigned long sum=0; index=0; for(i=0;i<Num_of_Results;i++) { sum+=results; } sum>>=5; //除以32 Trans_val(sum); } } /*********************转换数据函数**************** 功能;将16进制转换数据变换成三位10进制真实的模拟电压数据*****/ void Trans_val(uint Hex_val) { unsigned long caltmp; int d[5]; uchar i; float c,r,curr_volt1,t1; uint curr_volt; //uchar i,r,n,p; caltmp=Hex_val; caltmp=(caltmp<<5)+Hex_val; //caltmp=Hex_val*33 caltmp=(caltmp<<3)+(caltmp<<1); //caltmp=caltmp*10 curr_volt=caltmp>>12; //curr_volt= caltmp/2^n curr_volt1=curr_volt; r= (1700/(851-curr_volt1))-1.4; c= (1/((1/298.15)+(log(r)/3950)))-273.15; d[0]=(int)(c)/10;//得到c为4位有效数字 小数点前、后各两位 t1=c-(d[0]*10); d[1]=(int)(t1); d[2]=10; d[3]=(int)((t1*10)-(d[1]*10)); d[4]=(int)(t1*1000-d[1]*1000-d[3]*100)/10; for(i=0;i<5;i++) { DisplChar((6+i),1,shuzi[d]); } } |