|
恩恩,我现在遇到瓶颈就是程序运行没问题,与PC通信也可以实现,但是加入A/D部分,上位机就收不到数据啦。附带程序,求帮助,谢谢。#include"msp430g2553.h"
void ADC10_Init(void);
void USCI(void);
void main(void)
{
int ADC10_Result;
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
ADC10_Init();
for( i=0;i<5;i++)
{
ADC10CTL0 |=ENC+ADC10SC; //开始转换
while((ADC10CTL0 &ADC10IFG)==0); //等待ADC10IFG标志变高(转换完成)
ADC10_Result+=ADC10MEM; //读取采样结果
}
ADC10_Result= ADC10_Result/5;
USCI();
while(1)
{
if(UCA0RXBUF=='a')
UCA0TXBUF =ADC10_Result; //发送接收到的数据
//UCA0TXBUF ='1';
}
}
void ADC10_Init(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
ADC10CTL1=CONSEQ_2;//单通道多次转换,这句应当写在最前面
ADC10CTL0 = REFON+SREF_1+REF2_5V; //打开2.5V 正参考,地为负参考
ADC10CTL0|= ADC10ON+ADC10SHT_3+MSC;//打开ADC10 内核,设定采样保持时间为64个ADC10CLK,使能ADC10 中断
ADC10CTL1 = INCH_4+SHS_0+ADC10SSEL_1; // input A4,采样保持
ADC10AE0 |= 0x10; // P1.4 DC option select。A4 模拟信号输入使能
return;
}
void USCI(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
UCA0CTL1 |= UCSWRST; // USCI_A0 进入软件复位状态
UCA0CTL1 |= UCSSEL_2; //时钟源选择 SMCLK
BCSCTL1 = CALBC1_1MHZ; //设置 DCO 频率为 1MHz
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1DIR |= BIT0;
UCA0BR0 = 0x68; //时钟源 1MHz 时波特率为9600
UCA0BR1 = 0x00; //时钟源 1MHz 时波特率为9600
UCA0MCTL = UCBRS0; //小数分频器
UCA0CTL1 &= ~UCSWRST; //初始化 USCI_A0 状态机
IE2 |= UCA0RXIE; //使能 USCI_A0 接收中断
_EINT(); //开总中断
}
|
|