|
这里要实现一个功能,P1.0和P1.5作为10位AD输入,把采集的数据通过P1.1和P1.2串口发送出去,串口数据前面再加个帧头0xff,发送格式如图所示,代码如下(连续采样,独立采样都试过了,这个代码是最笨的一个方法,也不行),但怎么都不对,哪们大侠能够指教一下,谢谢
#include <msp430g2553.h>
int main(void)
{
unsigned int ADCVal; // holds ADC result
unsigned int i,j;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2;
UCA0CTL0 &= ~UCMSB;
UCA0CTL1 |= UCSSEL_2; // CLK = ACLK
UCA0BR0 = 52; // 32kHz/9600 = 3.41
UCA0BR1 = 0x00;
// UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 3
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
// IE2 |= UCA0RXIE + UCA0TXIE; // Enable USCI_A0 TX/RX interrupt
while(1)
{
ADC10CTL0 = ADC10SHT_2 + ADC10ON; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_5; // input A5
ADC10AE0 = 0x20; // PA.1 ADC option select
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
while (!(ADC10IFG & ADC10CTL0)); // conversion complete?
ADC10CTL0 &= (~ADC10IFG);
ADCVal = ADC10MEM;
while((IFG2&UCA0TXIFG) == 0);
IFG2 |= UCA0TXIFG;
UCA0TXBUF = 0xff;
while((IFG2&UCA0TXIFG) == 0);
IFG2 |= UCA0TXIFG;
UCA0TXBUF = ADCVal;
while((IFG2&UCA0TXIFG) == 0);
IFG2 |= UCA0TXIFG;
UCA0TXBUF = ((ADCVal>>8)&0x3);
ADC10CTL0 &= (~ADC10ON);
for(i=0;i<30;i++)
for(j=0;j<500;j++);
ADC10CTL0 = ADC10SHT_2 + ADC10ON; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_0; // input A0
ADC10AE0 = 0x1; // PA.1 ADC option select
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
while (!(ADC10IFG & ADC10CTL0)); // conversion complete?
ADC10CTL0 &= (~ADC10IFG);
ADCVal = ADC10MEM;
while((IFG2&UCA0TXIFG) == 0);
IFG2 |= UCA0TXIFG;
UCA0TXBUF = ADCVal;
while((IFG2&UCA0TXIFG) == 0);
IFG2 |= UCA0TXIFG;
UCA0TXBUF = ((ADCVal>>8)&0x3);
ADC10CTL0 &= (~ADC10ON);
for(i=0;i<30;i++)
for(j=0;j<500;j++);
}
}
// USCI A0/B0 Transmit ISR
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
}
// USCI A0/B0 Receive ISR
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|