本帖最后由 南国的鳕 于 2014-4-14 08:39 编辑
有人遇到过这种情况么,用的C8051F392的CPU。
程序烧进去后大概隔一段时间再上电,系统时钟频率会变化很大。。。
void init() _task_ TASK_INIT{
#if DI_EN
uchar DIStatus;
// uchar diData;
#endif
uchar i;
uchar keystatus = 0xFF;
// uchar SysTickCpy;
// AD.F_Sumclc=0;
// ulong EqCpy;
#if DI_EN
DIStatus=0;
AD.DIData = 0;
ResetDICnt();
#endif
SetSaveSeq=0;
FAutoZero=0;
FAutoCal=0;
ModbusOk = 0;
#if AUTO_CALIBRATION_EN
DispStr2LEDA(64, 64, 64, 64); //----
DispStr2LEDB(64, 64, 64, 64); //----
#else
DispStr2LEDA(_0, _0, _0, _0);
DispStr2LEDB(_0, _0, _0, _0);
#endif
// ADC init
TSample1=4;TSample2=0;AD.SamplePoint=0;
//AD.SamplePoint=183;
Init_Device();
PIN_485DE_RE=BUS_RE;
#if AUTO_CALIBRATION_EN
RAM_FUN03(ADD_BUS_ADDRESS) = 50;
EEPWriteBuff(pbFun03(ADD_BUS_ADDRESS), ADD_EEP_FUN03(ADD_BUS_ADDRESS), 2);
SysTick = 0;
while(SysTick<10);
RAM_FUN03(ADD_BAUDRATE_NO)=3;
EEPWriteBuff(pbFun03(ADD_BAUDRATE_NO), ADD_EEP_FUN03(ADD_BAUDRATE_NO), 2);
SysTick = 0;
while(SysTick<10);
RAM_FUN03(ADD_CT1)=5;
EEPWriteBuff(pbFun03(ADD_CT1), ADD_EEP_FUN03(ADD_CT1), 2);
for(i=0; i<4; i++){
SysTick = 0;
while(SysTick<10);
RAM_FUN03(ADD_EP_TOTAL_HIGH+i)=0;
EEPWriteBuff(pbFun03(ADD_EP_TOTAL_HIGH+i), ADD_EEP_FUN03_E(ADD_EP_TOTAL_HIGH+i), 2);
}
SysTick = 0;
while(SysTick<10);
#endif
SetInit();
IE |= 0x10; //Usart中断使能
// MData.DataMode = MODBUS_IDLE;
SysTick = 1;
while(SysTick);
SysTick = 1;
while(SysTick);
RSTSRC = 0x02;//使能VDD监视器作为复位源
WorkMode = DEF_WORKMODE;
#if DI_EN
for(i=0; i<11; i++){
RAM_FUN03(ADD_TEMPERATURE+i)=0;
}
#else
for(i=0; i<8; i++){
RAM_FUN03(ADD_TEMPERATURE+i)=0;
}
#endif
RAM_FUN03(ADD_PF)=1000;
// RAM_FUN03(ADD_I1)=0;
// RAM_FUN03(ADD_P)=0;
// RAM_FUN03(ADD_Q)=0;
// RAM_FUN03(ADD_S)=0;
SM_BUSY = 0;
WatchDogEnable();
FECalced=0;
os_create_task(TASK_KEYSCAN);
os_create_task(TASK_COMUNICATE);
while(1){
EA=0;
SysTickCpy = SysTick;
EA=1;
WatchDog();
os_wait(K_IVL, 1, 0);
ADCalculate();
if(FlashTimer)FlashTimer--;
if(ADflag){
if(WorkMode<WM_SETMODE)ADDisplay();
else if(!FlashTimer){
ResetFlashTimer();
FlashFlag = ~FlashFlag;
if(FlashPos<8) dispbuff.map[FlashPos] = (FlashFlag?DispBuffBack.map[FlashPos]:0);
else if(FlashPos==8) (dispbuff.Row[LED_ROW_2]) =
(FlashFlag ? (DispBuffBack.Row[LED_ROW_2]):0);
}
}
}
}
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void KeyScan() _task_ TASK_KEYSCAN{
// os_wait(K_TMO, 1, 0);
while(1){
WatchDog();
///// key Scan
// if(SysTickCpy % 4 == 0){ // 10ms
keystatus <<= 1;
keystatus |= 0x11;
if(AD.KeyData12 < 20); //NK
else if(AD.KeyData12 < 90) keystatus &= 0xFE; //k1
else if(AD.KeyData12 < 170) keystatus &= 0xEF; //K2
else keystatus &= 0xEE; //k1k2
////////////////////
#if USER_INTERFACE_EN
#if FUNCTION_TYPE==FUN_AUTOCAL
switch(keystatus){
case 0x80:
case 0x08: //k1k1
case 0x88:
if(WorkMode < WM_SETMODE){
WorkMode=WM_SETMODE;
SetLedA(-1);
SetLedB(-1);
}
else{
WorkMode = DEF_WORKMODE;
}
break;
case K_FUN: //k1 K_FUN
if(WorkMode < WM_SETMODE)WorkMode = MODE_SWITCH_K_FUN[WorkMode];
break;
case K_V_A: //k2 K_VA
if(WorkMode < WM_SETMODE)WorkMode = MODE_SWITCH_K_VA[WorkMode];
break;
}
#else
switch(keystatus){
case 0x80:
case 0x08: //k1k2
case 0x88:
if(WorkMode < WM_SETMODE){
WorkMode=WM_SETMODE;
EnterPasswordInit();
if(SetData != version)
DispIntSet(LEDB,SetData);
FlashFlag =0;
}
else {
WorkMode = DEF_WORKMODE;
// SaveModbusSet();
CheckInitSet();
}
KeyCode = K_SET;
break;
case K_FUN: //k1 K_FUN
if(KeyCode==K_SET){
KeyCode = K_IDEL;
break;
}
#if FUNCTION_TYPE==FUN_3I || FUNCTION_TYPE==FUN_3U
VTmain=0;
#endif
if(WorkMode>=WM_SETMODE && KFunProcTbl[WorkMode-WM_SETMODE]){
KFunProcTbl[WorkMode-WM_SETMODE]();
FlashFlag =0;
if(SetData != version)
DispIntSet(LEDB,SetData);
}
WorkMode = MODE_SWITCH_K_FUN[WorkMode];
#if CLEAR_E_EN
if(WorkMode == WM_CLEAR_E){
DispYesNo();
}
#endif
break;
case K_V_A: //k2 K_VA
if(KeyCode==K_SET){
KeyCode = K_IDEL;
break;
}
#if FUNCTION_TYPE==FUN_3I || FUNCTION_TYPE==FUN_3U
VTmain=0;
#endif
WorkMode = MODE_SWITCH_K_VA[WorkMode];
if(WorkMode>=WM_SETMODE && KVAProcTbl[WorkMode-WM_SETMODE]){
KVAProcTbl[WorkMode-WM_SETMODE]();
#if DI_EN
// if(WorkMode!=WM_DISP_DI)
#endif
#if CLEAR_E_EN
if(WorkMode == WM_CLEAR_E){
DispYesNo();
}
else
#endif
if(SetData != version)
DispIntSet(LEDB,SetData);
FlashFlag =1;
FlashTimer=0;
}
break;
case 0xFF:
KeyCode = K_IDEL;
break;
}
#endif
#endif
// }
if(SysTickCpy == 0xFF){ // 640ms
if(!EpEqChangeFlag)ESaveSeq=-1;
if(--ESaveSeq==1){
// if(EpEqChangeFlag & ( 1<< ESaveSeq)){
// ESaveSeq = ~(1<<ESaveSeq);
EEPWriteBuff(pbFun03(ADD_EP_TOTAL_HIGH),ADD_EEP_FUN03_E(ADD_EP_TOTAL_HIGH), 4);
}
else if(ESaveSeq==0){
EEPWriteBuff(pbFun03(ADD_EQ_TOTAL_HIGH),ADD_EEP_FUN03_E(ADD_EQ_TOTAL_HIGH), 4);
EpEqChangeFlag=0;
}
}
while(SysTickCpy == SysTick);
//
}
}
|