N76E003电压检测比较 功耗太大,现在功耗20MA多谁帮我优化下,有偿优化!unsigned char xdata ADCdataH[10], ADCdataL[10];
unsigned int ADP03,ADP04,ADP07,ADP17;
unsigned int tempH,tempL,tempHLD,tempHLI;
/******************************************************************************
DS功能:
P17=2.5V电压
开机检测一次P07电压,不循环。当P07<P17时,P13为高电平,当P07>P17时,P13为低电平。
检测P03电压,并保存不变的固定电压值假设为a。
下面为循环到关机为止。
检测P04电压,
当P04>P03时,P06和P13输出高电平。
当P04<P03时,(P06和P13输出低电平,也可以不管,因为上面默认=0)
P0.6/P1.3/P0.0/P1.6输出高电平
P0.3/P0.4/P0.7/P17 ADC检测功能
******************************************************************************/
void main (void)
{
unsigned char i;
P06_Quasi_Mode;
P13_Quasi_Mode;
P14_Quasi_Mode;
P06=1;
P14=0;
P13=0;
//Timer1_Delay10ms(100);
Timer1_Delay10ms(100);//延时2s
/*----电源欠压采样----P07------*/
P06=0;
ADP17 =0x07FF;
for(i=0;i<10;i++)
{
Enable_ADC_AIN2; // P07
set_ADCS;
while(ADCF == 0);//等待采样完毕
ADCdataH[i] = ADCRH;
ADCdataL[i] = ADCRL;
}
tempH =(ADCdataH[6]+ADCdataH[7]+ADCdataH[8]+ADCdataH[9]+ADCdataH[5])/5;
tempL =(ADCdataL[5]+ADCdataL[6]+ADCdataL[7]+ADCdataL[8]+ADCdataL[9])/5;
ADP07 =((unsigned int)tempH<<4) + tempL;
if(ADP07<=(ADP17+5))
{
P13=1;
}
else if(ADP07>ADP17)
{
P13=0;
}
Timer1_Delay10ms(10);
clr_ADCF; //这里关闭ADC达到省电
/*----电压采样----P03------*/
for(i=0;i<10;i++)
{
Enable_ADC_AIN6; // P03
set_ADCS;
while(ADCF == 0);//等待采样完毕
ADCdataH[i] = ADCRH;
ADCdataL[i] = ADCRL;
}
tempH =(ADCdataH[6]+ADCdataH[7]+ADCdataH[8]+ADCdataH[9]+ADCdataH[5])/5;
tempL =(ADCdataL[5]+ADCdataL[6]+ADCdataL[7]+ADCdataL[8]+ADCdataL[9])/5;
ADP03 =((unsigned int)tempH<<4) + tempL;
clr_ADCF; //这里关闭ADC达到省电看下入这位置对吗
while(1)
{
/*----电压采样----P04------*/
for(i=0;i<10;i++)
{
Enable_ADC_AIN5; // P04
set_ADCS;
while(ADCF == 0);//等待采样完毕
ADCdataH[i] = ADCRH;
ADCdataL[i] = ADCRL;
}
tempH =(ADCdataH[6]+ADCdataH[7]+ADCdataH[8]+ADCdataH[9]+ADCdataH[5])/5;
tempL =(ADCdataL[5]+ADCdataL[6]+ADCdataL[7]+ADCdataL[8]+ADCdataL[9])/5;
ADP04 =((unsigned int)tempH<<4) + tempL;
// ADP03=256;
// ADP04=265;
if(ADP04>(ADP03+20)) //100=0.1V
{
P06=1;
P14=1;
Timer1_Delay10ms(10);
P14=0;
P06=0;
}
else if(ADP04<=ADP03)
{
P14=0;
P06=0;
//想在这位置加个如果在这行代码运行有1分钟,说明设备没有工作,进入掉电省电模式
}
Timer1_Delay10ms(100);
nop;
//当(ADP04>ADP03)电压唤醒休眠接着向下运行代码
}
}
|