volaTIle unsigned int ad_value[10];
Int main( void )
{
WDTCTL=WDTPW+WDTHOLD; //Close the watchdog
BCSCTL1 =CALBC1_1MHz; //Set the DCO to 1MHZ
DCOCTL =CALBC1_1MHZ;
//The clock source selects the AD internal clock and divides by 4, selects channel 10, the AD start signal source selects TA.OUT1, and the menu channel is continuously sampled.
ADC10CTL1=ADC10DIV_3+INCH_10+SHS_1+CONSEQ_2;
//Select 1.5V for forward reference, ground for negative reference, AD interrupt enable, open reference, start AD module (not start AD conversion)
ADC10CTL0=SREF_1+ADC10SHT_3+ADC10IE+REFON+ADC10ON;
TACCR0=30; //delay wait for reference stability
TACCTL0 |=CCIE; //CCR0 interrupt enable
TACTL=TACLR+MC_1+TASSEL_2; //TA increments, the clock source is smclk
_BIS_SR(LPM0_bits+GIE); //Enter low power consumption 0, enable total interrupt, wait for reference stability
TACCTL0 &=~CCIE; //CCR0 interrupt disabled
_BIC_SR(GIE); //Off total interruption
ADC10CTL0 |=ENC; //AD conversion enable
TACCTL1=OUTMOD_4; //CCR1 selects output mode 4, when TAR=0, output high level
TACTL = TASSEL_2+MC_2; //TA is changed to continuous count, smclk clock source
_BIS_SR(LPM0_bits+GIE); //Enter low power 0, enable total interrupt, wait for 10AD to complete
_NOP();
Return 0;
}
#pragma vector = TIMERA0_VECTOR //TA0 interrupt service, used for reference stabilization
__interrupt void ta0_isr(void)
{
TACTL=0; //Off TA
_BIC_SR_IRQ(LPM0_bits); //Exit low power
}
#pragma vector = ADC10_VECTOR //ADC10 Interrupt Service
__interrupt void adc_isr(void)
{
staTIc char i=0;
Ad_value[i]=ADC10MEM; //Save AD results
i++;
If(i==10) //Do 10 AD
_BIC_SR_IRQ(LPM0_bits+GIE); //Exit low power
}
Neoprene Velcro Cable Sleeve,Expandable Braided Cable Sleeving,Computer Cable Sleeves,Automotive Wire Sheathing
Shenzhen Huiyunhai Tech.Co., Ltd. , https://www.cablesleevefactory.com