Created
April 8, 2022 11:27
-
-
Save krisfans/1a6aaff45f949a695f23ad15de1fcf20 to your computer and use it in GitHub Desktop.
20222-4-8-MSP430F5529单片机ADC测试代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <msp430.h> | |
unsigned int voltage[4]; | |
int main(void) { | |
WDTCTL = WDTPW + WDTHOLD; // Stop WDT | |
P6SEL = BIT1; // P6.1 ADC option select | |
// P1DIR |= BIT0; // P1.0 output | |
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on | |
ADC12CTL1 = ADC12SHP; // Use sampling timer | |
// ADC12IE = ADC12IE1; // Enable interrupt p6.1 | |
ADC12MCTL0 = ADC12INCH_1; // A1 as adc input channel p6.0 | |
// ADC12MCTL1 = ADC12INCH_1; //A1 as adc input channel p6.1 | |
ADC12CTL0 |= ADC12ENC; | |
int i; | |
volatile unsigned long tmp; | |
while (1) { | |
tmp = 0; | |
for (i = 0; i < 4; i++) { | |
ADC12CTL0 |= ADC12SC; // Start sampling/conversion | |
voltage[i] = ADC12MEM0; | |
tmp += voltage[i]; | |
} | |
tmp = tmp >> 2; | |
// while(!(ADC12IFG & BIT1 )); | |
// __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force | |
// exit | |
__no_operation(); // For debugger | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment