void OPAAdjusting(void) { if((b_SYSInitial!=0)&&(b_AdjustOPAOK!=1)) { //--------------------------------------------------50 //_Step1 _ocpdc0 = 0x82; _ocpocal = 0xC0; //进入失调校准模式,运算放大器 _ocpccal = 0x00; //比较器 _ocpda = 0x5D; //(VDD-1.4)/2 _Delay_Timer(250); M_MBuf0 = 0; if(_ocpo!=0) {M_MBuf0 = 0X01;} //save last status //----------------------------------------40 _OPAAdjust_Loop0: _Delay_Timer(250); M_MBuf1 = 0; if(_ocpo!=0) {M_MBuf1 = 0X01;} M_MBuf4 = M_MBuf0^M_MBuf1; if(M_MBuf4 == 0) { if((_ocpocal&0x3F)!=0x3F) { _ocpocal ++; goto _OPAAdjust_Loop0; } else {goto _OPAAdjust_Fail;} //Max } //--------------------------------------------------50 //_Step2 M_MBuf2 = _ocpocal&0x3F; _ocpocal = 0xFF; //进入失调校准模式,运算放大器 _Delay_Timer(250); M_MBuf0 = 0; if(_ocpo) {M_MBuf0 = 0X01;} //save last status //----------------------------------------40 _OPAAdjust_Loop1: _Delay_Timer(250); M_MBuf1 = 0; if(_ocpo) {M_MBuf1 = 0X01;} M_MBuf4 = M_MBuf0^M_MBuf1; if(M_MBuf4 == 0) { if((_ocpocal&0x3F)!=0x3F) { _ocpocal --; goto _OPAAdjust_Loop1; } else {goto _OPAAdjust_Fail;} //Min } //--------------------------------------------------50 //_Step3 M_MBuf3 = _ocpocal&0x3F; M_MBuf3 = (M_MBuf2+M_MBuf3)>>1; //(Vos1+Vos2)/2 M_MBuf3 ++; //内部放大校准成功 _ocpocal &= 0x0C; _ocpocal = _ocpocal|M_MBuf3; _oofm = 0; //退出失调校准 b_AdjustOPAOK = 1; p_OPAAdj_L = 0; //再校准 pc_OPAAdj_L = 0; goto OPAAdjusting_End; //内部放大校准失败 _OPAAdjust_Fail: _oofm = 0; //退出失调校准 b_AdjustOPAOK = 1; b_AdjuOPAADOK = 1; OPAAdjusting_End: _ocpdc0 = 0x9A; //reference 93 page _ocpdc1 = 0x04; //reference 94 page } } //*************************************************************************** //*************************************************************************** //******************** 全局调用子函数 ************************************* //*************************************************************************** //*************************************************************************** ////================================================================ ////================================================================ void _Delay_Timer(Byte DelayTimer) { for(; DelayTimer > 0; DelayTimer--) {_nop();_nop();} return; }