我用MSP430F149自带AD接口写的一个测量电压的程序,为什么只显示汉字而电压值没有显示,求高手指点
voidTrans_val(unsignedlongsum){uchari;unsignedcharp[4]={0};p[0]=sum/1000+0x30;p[1]=su...
void Trans_val(unsigned long sum)
{
uchar i;
unsigned char p[4]={0};
p[0]=sum/1000+0x30;
p[1]=sum%1000/100+0x30;
p[2]=sum%100/10+0x30;
p[3]=sum%10+0x30;
for(i=0;i<4;i++)
display(2,0,p[i]);
}
void main()
{
uint i;
uchar table1[]={"电压测量"};
WDTCTL=WDTPW+WDTHOLD;
Ini_Lcd();
Clear_GDRAM();
Write_Cmd(0x80); //第一行显示汉字,可以显示
for(i = 0; i < 8; i++)
Write_Data(table1[i]);
P6SEL|=0x01;
ADC12CTL0 = ADC12ON+MSC+SHT0_2 ; //开ADC12内核,设SHT0=2 (N=4)
ADC12CTL1 = SHP+CONSEQ_2 ; //SAMPCON信号选为采样定时器输出 //应该加上CONSEQ_2 选择单通道多次转化
ADC12CTL0 |= REF2_5V+REFON ; //选用内部参考电压为2.5V
ADC12MCTL0 |= SREF_1; //R+=2.5V R-=VSS
ADC12IE |= 0x01;
ADC12CTL0 |= ENC ; //转换允许(上升沿)
ADC12CTL0 |= ADC12SC;
}
/*******************************************
函数名称:ADC12ISR
功 能:ADC中断服务函数,在这里用多次平均的
计算P6.0口的模拟电压数值
参 数:无
返回值 :无
********************************************/
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
unsigned int index = 0;
while((ADC12CTL1&ADC12BUSY)==0);
results[index++] = ADC12MEM0; // Move results
if(index == Number_of_Results)
{
unsigned char i;
unsigned long sum = 0;
index = 0;
for(i = 0; i < Number_of_Results; i++)
{
sum += results[i];
}
sum =sum/Number_of_Results; //除以50,得到平均值
sum=sum*2500/4095; //把结果扩大1000倍,方便显示
Trans_val(sum); //把结果各个位上的数字显示
}
} 展开
{
uchar i;
unsigned char p[4]={0};
p[0]=sum/1000+0x30;
p[1]=sum%1000/100+0x30;
p[2]=sum%100/10+0x30;
p[3]=sum%10+0x30;
for(i=0;i<4;i++)
display(2,0,p[i]);
}
void main()
{
uint i;
uchar table1[]={"电压测量"};
WDTCTL=WDTPW+WDTHOLD;
Ini_Lcd();
Clear_GDRAM();
Write_Cmd(0x80); //第一行显示汉字,可以显示
for(i = 0; i < 8; i++)
Write_Data(table1[i]);
P6SEL|=0x01;
ADC12CTL0 = ADC12ON+MSC+SHT0_2 ; //开ADC12内核,设SHT0=2 (N=4)
ADC12CTL1 = SHP+CONSEQ_2 ; //SAMPCON信号选为采样定时器输出 //应该加上CONSEQ_2 选择单通道多次转化
ADC12CTL0 |= REF2_5V+REFON ; //选用内部参考电压为2.5V
ADC12MCTL0 |= SREF_1; //R+=2.5V R-=VSS
ADC12IE |= 0x01;
ADC12CTL0 |= ENC ; //转换允许(上升沿)
ADC12CTL0 |= ADC12SC;
}
/*******************************************
函数名称:ADC12ISR
功 能:ADC中断服务函数,在这里用多次平均的
计算P6.0口的模拟电压数值
参 数:无
返回值 :无
********************************************/
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
unsigned int index = 0;
while((ADC12CTL1&ADC12BUSY)==0);
results[index++] = ADC12MEM0; // Move results
if(index == Number_of_Results)
{
unsigned char i;
unsigned long sum = 0;
index = 0;
for(i = 0; i < Number_of_Results; i++)
{
sum += results[i];
}
sum =sum/Number_of_Results; //除以50,得到平均值
sum=sum*2500/4095; //把结果扩大1000倍,方便显示
Trans_val(sum); //把结果各个位上的数字显示
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询