#include "msp430x20x2.h"
unsigned char bz=0;
void ADC_Init(void)
{
ADC10CTL0 = SREF_0 + ADC10SHT_3 + REF2_5V + MSC + REFON + ADC10ON + ADC10IE + ENC + ADC10SC;
ADC10CTL1 = INCH_1 + SHS_0 + ADC10SSEL_0 + CONSEQ_2;
P1SEL|=0x02; //用A1
}
int main (void)
{
__enable_interrupt();
ADC_Init();
bz=1;
while(1)
{
while(bz==1)
{
ADC10CTL0 |= ADC10SC; //开启转换
bz=0;
ADC10CTL0 |= ADC10IE;
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR ()
{
while((ADC10CTL1&0x02)==1);
if (ADC10MEM > 0x170)
Turn_on;
else
Turn_off;
bz=1;
ADC10CTL0&=~ ADC10IE; //不写这句,就一直在中断里,也跳不出去,不能回主程序,为什么呢?
|