MSP430F19自带的ADC12做数字电压表,用变阻器给p6^0通道提供0~5V电压,买的单片机模块,在P6端口每个管脚都带一个贴片LED二极管,以后还想用LED,所以不敢贸然卸掉LED,不知道是程序的问题还是led影响,在网上还找了其他的两个程序,也是数值不改变,一个一直显示1.19V,另一个一直显示0.09V,自己弄了好几天了,求大神指点一下,谢谢
#include "msp430f149.h"
#include "1602.c"
#define Number_of_Results 200
#define uchar unsigned char
#define uint unsigned int
uchar shuzi[] = {"0123456789."};
static uint results[Number_of_Results];
void uart_orag()
{
ME1|=UTXE0+URXE0;
UCTL0|=CHAR;
UTCTL0|=SSEL0;
UBR00=0X03;
UBR10=0X00;
UMCTL0=0X4a;
P3SEL|=0X30;
P3DIR|=0X10;
UCTL0&=~SWRST;
IE1|=URXIE0;
}
void Trans_val(uint Hex_Val)
{
int i,m,n,j=0;
uchar p[5];
p[0]=Hex_Val/1000;
p[1]=10;
m=Hex_Val%1000;
p[2]=m/100;
n=Hex_Val%100;
p[3]=n/10;
j=Hex_Val%10;
p[4]=j;
for(i = 0;i < 5;i++)
LCD_write_char((6 + i),1,shuzi[p[i]]);
delay_ms(10);
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDT_Init(); //看门狗设置
Clock_Init(); //系统时钟设置
Port_init(); //系统初始化,设置IO口属性
delay_ms(10); //延时100ms
LCD_init(); //液晶参数初始化设置
LCD_clear();
LCD_Desk();
uart_orag();
P6SEL|=0X01;
ADC12IE=0X01;
ADC12CTL0=ADC12ON+MSC;
ADC12CTL1=SHP+CONSEQ_2;
ADC12CTL0|=SREF_1;
ADC12MCTL0|=SREF_1;
ADC12CTL0|=ENC;
_EINT();
ADC12CTL0|=ADC12SC;
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(void)
{
static uint index=0;
results[index++]=ADC12MEM0;
if(index==Number_of_Results)
{
uchar i;
unsigned long sum=0;
index=0;
for(i=0;i<Number_of_Results;i++)
{
sum+=results[i];
}
sum=sum/200;
sum=sum*3000/4095;
Trans_val(sum);
delay_ms(10);
}
} |