赶紧帮帮我吧,好几天啦。。。。以下是我写的launchpad程序,请教给位大神:我想先用P1口的8位ADC10采集完数据后保存起来,然后再用P1.1和P1.2的UART功能把采集到的数据传到PC中,请问我哪儿错了,我一定改!!!!!
#include
#define CPU_F ((double)1000000)
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))//IAR自带的延时
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))//IAR自带的延时
#define uchar unsigned char
#define uint unsigned int
int result,AD_result[8];
char result_M[4];
uchar i,u;
double v;
void uart_init()
{
ADC10CTL0 = 0;//不允许中断
ADC10CTL1 = 0;
ADC10AE0 = 0;
UCA0CTL1|=UCSSEL_2;
UCA0BR0=104; //波特率为9600
UCA0BR1=0;
UCA0MCTL=UCBRS0;
P1SEL=0;
P1DIR = BIT2; //P1.2 UART_TX
P1SEL|=BIT1+BIT2; //将P1.1 P1.2设为第二功能
P1SEL2 = BIT1 + BIT2;
UCA0CTL1&=~UCSWRST;
IE2|=UCA0RXIE;
}
void AD_Init(void)
{
P1SEL = 0xFF;//将IO选择为AD输入
P1DIR = 0;
ADC10CTL0 |= SREF_1+REFON+ADC10IE;//将AD10基准设置为1.5V 开启AD允许中断
ADC10CTL0 |= ADC10SHT_3+MSC;//打开AD转换,过采样率设置为64个采样周期
ADC10CTL1 |= ADC10SSEL_3+SHS_0;//选择250K的采样时钟,用ADC10SC触发采集
ADC10CTL1 |= CONSEQ_1+INCH_7;//连续采样模式,从通道0~7
ADC10CTL0 |= ADC10ON;
ADC10AE0 |= 0xFB;
ADC10CTL0 |= ADC10SC+ENC;
}
void send(uchar c)
{
UCA0TXBUF=c;
while(!(IFG2&UCA0TXIFG));
IFG2&=~UCA0TXIFG;
}
void main()
{
WDTCTL=WDTPW+WDTHOLD;
DCOCTL=CALDCO_1MHZ; //将DCO设为1mhz
BCSCTL1=CALBC1_1MHZ;
for(u=0;u<8;u++)
{
AD_result=0;
}
uart_init();
send(\'B\');
send(\'e\');
send(\'g\');
send(\'i\');
send(\'n\');
send(\':\');
while(1)
{
// send(\'A\');
AD_Init();
_EINT();
delay_ms(50);
ADC10CTL0 |= ENC+ADC10SC;
delay_ms(50);
uart_init();
send(0x31);
send(AD_result[0]);
send(AD_result[1]);
send(AD_result[6]);
delay_ms(500);
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
AD_result=ADC10MEM;
u--;
if(u>8)
{
u=7;
}
}