#include"msp430g2553.h" //P1.2输出
unsigned int m=0,qushu=0,k=0,max=0,min=255;
void delay(unsigned int i)
{
unsigned int j;
for(j=0;j
}
int main(void)
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_1; // input A1模拟信号输入选择通道A1即p1.1
ADC10AE0 |= 0x01; // PA.1 ADC option select使p1.1允许AD模拟输入信号
P1DIR |= 0x40;
TA1CCTL0 = CCIE; // CCR0 0.524ms中断
TA1CCR0 = 312;
TA1CTL = TASSEL_2 + MC_1; //
_EINT(); //允许中断
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
P1DIR|=0x04;//p1.2输出
P1SEL|=0x04;
TA0CCTL1=OUTMOD_3;
TA0CCR0=255;
TA0CCR1=0;
TA0CTL=TASSEL_2+MC_1;
while(1)
{
if(m==1)
{
k=qushu/4;
TA0CCR1=k;
m=0;
}
}
}
/********************************************
*
定时器Timer1_A
*******************************************/
#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer1_A (void)//16M时定时0.04MS
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start开始转换
qushu=ADC10MEM;//取出ad转换值
if(max
if(min>qushu)min=qushu;
m=1;
P1OUT ^= 0x40;
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}