AD采集正弦波输出同频同相的方波。可是有错误,谁能把我看看。在下万分感谢。
#include <msp430g2452.h>
double pingjun=0;
long caiyangzhi;
double caiyang ();
void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR &=~BIT0;
P1SEL =BIT0;
P2DIR=BIT2;
P2OUT=0;
__enable_interrupt();
caiyang();
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
if(caiyangzhi<pingjun+0.05 & caiyangzhi<pingjun+0.05)
P2OUT ^= P2OUT;
__no_operation();
}
}
double caiyang ()
{
unsigned char i;
ADC10CTL1=INCH_0+ADC10DIV_3;
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;
__delay_cycles(1000);
ADC10CTL0 |= ENC + ADC10SC;
__bis_SR_register(CPUOFF + GIE);
caiyangzhi= ADC10MEM;
for (i=0;i<1024;i++)
{
pingjun += ADC10MEM;
}
pingjun=pingjun/10 ;
return (pingjun);
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode
}
此帖出自
小平头技术问答
一周热门 更多>