?? lzkfunc.c
字號:
if( MenuKeyPresCNT >= KeyPresEvtTime ) // 20 times Key Press, 250mS.
{
if( MenuKeyPresEVT == 0 )
{
MenuKeyPresCNT = MenuKeyPresCNT - KeyPresEvtTime;
MenuKeyPresEVT = 1;
}
}
}
else
{
if( MenuKeyPresCNT >= KeyPresEvtTime ) // 20 times Key Press, 250mS.
MenuKeyPresEVT = 1;
if( MenuKeyPresCNT >= KeyRelsEvtTime ) // 2 times Key Press, 25mS.
MenuKeyRelsEVT = 1;
MenuKeyPresCNT = 0; // .
} /* End of Menu Key */
/***KEY1******************************************************/
if( KEY1 == 0 ) // Begin of Up Key.
{ // KEY1: Up Key.
UpKeyPresCNT++;
if( UpKeyPresCNT >= KeyPresEvtTime ) // 20 times Key Press, 250mS.
{
if( UpKeyPresEVT == 0 )
{
UpKeyPresCNT = UpKeyPresCNT - KeyPresEvtTime;
UpKeyPresEVT = 1;
}
}
}
else
{
if( UpKeyPresCNT >= KeyPresEvtTime ) // 20 times Key Press, 250mS.
UpKeyPresEVT = 1;
if( UpKeyPresCNT >= KeyRelsEvtTime ) // 2 times Key Press, 25mS.
UpKeyRelsEVT = 1;
UpKeyPresCNT = 0; // .
} /* End of Up Key */
/***KEY2******************************************************/
if( KEY2 == 0 ) // Begin of Down Key.
{ // KEY2: Down Key.
DownKeyPresCNT++;
if( DownKeyPresCNT >= KeyPresEvtTime ) // 20 times Key Press, 250mS.
{
if( DownKeyPresEVT == 0 )
{
DownKeyPresCNT = DownKeyPresCNT - KeyPresEvtTime;
DownKeyPresEVT = 1;
}
}
}
else
{
if( DownKeyPresCNT >= KeyPresEvtTime ) // 20 times Key Press, 250mS.
DownKeyPresEVT = 1;
if( DownKeyPresCNT >= KeyRelsEvtTime ) // 2 times Key Press, 25mS.
DownKeyRelsEVT = 1;
DownKeyPresCNT = 0; // .
} /* End of Down Key */
/***KEY3******************************************************/
if( KEY3 == 0 ) // Begin of Enter Key.
{ // KEY3: Enter Key.
EnterKeyPresCNT++;
if( EnterKeyPresCNT >= KeyPresEvtTime )// 20 times Key Press, 250mS.
{
if( EnterKeyPresEVT == 0 )
{
EnterKeyPresCNT = EnterKeyPresCNT - KeyPresEvtTime;
EnterKeyPresEVT = 1;
}
}
}
else
{
if( EnterKeyPresCNT >= KeyPresEvtTime )// 20 times Key Press, 250mS.
EnterKeyPresEVT = 1;
if( EnterKeyPresCNT >= KeyRelsEvtTime ) // 2 times Key Press, 25mS.
EnterKeyRelsEVT = 1;
EnterKeyPresCNT = 0;
} /* End of Enter Key */
KeyScanIntvlCNT = 0;
}
/*****************************************************************
*** CanBUS數據收發
*****************************************************************/
}
/*****************************************************************
*** TIMER 0 SLOT 3
*** (1)直流勵磁電壓UF采樣, 每周波32點(1.6kSPS);
*** (2)直流勵磁電流IF采樣,每周波32點(1.6kSPS);
*****************************************************************/
/*
uint8 xdata EmVoltSamCNT;
INTUC xdata EmVoltSamDATA[32];
uint16 xdata EmVoltDATA; // 勵磁電壓實測值
uint8 xdata EmCurrSamCNT;
INTUC xdata EmCurrSamDATA[32];
uint16 xdata EmCurrDATA; // 勵磁電流實測值
EmVoltSamEN
EmVoltSamOVER
EmCurrSamEN
EmCurrSamOVER
*/
if( TimSlotCNT == 3 ) // 32 * 0.625 = 20mS.
{
if( EmVoltSamEN == 1 )
{
ADC0_CH_Setting(0x02); // AIN02 for UF.
AD0INT = 0; // RST ADC Convert Complete Flag.
AD0INT = 0; // Delay.
AD0BUSY = 1; // Start ADC0
while( AD0INT == 0 ); // Wait for Convert Over
EmVoltSamDATA[EmVoltSamCNT].ucVAR[1] = ADC0H; // Get High 8 Byte.
EmVoltSamDATA[EmVoltSamCNT].ucVAR[0] = ADC0L; // Get Low 8 Byte.
EmVoltSamDATA[EmVoltSamCNT].uiVAR = EmVoltSamDATA[EmVoltSamCNT].uiVAR >> 4;
EmVoltSamCNT++;
if( EmVoltSamCNT >= 32 )
{
EmVoltSamCNT = 0;
EmVoltSamEN = 0; // 等待程序重新使能
EmVoltSamOVER = 1; // 本輪采樣結束標記,等待處理
}
}
if( EmCurrSamEN == 1 )
{
ADC0_CH_Setting(0x03); // AIN03 = IF or CurrRingEI.
AD0INT = 0; // RST ADC Convert Complete Flag.
AD0INT = 0; // Delay.
AD0BUSY = 1; // Start ADC0
while( AD0INT == 0 ); // Wait for Convert Over
EmCurrSamDATA[EmCurrSamCNT].ucVAR[1] = ADC0H; // Get High 8 Byte.
EmCurrSamDATA[EmCurrSamCNT].ucVAR[0] = ADC0L; // Get Low 8 Byte.
EmCurrSamDATA[EmCurrSamCNT].uiVAR = EmCurrSamDATA[EmCurrSamCNT].uiVAR >> 4;
EmCurrSamCNT++;
if( EmCurrSamCNT >= 32 )
{
EmCurrSamCNT = 0;
EmCurrSamEN = 0; // 等待程序重新使能
EmCurrSamOVER = 1; // 本輪采樣結束標記,等待處理
}
}
else
{
if( EmCurr_CurrRingSamEN )
{
ADC0_CH_Setting(0x03); // AIN03 = CurrRingEI.
AD0INT = 0; // RST ADC Convert Complete Flag.
AD0INT = 0; // Delay.
AD0BUSY = 1; // Start ADC0
while( AD0INT == 0 ); // Wait for Convert Over
EmCurr_CurrRingSamDATA[EmCurr_CurrRingSamCNT].ucVAR[1] = ADC0H; // Get High 8 Byte.
EmCurr_CurrRingSamDATA[EmCurr_CurrRingSamCNT].ucVAR[0] = ADC0L; // Get Low 8 Byte.
EmCurr_CurrRingSamDATA[EmCurr_CurrRingSamCNT].uiVAR = EmCurr_CurrRingSamDATA[EmCurr_CurrRingSamCNT].uiVAR >> 4;
EmCurr_CurrRingSamCNT++;
if( EmCurr_CurrRingSamCNT >= 32 )
{
EmCurr_CurrRingSamCNT = 0;
EmCurr_CurrRingSamEN = 0; // 等待程序重新使能
EmCurr_CurrRingSamOVER = 1; // 本輪采樣結束標記,等待處理
}
}
}
}
/*****************************************************************
*** TIMER 0 SLOT 4
*** (1)采樣定子電壓或功率因數電流環電流;
*** (2)電流采樣,用于計算功率因數
*****************************************************************/
/*
uint8 xdata DUxDIxSamCNT; // 采樣計數
INTUC xdata DUxSamDATA[32]; //
INTUC xdata DIxSamDATA[32]; //
DUxDIxSamOVER //
*/
if( TimSlotCNT == 4 ) //
{
/*****************************************************************
*** 功率因數電流環電流采樣;
*****************************************************************/
if( PwrFact_CurrRingSamEN == 1 )
{
CurrRingEYSamTimSlotCNT++; // 采樣間隔4 * 0.625uS = 2.5mS.
if( CurrRingEYSamTimSlotCNT >= 4 )
{
CurrRingEYSamTimSlotCNT = 0;
ADC0_CH_Setting(0x00); // AIN00 = AinDU or CurrRingEY.
AD0INT = 0; // RST ADC Convert Complete Flag.
AD0INT = 0; // Delay.
AD0BUSY = 1; // Start ADC0
while( AD0INT == 0 ); // Wait for Convert Over
PwrFact_CurrRingSamDATA[PwrFact_CurrRingSamTimCNT].ucVAR[1] = ADC0H; // Get High 8 Byte.
PwrFact_CurrRingSamDATA[PwrFact_CurrRingSamTimCNT].ucVAR[0] = ADC0L; // Get Low 8 Byte.
PwrFact_CurrRingSamDATA[PwrFact_CurrRingSamTimCNT].uiVAR = CurrRingEYDATA[CurrRingEYSamTimCNT].uiVAR >> 4;
PwrFact_CurrRingSamTimCNT++;
if( PwrFact_CurrRingSamTimCNT >= 8 )
{
PwrFact_CurrRingSamTimCNT = 0;
PwrFact_CurrRingSamEN = 0;
PwrFact_CurrRingSamOVER = 1;
}
} // End of CurrRingEY Sampling.
}
/*****************************************************************
*** (1)采樣定子電壓;
*** (2)采樣定子電流;
*** 說明:優先級低于功率因數電流環方式;
*****************************************************************/
else
{
if( PwrFact_DUxDIxSamEN == 1 )
{
ADC0_CH_Setting(0x00); // AIN00 = AinDU or CurrRingEY.
AD0INT = 0; // RST ADC Convert Complete Flag.
AD0INT = 0; // Delay.
AD0BUSY = 1; // Start ADC0
while( AD0INT == 0 ); // Wait for Convert Over
DUxSamDATA[DUxDIxSamCNT].ucVAR[1] = ADC0H; // Get High 8 Byte.
DUxSamDATA[DUxDIxSamCNT].ucVAR[0] = ADC0L; // Get Low 8 Byte.
DUxSamDATA[DUxDIxSamCNT].uiVAR = DxSamDATA[DUxDIxSamCNT].uiVAR >> 4;
ADC0_CH_Setting(0x01); // AIN01 = AinDI.
AD0INT = 0; // RST ADC Convert Complete Flag.
AD0INT = 0; // Delay.
AD0BUSY = 1; // Start ADC0
while( AD0INT == 0 ); // Wait for Convert Over
DIxSamDATA[DUxDIxSamCNT].ucVAR[1] = ADC0H; // Get High 8 Byte.
DIxSamDATA[DUxDIxSamCNT].ucVAR[0] = ADC0L; // Get Low 8 Byte.
DIxSamDATA[DUxDIxSamCNT].uiVAR = DIxSamDATA[DUxDIxSamCNT].uiVAR >> 4;
DUxDIxSamCNT++;
if( DUxDIxSamCNT >= 32 )
{
DUxDIxSamCNT = 0;
PwrFact_DUxDIxSamEN = 0;
PwrFact_DUxDIxSamOVER = 1;
}
}
}
}
TimSlotCNT++; // Time Slot Counting.
if( TimSlotCNT >= 5 )
TimSlotCNT = 0;
uiTimCNT++; // 1S Counting.
if( uiTimCNT >= 8000 ) // Second Time Base.
{
uiTimCNT = 0; // .
SecFlag = 1; // Second Signal.
}
}
/****************************************************************************
** 函數名稱: T3_ISR()
** 功能描述: T3定時器中斷處理,中斷間隔10mS
(1)電機正常啟動;
(2)電機降壓啟動;
(3)電機失控處理;
(4)電機失步處理;
** 入口參數: 無
** 出口參數: 無
** 全局變量: 無
** 調用模塊: 無
** 說明:
****************************************************************************/
void T3_ISR(void) interrupt 14
{
SFRPAGE = TMR3_PAGE; // Change to TIMER01 PAGE.
TF3 = 0;
if( MotNmlVoltStaUpEN == 1 ) // 電機正常啟動.
{
}
if( MotLowVoltStaUpEN == 1 ) // 電機降壓啟動.
{
}
if( MotAsyncAftSyncEvt )
{
TrigOutEN = 0;
MotAsyncAftSyncEvt = 0;
}
}
/****************************************************************************
** 函數名稱: main()
** 功能描述: 主程序,處理非實時任務或計算任務;
** 入口參數: 無
** 出口參數: 無
** 全局變量: 無
** 調用模塊: 無
** 說明:
****************************************************************************/
void main(void)
{
uint8 data i, j, ucTMP, LCD_DispBuff[3];
uint8 data SecCNT;
uint16 idata uiTMP;
EA = 0;
SP = 0xC0; // SP: 64 Bytes,0xC0~0xff, User: 192 Bytes.
WDT_Disabled(); // WatchDog Disabled.
Port_Init(); // I/O Port and EMIF Config.
External_Osc(); // Switch to External Oscillator, 24.000MHz.
Interrupt_Init(); // Interrupt Controllor Initialize.
Ref_Init(1); // Enabled Internal Vlotage Reference.
ADC0_Init(1,0,0,0,0,0,1); // ADC0 Enabled, AD0BUSY, CH0, GAIN: 1, HVA Disabled, HVA GAIN: 1, Left-justified.
PCA_Init(); // CEX0: Square Wave. CEX1: "1".
PulseOutPut(0x7f); // iLED = "0",Pulse Output Indicating.
LCD_nCS0 = 1; // 禁止LCD總線輸出,防止數據總線沖突.
T0T1_Init(); // T0: 125uS; T1: PhaseDiff MSR.
T4_Init(); // UART0 Baudrate, RS-485.
T0_RunCtrl(1);
LED_OnOff(BLED,1); // LCD BackLED On.
BLED_ON_Flag = 1;
BLED_ON_CNT = 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -