[P]谁能帮我看看有什么问题啊,用示波器观察P3.4没有输出,有问题就请帮我指出来吧,谢谢了[/P][P]串口发送应该没问题,自己感觉是定时器设置的问题,还有就是需不需要加横线的那一段?[/P][P]#include "msp430x24x.h"
#define uchar unsigned char
void adc12_init(void);
void timer_init(void);
void UART_init(void);[/P][P]
void main(void)
{ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer //========================================================= unsigned int i; BCSCTL1 &= ~XT2OFF; // XT2on do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } while (IFG1 & OFIFG); // OSCFault flag still set? BCSCTL2 |= SELM_2 + SELS; // MCLK= SMCLK= XT2 (safe) //========================================================= adc12_init(); // Initialize ADC12 UART_init(); ADC12CTL0 |= ENC; // Start conversion _BIS_SR(LPM0_bits); // Enter LPM0
}[/P][P]void adc12_init(void)
{ P1DIR = 0xff; // set port to outputs P1OUT = 0; // reset port outputs P6SEL |= 0x01; // select A0 input ADC12CTL0 = ADC12ON+SHT0_1+REF2_5V+REFON; // Setup ADC12 ADC12CTL1 = SHP+CONSEQ_2+SHS_1; // Timer triggers sampling ADC12MCTL0 = INCH_0 + SREF_1; ADC12IE = 0x0001; // Enable ADC12IFG.0 TACCR0 = 1500; // Delay to allow Ref to settle TACCTL0 |= CCIE; // Compare-mode interrupt. TACTL = TASSEL_2 | MC_1; // TACLK = ACLK, Up mode. _BIS_SR(LPM3_bits + GIE); // Wait for delay, Enable interrupts TACCTL0 &= ~CCIE; // Disable timer P2SEL |= BIT3; // Set for Timer A1 P2DIR |= 0x08; TACCR0 = 1000; // Init TACCR0 w/ sample prd=CCR0+1 TACCR1 = 500; // Trig for ADC12 sample & convert TACCTL1 = OUTMOD_3; // Set/reset TACTL = TACLR | MC_1 | TASSEL_2; // ACLK, clear TAR, up mode
}[/P][P]void UART_init()
{ P3SEL |= 0x10; // Use P3.4 for USCI_A0 UCA0CTL1 |= UCSSEL_2; // UCLK = SMCLK UCA0BR0 |= 0xA1; // 8Mhz/19200 ~ 417 UCA0BR1 = 0x01; UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**[/P][P]}[/P][P]void UART_sendbyte(uchar data)
{ UCA0TXBUF = data; while (!(IFG2 & UCA0TXIFG )); // USCI_A0 TX buffer ready?
}[/P][P]// Timer_A0 Interrupt Service Routine
#pragma vector=TIMERA0_VECTOR
__interrupt void ta0_isr(void)
{ TACTL = 0; LPM3_EXIT; // Exit LPM3 on return
}[/P][P]// ADC12 Interrupt Service Routine #pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{ unsigned int advalue; advalue = ADC12MEM0; // Move results UART_sendbyte(advalue>>4);
}[/P] |