⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remote.c

📁 无线汽车遥控器源代码,不可多得的开发资料 有很好的参考价值
💻 C
📖 第 1 页 / 共 3 页
字号:
void run_process(void)
{
      static bank1 RunStruct Run=0;
      
      ///////////15s后自动锁门////////
      static Timer16Struct AutoLock=0;
      if(Flag.SystemStateChange)
      {
            AlarmNoub=0;
            Flag.SystemStateChange=0;
            Run.State=0;
            AutoLock.Interval=0;
            Run.DoorOpened=0;
      }
      switch(Run.State)
      {
            case 0:
                  if(InState.SideDoor)
                        Run.DoorOpened=1;
                  if(!InState.SideDoor&&Run.DoorOpened)
                  {
                        Run.State=0;
                        Run.DoorOpened=0;
                        AutoLock.Interval=0;
                  }
                  if(++AutoLock.Interval>=15000/TIME_BASE)
                  {
                        Run.State=1;
                        AutoLock.Interval=0;
                  }
                  break;
            case 1:
                  if(InState.Brake)
                  {
                        Run.Lock=1;
                        Run.State=2;
                  }
                  break;
            case 2:
                  if(InState.SideDoor)
                        Run.DoorOpened=1;
                  if(!InState.SideDoor&&Run.DoorOpened)
                  {
                        Run.State=0;
                        Run.DoorOpened=0;
                  }
                  break;      
            default:
                  Run.State=2;
                  break;
      }
      /////////////////////////////////
      if(RemoteKey.Flag.Press)
      {
            switch(RemoteKey.Key)
            {
                  case KEY_LOCK:
                  		Run.Unlock=0;
                        Run.Lock=1;
                        door_lock_process(0,0);
                        RemoteKey.Flag.Press=0;
                        break;
                  case KEY_UNLOCK:
                  		Run.Lock=0;
                        Run.Unlock=1;
                        door_lock_process(0,0);
                        RemoteKey.Flag.Press=0;
                        break;
                  case KEY_FIND:
                        if(RemoteKey.Time.Interval>=1500/TIME_BASE)
                        {
                              RemoteKey.Flag.Press=0;
                              system_state_change(State,ALARM_HELP,1);
                        }
                        break;
                  case KEY_QUIET:
                        if(RemoteKey.Time.Interval>=1500/TIME_BASE)
                        {
                              RemoteKey.Flag.Press=0;
                              Energency=PRESS_FIND;
                              system_state_change(State,ALARM_ENERGENCY,1);
                        }
                        break;
                  default:break;
            }
      }
      
      roadside_stop();
      
      if(!InState.Acc)
      {
            //PreState=State;
            //State=NORMAL;
            system_state_change(State,NORMAL,1);
      }
      if(Run.Unlock)
      {
            if(door_lock_process(500/TIME_BASE/5,LOCK_OFF))
            {
                  Run.Unlock=0;
                  if(Jump.Electromotion)
                        door_lock_process(0,0);
            }
      }
      else if(Run.Lock)
            if(door_lock_process(500/TIME_BASE/5,LOCK_ON))
            {
                  Run.Lock=0;
                  if(Jump.Electromotion) 
                        door_lock_process(0,0);
            }
}
void alarm_down_opened_process(void)
{
      //alarm_led_long_light(4,4);
      
      if(Flag.SystemStateChange)
      {
            Flag.SystemStateChange=0;
            if(AlarmNoub++>=3) AlarmNoub=3;
      }
      
      if(AlarmGrade<=Opened)
            AlarmGrade=Opened;
      signal_led_alarm(AlarmGrade);
      frameout_precoss(60);
      flash_trun_signal(500/TIME_BASE,500/TIME_BASE,26);
      if(speak_act_precoss(0,0,26000/TIME_BASE/5,LONG))
      {
            speak_act_precoss(0,0,0,RESET);
            flash_trun_signal(0,0,0);
            system_state_change(State,PreState,0);
      } 
      if(RemoteKey.Flag.Press)
      {
            RemoteKey.Flag.Press=0;
            switch(RemoteKey.Key)
            {
                  case KEY_LOCK:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_UNLOCK:
                        system_state_change(PreState,NORMAL,1);
                        break;
                  case KEY_FIND:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_QUIET:
                        system_state_change(State,PreState,0);
                  default:break;
            }
      }
}

