#include "N76E003.h"
#include "Main.h"
#include "Definition.h"
#include "menu.h"
#include "Buzzer.h"
#include "Function_define.h"
#include "SFR_Macro.h"
#include "receive.h"
#include "flash_eeprom.h"
void MCU_IO_Port_init(void);
void Timer0Initial(void);
void Timer1Initial(void);
void CheckInPut(void);
void Check_KeyCode(void);
extern bit BIT_TMP;
G_TIME_RAM g_Time_ram;
G_SYSTEM_RAM g_System_ram;
struct Work_Register WRC;
INT8U idata powerOnBti;
INT8U enableBit;
/*
INT8U read_APROM_BYTE_(INT16U code *u16_addr)
{
INT8U rdata;
rdata = *u16_addr>>8;
return rdata;
}
*/
void MCU_IO_Port_init(void)
{
P00_Input_Mode;
P02_Quasi_Mode;
P03_Input_Mode;
P10_Input_Mode;
P11_Input_Mode;
P12_Input_Mode;
P13_Input_Mode;
P14_Input_Mode;
P15_Input_Mode;
P01_PushPull_Mode;
P04_PushPull_Mode;
P05_PushPull_Mode;
P06_PushPull_Mode;
P07_PushPull_Mode;
P17_PushPull_Mode;
P30_PushPull_Mode;
P_LampOut = IO_OFF;
P_MidLockOut = IO_OFF;
P_MidOpenOut = IO_OFF;
P_LedOut = IO_OFF;
P_BUZZER_OUT = IO_OFF;
P_TrunkOut = IO_OFF;
P_EngineOffOut = IO_OFF;
}
/************************************************************************************************************
* Main function
************************************************************************************************************/
void main (void)
{
static INT8U SysStatusTemp = 0;
static INT8U MidLockBit = 0,MidUnLockBit = 0;
TMOD = 0XFF;
clr_T0M;
clr_T1M;
set_EA;
MCU_IO_Port_init();
Timer0Initial();// 100us
Timer1Initial();// 1ms
////////////////////////////上电读取eeprom的数据///////////////
UserReadData();
if (g_System_ram.SysStatus == SYS_DISARMMODE)
{
WRC.SecondRelockBit = 1;
p_MenuMode = DisarmMode;
g_System_ram.Initial = TRUE;
P_EngineOffOut = FALSE;
P_LedOut = FALSE;
}
else if ((g_System_ram.SysStatus == SYS_ARMMODE)||(g_System_ram.SysStatus == SYS_AnitHiJack))
{
p_MenuMode = ArmMode;
g_System_ram.Initial = TRUE;
WRC.MidStatusBit = 1;
enableBit = 1;
}
else
{
p_MenuMode = powerOn;
g_System_ram.Initial = FALSE;
}
powerOnBti = TRUE;
WRC.Save_LockTypeBit = 1;
WRC.Save_BrakeBit = 1;
WRC.Save_ShockBit = 1;
if (!P_ResetIn)
{
p_MenuMode = TestMode;
g_System_ram.Initial = FALSE;
}
if (P_Jump1)
{
WRC.Jump1InBit = 1;
}
else
{
WRC.Jump1InBit = 0;
}
///////////////////////////////////////////////////////////////////////////
while (1)
{
CheckInPut();
Check_KeyCode();
if (!WRC.Jump1InBit)//插上跳线时,取消自动设防功能
{
WRC.AutoRelock = 0;
}
if ((!P_EngineOffOut)&&(p_MenuMode != ArmMode)&&(p_MenuMode != TestLockMode)
&&(p_MenuMode != TestMode))
{
if (WRC.ManualLock)
{
if (!MidLockBit)
{
g_Time_ram.TimeForEleLock_100ms = 0;
g_Time_ram.TimeForAirLock_100ms = 0;
P_MidLockOut = TRUE;
P_MidOpenOut = FALSE;
WRC.MidStatusBit = 1;
MidLockBit = 1;
enableBit = 0;
}
}
else
{
MidLockBit = 0;
}
if (WRC.ManualUnLock)
{
if (!MidUnLockBit)
{
g_Time_ram.TimeForEleLock_100ms = 0;
g_Time_ram.TimeForAirLock_100ms = 0;
P_MidOpenOut = TRUE;
P_MidLockOut = FALSE;
WRC.MidStatusBit = 0;
MidUnLockBit = 1;
}
}
else
{
MidUnLockBit = 0;
}
}
/////////////////////////////////////////////////////////////////////////
if ((WRC.AccInBit)&&(!WRC.DoorInBit_N))
{
if (WRC.RestInHiGoingEdgeBit)//紧急解除
{
if ((p_MenuMode == AlarmMode)||(p_MenuMode == AlarmForShockMode)
||(p_MenuMode == ArmMode))
{
P_EngineOffOut = FALSE;
P_LedOut = FALSE;
g_Time_ram.CheckResetInTime = 0;
p_MenuMode = DisarmMode;
WRC.AccInLowGoingEdgeBit = 0;
g_System_ram.Initial = FALSE;
WRC.RestInHiGoingEdgeBit = 0;
WRC.TriggerCount++;
if (!WRC.SilenceBit)
{
Buzzer_Bz_Bz();
}
}
}
}
/////////////////////////////////////////////////////////////////////////
///////////////////写码开始//////////////////////////////////////////////
if ((WRC.AccInBit)&&(WRC.DoorInBit_N))
{
if (WRC.RestBit)
{
if (g_Time_ram.TimeForWriteCode_100ms >= 50)
{
if ((p_MenuMode != LearnCodeMode)&&(p_MenuMode != AlarmMode)
&&(p_MenuMode != ArmMode)&&(p_MenuMode != TestLockMode)
&&(p_MenuMode != PanicMode))
{
p_MenuMode = LearnCodeMode;
g_System_ram.Initial = FALSE;
WRC.ClearCodeBit = 1;
P_LampOut = TRUE;
P_LedOut = TRUE;
}
}
}
else
{
g_Time_ram.TimeForWriteCode_100ms = 0;
}
}
else
{
g_Time_ram.TimeForWriteCode_100ms = 0;
}
/////////////////////写码结束////////////////////////////////////////////
p_MenuMode(); /////////主菜单/////////
/////////////////////中控锁的断开输出////////////////////////////////////
if ((p_MenuMode != TestUnLockMode)&&(p_MenuMode != TestLockMode))
{
if(WRC.Save_LockTypeBit)
{
if (g_Time_ram.TimeForEleLock_100ms >= 5)//电锁输出 0.5s
{
P_MidLockOut = FALSE;
P_MidOpenOut = FALSE;
}
}
else
{
if (g_Time_ram.TimeForAirLock_100ms >= 40)
{
P_MidLockOut = FALSE;
P_MidOpenOut = FALSE;
}
}
}
/////////////////////////////////////////////////////////////////////////
/////////////////////行李箱开启开始//////////////////////////////////////
if ((WRC.KeyCode == REWORD12_L)||(WRC.KeyCode == REWORD4_L))
{
g_Time_ram.TimeForTrunk_100ms = 0;
P_TrunkOut = IO_ON;
}
if (g_Time_ram.TimeForTrunk_100ms >= 8)
{
P_TrunkOut = IO_OFF;
}
//////////////////////行李箱开启结束////////////////////////////////////
//////////////////////掉电存储状态//////////////////////////////////////
if (SysStatusTemp != g_System_ram.SysStatus) //当状态发生变化的时候再去启动存储功能
{
WriteBuffer[13] = g_System_ram.SysStatus;
WriteBuffer[12] = WRC.SilenceBit;
if (g_Time_ram.TimeForOutage_100ms >= 15)//动作完再存储
{
if (UserWriteData()== TRUE)
{
UserReadData();
SysStatusTemp = g_System_ram.SysStatus;
}
}
}
else
{
g_Time_ram.TimeForOutage_100ms = 0;
}
/////////////////////////////////////////////////////////////////////////
if ((p_MenuMode == IdleMode)||(p_MenuMode == DisarmMode)
||(p_MenuMode == DoorOpenMode))//关闭LED常亮3秒,报警提示状态
{
if (g_Time_ram.TimeForLEDoff_100ms >= 30)
{
P_LedOut = FALSE;
}
}
/////////////////////////////////////////////////////////////////////////
if (WRC.KeyCode != REWORD4)
{
WRC.KeyCode = FALSE;
}
}
}
void CheckInPut(void)
{
///////////////////////////////////////////////////////////////
if ((P_AccIn)&&(g_Time_ram.CheckAccOnPasitiveTime >= 2))
{
WRC.AccInBit = 1;
}
else
{
if (!P_AccIn)
{
g_Time_ram.CheckAccOnPasitiveTime = 0;
WRC.AccInBit = 0;
}
}
//////////////////ACC边沿信号检测//////////////////////////////
if (P_AccIn)
{
if (WRC.AccInStatusTemp)
{
if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)
&&(p_MenuMode != ArmMode)&&(WRC.DoorInBit_N))
{
WRC.TriggerCount++;
}
WRC.AccInStatusTemp = FALSE;
WRC.AccInHiGoingEdgeBit = 1;
powerOnBti = FALSE;
}
}
else
{
if (!WRC.AccInStatusTemp)
{
WRC.AccInStatusTemp = TRUE;
if (!powerOnBti)
{
WRC.AccInLowGoingEdgeBit = 1;
}
/*if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)
&&(p_MenuMode != ArmMode)&&(WRC.DoorInBit_N))
{
WRC.TriggerCount++;
}*/
}
}
/////////////////////////////////////////////////////////////
//////////////////边门负检测///////////////////////////////
if ((!P_DoorIn_N)&&(g_Time_ram.CheckDoorNagetiveTime >= 2))
{
WRC.DoorInBit_N = 0;
}
else
{
if (P_DoorIn_N)
{
g_Time_ram.CheckDoorNagetiveTime = 0;
WRC.DoorInBit_N = 1;
}
}
///////////////边门边沿信号检测///////////////////////////
if (!P_DoorIn_N)
{
if (WRC.DoorInStatus)
{
if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)&&(p_MenuMode != ArmMode))
{
WRC.TriggerCount++;
}
WRC.DoorInStatus = FALSE;
WRC.DoorInHiGoingEdgeBit = 1;
}
}
else
{
if (!WRC.DoorInStatus)
{
WRC.DoorInStatus = TRUE;
WRC.DoorInLowGoingEdgeBit = 1;
/*if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)&&(p_MenuMode != ArmMode))
{
WRC.TriggerCount++;
}*/
}
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
if ((P_BrakeIn)&&(g_Time_ram.CheckBrakeTime >= 2))
{
WRC.BrakeInBit = 1;
}
else
{
if (!P_BrakeIn)
{
g_Time_ram.CheckBrakeTime = 0;
WRC.BrakeInBit = 0;
}
}
//////////////////脚刹边沿信号检测//////////////////////////////
if (P_BrakeIn)
{
if (WRC.BrakeInStatusTemp)
{
WRC.BrakeInStatusTemp = FALSE;
WRC.BrakeInHiGoingEdgeBit = 1;
}
}
else
{
if (!WRC.BrakeInStatusTemp)
{
WRC.BrakeInStatusTemp = TRUE;
WRC.BrakeInLowGoingEdgeBit = 1;
}
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
if ((!P_ShockIn)&&(g_Time_ram.CheckShockInTime >= 10))
{
WRC.ShockSensorBit = 1;
g_Time_ram.CheckShockInTimeTemp = 0;
}
else
{
if ((P_ShockIn)&&(g_Time_ram.CheckShockInTimeTemp >= 20))
{
g_Time_ram.CheckShockInTime = 0;
WRC.ShockSensorBit = 0;
}
}
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
if ((!P_ResetIn)&&(g_Time_ram.CheckResetInTime >= 1))
{
WRC.RestBit = 1;
}
else
{
if (P_ResetIn)
{
g_Time_ram.CheckResetInTime = 0;
WRC.RestBit = 0;
}
}
if (WRC.RestBit)
{
if (WRC.RestInStatus)
{
WRC.RestInStatus = FALSE;
WRC.RestInHiGoingEdgeBit = 1;
}
}
else
{
if (!WRC.RestInStatus)
{
WRC.RestInStatus = TRUE;
WRC.RestInHiGoingEdgeBit = 0;
}
}
///////////////////////////////////////////////////////
if ((!P_ManualLockIn)&&(g_Time_ram.ManualLockTime >= 2))
{
WRC.ManualLock = 1;
}
else
{
if (P_ManualLockIn)
{
g_Time_ram.ManualLockTime = 0;
WRC.ManualLock = 0;
}
}
if ((!P_ManualUnLockIn)&&(g_Time_ram.ManualUnLockTime >= 2))
{
WRC.ManualUnLock = 1;
}
else
{
if (P_ManualUnLockIn)
{
g_Time_ram.ManualUnLockTime = 0;
WRC.ManualUnLock = 0;
}
}
//////////////////////////////////////////////////////////////////
}
void Check_KeyCode(void)
{
static INT8U keyBit = 0;
if (ReceiveBuffer[2] != 0)
{
if (WRC.K_OldKeyCode == ReceiveBuffer[2])
{
if (ReceiveBuffer[2] != REWORD4)
{
if (g_Time_ram.TimeForContinueKey_100ms >= 15)
{
g_Time_ram.TimeForContinueKey_100ms = 0;
if (!keyBit)
{
keyBit = 1;
WRC.KeyCode = ReceiveBuffer[2]|0x30;
}
}
}
else
{
if (g_Time_ram.TimeForContinueKey_100ms >= 20)
{
g_Time_ram.TimeForContinueKey_100ms = 0;
if (!keyBit)
{
keyBit = 1;
WRC.KeyCode = ReceiveBuffer[2]|0x30;
}
}
g_Time_ram.TimeForContinueKey_10ms = 0;
}
}
else
{
if (((ReadBuffer[0] == ReceiveBuffer[0])&&(ReadBuffer[1] == ReceiveBuffer[1])&&(ReadBuffer[2] == ReceiveThirdData))
||((ReadBuffer[3] == ReceiveBuffer[0])&&(ReadBuffer[4] == ReceiveBuffer[1])&&(ReadBuffer[5] == ReceiveThirdData))
||((ReadBuffer[6] == ReceiveBuffer[0])&&(ReadBuffer[7] == ReceiveBuffer[1])&&(ReadBuffer[8] == ReceiveThirdData))
||((ReadBuffer[9] == ReceiveBuffer[0])&&(ReadBuffer[10] == ReceiveBuffer[1])&&(ReadBuffer[11] == ReceiveThirdData))
||(WRC.WriteCodeBit))
{
WRC.KeyCode = ReceiveBuffer[2];
WRC.K_OldKeyCode = ReceiveBuffer[2];
g_Time_ram.TimeForContinueKey_100ms = 0;
g_Time_ram.TimeForContinueKey_10ms = 0;
keyBit = 0;
}
}
}
else
{
WRC.K_OldKeyCode = 0;
g_Time_ram.TimeForContinueKey_100ms = 0;
}
}
|