|
/*请问我这可程序的ADC部分的寄存器配置错在哪里啊,漏掉了为那些啊*/
# include "msp430g2553.h"
void init_UART();
void delay_50ms(unsigned int t);
unsigned char v = 0;
/*
* main.c
*/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //stop the watchdog
ADC10CTL0 = ADC10ON + ADC10IE;
ADC10CTL0 |= ADC10SHT_2;
init_UART();
P1SEL |= BIT0;
P1SEL2 |= BIT0;
__bis_SR_register(GIE); // interrupts enabled
for(;;)
{
ADC10CTL0 |= ADC10SC;
while(!(UCA0TXIFG & IFG2));
UCA0TXBUF = V;
delay_50ms(40);
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
v = ADC10MEM;
}
void init_UART() // DCO 1MHz SMCLK 9600
{
/* system clock */
DCOCTL = CALDCO_1MHZ; // Set DCO
BCSCTL1 = CALBC1_1MHZ;
/* PX and TX IO */
P1SEL = BIT1 + BIT2; //P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2; //P1.1 = RXD, P1.2=TXD
/* BPS */
UCA0CTL1 = UCSSEL_2; //select clock source is SMCLK
UCA0BR0 = 104; // BPS is 9600bps
UCA0BR1 = 0;
//UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // enable RX inerrupt
//_EINT(); //interrupt enable(总)
}
void delay_50ms(unsigned int t)
{
unsigned int j;
for(;t>0;t--)
for(j=20000;j>0;j--)_nop();
}
|
|