void shark_alarm(uchar Mode)
{
	if(Flag.SystemStateChange)
      {
            Flag.SystemStateChange=0;
            if(AlarmNoub++>=3) AlarmNoub=3;
      }
      if(AlarmGrade<=Shaked)
            AlarmGrade=Shaked;
	signal_led_alarm(AlarmGrade);
	if(SharkFlag.Time==1)
	{
	      //if(frameout_precoss(60));
	      if(Mode==SOUND_MODE) 
			if(speak_act_precoss(50/TIME_BASE,950/TIME_BASE,5,SHORT));
		if(flash_trun_signal(500/TIME_BASE,500/TIME_BASE,5))
	      {
	            speak_act_precoss(0,0,0,RESET);
	            flash_trun_signal(0,0,0);
	            system_state_change(State,PreState,0);
	      }

	}
      else if(SharkFlag.Time==2)
      {
	      if(frameout_precoss(61));
	      if(Mode==SOUND_MODE)  
			if(speak_act_precoss(0,0,27000/TIME_BASE/5,LONG));
	      if(flash_trun_signal(500/TIME_BASE,500/TIME_BASE,26))
	      {
	            speak_act_precoss(0,0,0,RESET);
	            flash_trun_signal(0,0,0);
	            system_state_change(State,PreState,0);
	      }
      }       
	if(InState.SideDoor==DOOR_OPENED||InState.Acc||InState.Brake)
            system_state_change(PreState,ALARM_DOOR_OPENED,1);
}
void alarm_quiet_process(void)
{
      //if(Flag.SystemStateChange)
      //{
            //Flag.SystemStateChange=0;
            //if(AlarmNoub++>=3) AlarmNoub=3;
      //}
      //if(AlarmGrade<=Shaked)
            //AlarmGrade=Shaked;
      
      
	shark_alarm(QUIET_MODE);
      
      if(RemoteKey.Flag.Press)
      {
            RemoteKey.Flag.Press=0;
            switch(RemoteKey.Key)
            {
                  case KEY_LOCK:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_UNLOCK:
                        
                        system_state_change(PreState,NORMAL,1);
                        break;
                  case KEY_FIND:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_QUIET:
                        system_state_change(State,PreState,0);
                  default:break;
            }
      }
}

void alarm_sound_process(void)
{
      
      //signal_led_alarm(AlarmGrade);
      
	shark_alarm(SOUND_MODE);
      //if(InState.SideDoor==DOOR_OPENED)
      //if(InState.SideDoor==DOOR_OPENED||InState.Acc||InState.Brake)
            //system_state_change(PreState,ALARM_DOOR_OPENED,1);
      if(RemoteKey.Flag.Press)
      {
            RemoteKey.Flag.Press=0;
            switch(RemoteKey.Key)
            {
                  case KEY_LOCK:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_UNLOCK:  
                        system_state_change(PreState,NORMAL,1);
                        break;
                  case KEY_FIND:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_QUIET:
                        system_state_change(State,PreState,0);
                  default:break;
            }
      }
}

void alarm_energency(void)
{     
      static Timer16Struct Timer8S=0;
      switch(Energency)
      {
            case PRESS_FIND:
                  if(flash_trun_signal(4000/TIME_BASE,0,1))
                  {
                        flash_trun_signal(0,0,0);
                        system_state_change(State,PreState,1);
                  }
                  if(RemoteKey.Flag.Press)
                  {
      
                        switch(RemoteKey.Key)
                        {
                              case KEY_LOCK:
                                    RemoteKey.Flag.Press=0;
                                    system_state_change(State,PreState,1);
                                    break;
                              case KEY_UNLOCK:  
                                    RemoteKey.Flag.Press=0;
                                    system_state_change(State,PreState,1);
                                    break;
                              case KEY_FIND:
                                    if(RemoteKey.Time.Interval>=600/TIME_BASE)
                                    {
                                          RemoteKey.Flag.Press=0;
                                          Energency=TRUN_FLASH;
                                          flash_trun_signal(0,0,0);
                                          if(speak_act_precoss(0,0,0,RESET));
                                    }                                
                                    break;
                              case KEY_QUIET:
                                    RemoteKey.Flag.Press=0;
                                    system_state_change(State,PreState,1);
                              default:break;
                        }
                  }
                  break;         
            case TRUN_FLASH:
                  if(flash_trun_signal(500/TIME_BASE,500/TIME_BASE,33)); 
                  if(speak_act_precoss(0,0,33000/TIME_BASE/5,LONG))
                  {
                        flash_trun_signal(0,0,0);
                        speak_act_precoss(0,0,0,RESET);
                        Energency=DELAY_8S;
                        Timer8S.Interval=0;
                  }
                  if(RemoteKey.Flag.Press)
                  {
                        RemoteKey.Flag.Press=0;
                        switch(RemoteKey.Key)
                        {
                              case KEY_UNLOCK:
                                    system_state_change(State,PreState,0);
                                    break;
                              default:break;
                        }
                  }
                  break;   
            case DELAY_8S:
                  if(++Timer8S.Interval>=8000/TIME_BASE)
                        Energency=TRUN_FLASH;
                  if(RemoteKey.Flag.Press)
                  {
                        RemoteKey.Flag.Press=0;
                        switch(RemoteKey.Key)
                        {
                              case KEY_UNLOCK:
                                    system_state_change(State,PreState,0);
                                    break;
                              default:break;
                        }
                  }
                  break;
            default:break;
      }
}

