#include "msp430x44x.h"
#include "Globle.h"
#include "TI_CC_CC1100_MODULE.h"
#define VIN1 6
#define AVref 2.5
#define MID_POWER 1.42
#define HIGH_POWER 1.46
#define Idz 75 //电磁阀堵转电流
#define Idzl 48
float Vdcf;
unsigned int ADCresult; //A0通道转换结果
unsigned int ADCresult1; //A1通道转换结果
unsigned int ADCflag=0; //ADC进中断标志
unsigned int ADC_CHANNEL=0; //ADC通道选择
float Vbattery; //电池剩余电量
float Vdcf; //电磁阀驱动相关电压
unsigned int KEY_COUNT=0; //按键次数
unsigned char KEYflag; //按键进中断标志
unsigned char battery_monitor(void);
void open_dcf(void);
void close_dcf(void);
void stop_dcf(void);
unsigned int dcf_moniter(void);
void adc_transfer( unsigned int bit,unsigned int INCH,unsigned int CSTARTADDx );
void key_moniter(void);
void key_inter_init(void);
unsigned int checkkey(void);
void adc_transfer( unsigned int bit,unsigned int INCH,unsigned int CSTARTADDx )
{
unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // 停止看门狗定时器
P6SEL |= bit; // 输入通道Ax
ADC12CTL0 = ADC12ON+REFON+REF2_5V+SHT0_4; // 设置 ADC12,采样时间
ADC12CTL1 = SHP+CONSEQ_0+CSTARTADDx; // 用采样定时器,转换模式
//ADC12MCTL0 = INCH+SREF_0; // 选择参考电压AVcc
if(bit == 0x01)
{ADC12MCTL0 = INCH_0+SREF_1;} // 选择参考电压AVref
else if(bit == 0x02)
{ ADC12MCTL1 = INCH_1+SREF_1;}
ADC12IE = bit; // 使能ADC12IFG.x
ADC_CHANNEL = bit;
for (i=0; i<3600; i++) //延时等待参考稳定
{}
ADC12CTL0 |= ENC; //使能转换
_EINT(); // 全局中断使能
ADC12CTL0 |= ADC12SC; // 开始转换
//_BIS_SR(LPM0_bits); // 进入LPM0
for( i=0; i<1000;i++ )
{
if( ADCflag == 1)
{
ADCflag = 0;
//break;
//_BIS_SR(LPM0_bits);
}
}
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
ADCflag = 1;
if( ADC_CHANNEL == 1 )
{
ADCresult = ADC12MEM0;
Vbattery = ((float)ADCresult*AVref)/4095;
} // 读取结果
else if(ADC_CHANNEL == 0x02)
{
ADCresult1 = ADC12MEM1;
Vdcf = (ADCresult1*AVref)/4095;
}
//_BIC_SR_IRQ(LPM0_bits); // 清 LPM0 (退出低功耗模式0~~)
ADC12CTL0 &= ~ENC;
} |