main.c
#include <msp430.h> #include <ti/mcu/msp430/Grace.h> /* * ======== main ======== */ int main(void) { Grace_init(); // Activate Grace-generated configuration ADC10CTL0 |= ADC10SC; // comenzar conversion __bis_SR_register(LPM3 + GIE); }
InterruptVectors_init.c
/* * ======== Timer1_A3 Interrupt Service Routine ======== */ #pragma vector=TIMER1_A0_VECTOR __interrupt void TIMER1_A0_ISR_HOOK(void) { /* USER CODE START (section: TIMER1_A0_ISR_HOOK) */ P1OUT ^= BIT0; if (ADC10MEM < 512) { P2OUT |= BIT0; P2OUT &= ~BIT1; } else { P2OUT &= ~BIT0; P2OUT |= BIT1; } /* USER CODE END (section: TIMER1_A0_ISR_HOOK) */ }
ADC10_init.c
/* * ======== ADC10_graceInit ======== * Initialize MSP430 10-bit Analog to Digital Converter */ void ADC10_graceInit(void) { /* USER CODE START (section: ADC10_graceInit_prologue) */ /* User initialization code */ /* USER CODE END (section: ADC10_graceInit_prologue) */ /* disable ADC10 during initialization */ ADC10CTL0 &= ~ENC; /* * Control Register 0 * * ~ADC10SC -- No conversion * ~ENC -- Disable ADC * ~ADC10IFG -- Clear ADC interrupt flag * ~ADC10IE -- Disable ADC interrupt * ADC10ON -- Switch On ADC10 * REFON -- Enable ADC reference generator * ~REF2_5V -- Set reference voltage generator = 1.5V * MSC -- Enable multiple sample and conversion * ~REFBURST -- Reference buffer on continuously * ~REFOUT -- Reference output off * ~ADC10SR -- Reference buffer supports up to ~200 ksps * ADC10SHT_0 -- 4 x ADC10CLKs * SREF_1 -- VR+ = VREF+ and VR- = VSS * * Note: ~<BIT> indicates that <BIT> has value zero */ ADC10CTL0 = ADC10ON + REFON + MSC + ADC10SHT_0 + SREF_1; /* * Control Register 1 * * ~ADC10BUSY -- No operation is active * CONSEQ_2 -- Repeat single channel * ADC10SSEL_0 -- ADC10OSC * ADC10DIV_0 -- Divide by 1 * ~ISSH -- Input signal not inverted * ~ADC10DF -- ADC10 Data Format as binary * SHS_0 -- ADC10SC * INCH_1 -- ADC Channel 1 * * Note: ~<BIT> indicates that <BIT> has value zero */ ADC10CTL1 = CONSEQ_2 + ADC10SSEL_0 + ADC10DIV_0 + SHS_0 + INCH_1; /* Analog (Input) Enable Control Register 0 */ ADC10AE0 = 0x2; /* Software delay for REFON to settle */ __delay_cycles(30000); /* enable ADC10 */ ADC10CTL0 |= ENC; /* USER CODE START (section: ADC10_graceInit_epilogue) */ /* User code */ /* USER CODE END (section: ADC10_graceInit_epilogue) */ }
main.cfg
Esquema
No hay comentarios:
Publicar un comentario