void alarm_help(void)
{
      if(flash_trun_signal(500/TIME_BASE,500/TIME_BASE,30)); 
      if(speak_act_precoss(0,0,30000/TIME_BASE/5,LONG));
      if(RemoteKey.Flag.Press)
      {
            RemoteKey.Flag.Press=0;
            switch(RemoteKey.Key)
            {
                  case KEY_LOCK:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_UNLOCK:  
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_FIND:
                        system_state_change(State,PreState,0);
                        break;
                  case KEY_QUIET:
                        system_state_change(State,PreState,0);
                  default:break;
            }
      }
}

void learn_process(ulong Data)
{
      
      static bank2 uchar FlashNoub=0;
      switch(LearnStep)
      {
            case FRIST_DATA:
                  SIGNAL_LED=1;
                  PassWord[0]=get_password(Data);
                  FlashNoub=0;
                  if(KEY_NONE!=get_key(Data))
                        if(RemoteKey.Flag.Press==1)
                        {
                              RemoteKey.Flag.Press=0;
                              LearnStep=FRIST_FLASH;
                        }
                  break;
            case FRIST_FLASH:
                  if(Flag.LearnFlash)
                  {
                        Flag.LearnFlash=0;
                        SIGNAL_LED=!SIGNAL_LED;
                        if(FlashNoub++>=6)
                        {
                              save_ulong(ADDR_ISN0,PassWord[0]);
                              LearnStep=SECOND_DATA;
                        }
                  }
                  break;
            case SECOND_DATA:
                  SIGNAL_LED=1;
                  PassWord[1]=get_password(Data);
                  FlashNoub=0;
                  if(KEY_NONE!=get_key(Data))
                        if(RemoteKey.Flag.Press==1)
                        {
                              RemoteKey.Flag.Press=0;
                              LearnStep=SECOND_FLASH;
                        }
                  
                  break;
            case SECOND_FLASH:
                  
                  if(Flag.LearnFlash)
                  {
                        Flag.LearnFlash=0;
                        SIGNAL_LED=!SIGNAL_LED;
                        if(FlashNoub++>=8)
                        {
                              LearnStep=FRIST_DATA;
                              Flag.Mode=WORK_MODE;
                              save_ulong(ADDR_ISN1,PassWord[1]);
                        }
                  }
                  break;
            default:break;
      }
}

////////////////////////////////////////////////////////
//pre:先前状态                                        //
//Value:转变成的状态                                  //
////////////////////////////////////////////////////////

void system_state_change(StateEnum pre,StateEnum Value,uchar state)
{
      static bank1 StateEnum PrePreState=NORMAL;
      
      if(Value==FIND)   //如果要变成FIND模式,则把上一个状态保存
      {
            PrePreState=PreState;
      }
      
      PreState=pre;
      State=Value;
      
      if(pre==FIND)     //如果从FIND转变过来,则还原上次变成FIND前的状态 即PrePreState
      {
            PreState=PrePreState;
      }
      
      //if(pre==FIND||Value==FIND)//不进行保存
      //{
      //}
      save_uchar(ADDR_STATE,State);
      save_uchar(ADDR_PRESTATE,PreState);
      //Flag.SystemStateChange=1;
      //if(pre==FIND)     Flag.SystemStateChange=0;           //如果上一个状态是FIND的话,不进行第一次进入其他状态处理
      if(state==0)
      {
            Flag.GuardEngineOFF=1;
            Flag.SystemStateChange=0;
      }
      else 
      {
            Flag.GuardEngineOFF=0;
            Flag.SystemStateChange=1;
      }
      speak_act_precoss(0,0,0,RESET);
      flash_trun_signal(0,0,0);
      door_lock_process(0,0);
      frameout_precoss(0);
      
      Flag.DoorOpenedGuard=0;
      //Flag.BeginGuard=0;            //进入警戒状态5s之后开始采集数据 决定是否进行报警
      //clr some register 
      PressUnlock=0;
      ALARM_LED=0;
      
      #ifdef BOOT_EN
      Flag.Boot=0;
      open_boot(0);
      #endif
      
      AlarmSharkTimer.Interval=0;
      SystemGuardChangeFirstTime=1;

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -