小弟这边有一个程序,是用2553把AD数据通过UART把AD值给电脑,然后用labview做一个虚拟电压计,但是我现在的问题是,不管怎么改变外部电源,上位机收到的信号都是0XFF,我用CCS debug的时候,设置断点观察寄存器,得到的ADC10MEM和UCA0TXBUF的值都是正确的,但是传输到上位机就变了,请问个问大侠如何改,程序如下
#include <msp430g2553.h>
float adc_voltage;
unsigned int k;
void sys_clk_config(void)
{
//ACLK = ; MCLK = SMCLK = DCOCLK = 1.1MHZ
DCOCTL = 0;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
}
void uart_gpio_init(void)
{
P1SEL |= BIT1 + BIT2;
P1SEL2 |= BIT1 + BIT2;
P1DIR |= BIT2;
}
void led_gpio_init(void)
{
}
void ad_gpio_init(void)
{
}
void uart_config(void)
{
UCA0CTL1 |= UCSSEL_2;
UCA0BR0 = 8;
UCA0BR1 = 0;
UCA0MCTL = UCBRS2 + UCBRS0;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE;
}
void ad_config(void)
{
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10CTL1 = INCH_5 + CONSEQ_2 ;
ADC10AE0 |= 0x10;
ADC10CTL0 |= ENC + ADC10SC;
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
//sys_clk_config();
uart_gpio_init();
led_gpio_init();
ad_gpio_init();
uart_config();
ad_config();
__bis_SR_register(GIE);
while(1);
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
// while(!(IFG2 & UCA0TXIFG));
// UCA0TXBUF = UCA0RXBUF;
}
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_A0_ISR(void)
{
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = ((ADC10MEM*33)/1023);
k = 10000;
while(k--);
}
跪谢!
此帖出自
小平头技术问答
一周热门 更多>