找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2993|回复: 1
打印 上一主题 下一主题
收起左侧

新唐单片机无线解码程序

[复制链接]
跳转到指定楼层
楼主
ID:374653 发表于 2018-9-20 15:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
已经量产过的无线解码程序,新唐单片机

单片机源程序如下:
  1. #include "N76E003.h"
  2. #include "Main.h"
  3. #include "Definition.h"
  4. #include "menu.h"
  5. #include "Buzzer.h"
  6. #include "Function_define.h"
  7. #include "SFR_Macro.h"
  8. #include "receive.h"
  9. #include "flash_eeprom.h"

  10. void MCU_IO_Port_init(void);
  11. void Timer0Initial(void);
  12. void Timer1Initial(void);
  13. void CheckInPut(void);
  14. void Check_KeyCode(void);

  15. extern bit BIT_TMP;
  16. G_TIME_RAM g_Time_ram;
  17. G_SYSTEM_RAM g_System_ram;
  18. struct Work_Register WRC;

  19. INT8U idata powerOnBti;
  20. INT8U enableBit;
  21. /*
  22. INT8U read_APROM_BYTE_(INT16U code *u16_addr)
  23. {
  24.         INT8U rdata;
  25.         rdata = *u16_addr>>8;
  26.         return rdata;
  27. }
  28. */

  29. void MCU_IO_Port_init(void)
  30. {
  31.         P00_Input_Mode;
  32.         P02_Quasi_Mode;
  33.         P03_Input_Mode;
  34.         P10_Input_Mode;
  35.         P11_Input_Mode;
  36.         P12_Input_Mode;
  37.         P13_Input_Mode;
  38.         P14_Input_Mode;
  39.         P15_Input_Mode;

  40.     P01_PushPull_Mode;
  41.         P04_PushPull_Mode;
  42.         P05_PushPull_Mode;
  43.         P06_PushPull_Mode;
  44.         P07_PushPull_Mode;
  45.         P17_PushPull_Mode;
  46.         P30_PushPull_Mode;


  47.         P_LampOut = IO_OFF;
  48.         P_MidLockOut = IO_OFF;
  49.         P_MidOpenOut = IO_OFF;
  50.         P_LedOut = IO_OFF;
  51.         P_BUZZER_OUT = IO_OFF;
  52.         P_TrunkOut = IO_OFF;
  53.         P_EngineOffOut = IO_OFF;       
  54.        
  55. }
  56. /************************************************************************************************************
  57. *    Main function
  58. ************************************************************************************************************/
  59. void main (void)
  60. {
  61.     static INT8U SysStatusTemp = 0;
  62.     static INT8U MidLockBit = 0,MidUnLockBit = 0;
  63.    
  64.         TMOD = 0XFF;
  65.         clr_T0M;
  66.         clr_T1M;
  67.         set_EA;  
  68.                
  69.     MCU_IO_Port_init();
  70.     Timer0Initial();// 100us
  71.     Timer1Initial();// 1ms

  72.     ////////////////////////////上电读取eeprom的数据///////////////
  73.     UserReadData();
  74.    
  75.     if (g_System_ram.SysStatus == SYS_DISARMMODE)
  76.     {
  77.         WRC.SecondRelockBit = 1;
  78.         p_MenuMode = DisarmMode;
  79.         g_System_ram.Initial = TRUE;
  80.         P_EngineOffOut = FALSE;
  81.         P_LedOut = FALSE;
  82.     }
  83.     else if ((g_System_ram.SysStatus == SYS_ARMMODE)||(g_System_ram.SysStatus == SYS_AnitHiJack))
  84.     {
  85.         p_MenuMode = ArmMode;
  86.         g_System_ram.Initial = TRUE;
  87.         WRC.MidStatusBit = 1;
  88.         enableBit = 1;
  89.     }
  90.     else
  91.     {
  92.         p_MenuMode = powerOn;
  93.         g_System_ram.Initial = FALSE;
  94.     }
  95.    
  96.     powerOnBti = TRUE;
  97.     WRC.Save_LockTypeBit = 1;
  98.     WRC.Save_BrakeBit = 1;
  99.     WRC.Save_ShockBit = 1;
  100.    
  101.         if (!P_ResetIn)
  102.     {
  103.         p_MenuMode = TestMode;
  104.         g_System_ram.Initial = FALSE;
  105.     }

  106.     if (P_Jump1)
  107.     {
  108.         WRC.Jump1InBit = 1;
  109.     }
  110.     else
  111.     {
  112.         WRC.Jump1InBit = 0;
  113.     }
  114.         ///////////////////////////////////////////////////////////////////////////
  115.         while (1)
  116.         {
  117.             CheckInPut();
  118.             Check_KeyCode();
  119.             
  120.         if (!WRC.Jump1InBit)//插上跳线时,取消自动设防功能
  121.         {
  122.             WRC.AutoRelock = 0;
  123.         }
  124.         if ((!P_EngineOffOut)&&(p_MenuMode != ArmMode)&&(p_MenuMode != TestLockMode)
  125.             &&(p_MenuMode != TestMode))
  126.         {
  127.                 if (WRC.ManualLock)
  128.                 {
  129.                     if (!MidLockBit)
  130.                     {
  131.                     g_Time_ram.TimeForEleLock_100ms = 0;
  132.                     g_Time_ram.TimeForAirLock_100ms = 0;
  133.                     P_MidLockOut = TRUE;
  134.                     P_MidOpenOut = FALSE;
  135.                     WRC.MidStatusBit = 1;
  136.                     MidLockBit = 1;
  137.                     enableBit = 0;
  138.                 }
  139.                 }
  140.                 else
  141.                 {
  142.                 MidLockBit = 0;
  143.                 }
  144.                 if (WRC.ManualUnLock)
  145.                 {
  146.                     if (!MidUnLockBit)
  147.                     {
  148.                     g_Time_ram.TimeForEleLock_100ms = 0;
  149.                     g_Time_ram.TimeForAirLock_100ms = 0;
  150.                     P_MidOpenOut = TRUE;
  151.                     P_MidLockOut = FALSE;
  152.                     WRC.MidStatusBit = 0;
  153.                     MidUnLockBit = 1;
  154.                 }
  155.                 }
  156.                 else
  157.                 {
  158.                 MidUnLockBit = 0;
  159.                 }
  160.             }
  161.             /////////////////////////////////////////////////////////////////////////
  162.             if ((WRC.AccInBit)&&(!WRC.DoorInBit_N))
  163.             {
  164.                 if (WRC.RestInHiGoingEdgeBit)//紧急解除
  165.             {
  166.                 if ((p_MenuMode == AlarmMode)||(p_MenuMode == AlarmForShockMode)
  167.                 ||(p_MenuMode == ArmMode))
  168.                 {
  169.                     P_EngineOffOut = FALSE;
  170.                     P_LedOut = FALSE;
  171.                     g_Time_ram.CheckResetInTime = 0;
  172.                     p_MenuMode = DisarmMode;
  173.                     WRC.AccInLowGoingEdgeBit = 0;
  174.                     g_System_ram.Initial = FALSE;
  175.                     WRC.RestInHiGoingEdgeBit = 0;
  176.                     WRC.TriggerCount++;
  177.                     
  178.                     if (!WRC.SilenceBit)
  179.                     {
  180.                         Buzzer_Bz_Bz();
  181.                     }
  182.                 }
  183.             }
  184.         }
  185.         /////////////////////////////////////////////////////////////////////////
  186.         ///////////////////写码开始//////////////////////////////////////////////
  187.             if ((WRC.AccInBit)&&(WRC.DoorInBit_N))
  188.             {
  189.             if (WRC.RestBit)
  190.             {
  191.                 if (g_Time_ram.TimeForWriteCode_100ms >= 50)
  192.                 {
  193.                     if ((p_MenuMode != LearnCodeMode)&&(p_MenuMode != AlarmMode)
  194.                     &&(p_MenuMode != ArmMode)&&(p_MenuMode != TestLockMode)
  195.                     &&(p_MenuMode != PanicMode))
  196.                     {
  197.                         p_MenuMode = LearnCodeMode;
  198.                         g_System_ram.Initial = FALSE;
  199.                         WRC.ClearCodeBit = 1;
  200.                         P_LampOut = TRUE;
  201.                         P_LedOut = TRUE;
  202.                     }
  203.                 }
  204.             }
  205.             else
  206.             {
  207.                 g_Time_ram.TimeForWriteCode_100ms = 0;
  208.             }
  209.             }
  210.             else
  211.         {
  212.             g_Time_ram.TimeForWriteCode_100ms = 0;
  213.         }
  214.             /////////////////////写码结束////////////////////////////////////////////
  215.             p_MenuMode();  /////////主菜单/////////
  216.             /////////////////////中控锁的断开输出////////////////////////////////////
  217.             if ((p_MenuMode != TestUnLockMode)&&(p_MenuMode != TestLockMode))
  218.             {
  219.                 if(WRC.Save_LockTypeBit)
  220.                 {
  221.                 if (g_Time_ram.TimeForEleLock_100ms >= 5)//电锁输出 0.5s
  222.                 {
  223.                     P_MidLockOut = FALSE;
  224.                     P_MidOpenOut = FALSE;
  225.                 }
  226.             }
  227.             else
  228.             {
  229.                 if (g_Time_ram.TimeForAirLock_100ms >= 40)
  230.                 {
  231.                     P_MidLockOut = FALSE;
  232.                     P_MidOpenOut = FALSE;
  233.                 }
  234.             }
  235.         }
  236.         /////////////////////////////////////////////////////////////////////////
  237.         /////////////////////行李箱开启开始//////////////////////////////////////
  238.         if ((WRC.KeyCode == REWORD12_L)||(WRC.KeyCode == REWORD4_L))
  239.         {
  240.             g_Time_ram.TimeForTrunk_100ms = 0;
  241.             P_TrunkOut = IO_ON;
  242.         }
  243.         if (g_Time_ram.TimeForTrunk_100ms >= 8)
  244.         {
  245.             P_TrunkOut = IO_OFF;
  246.         }
  247.         //////////////////////行李箱开启结束////////////////////////////////////
  248.         
  249.         //////////////////////掉电存储状态//////////////////////////////////////
  250.         if (SysStatusTemp != g_System_ram.SysStatus) //当状态发生变化的时候再去启动存储功能
  251.         {
  252.             WriteBuffer[13] = g_System_ram.SysStatus;
  253.             WriteBuffer[12] =  WRC.SilenceBit;

  254.             if (g_Time_ram.TimeForOutage_100ms >= 15)//动作完再存储
  255.             {
  256.                 if (UserWriteData()== TRUE)
  257.                 {
  258.                     UserReadData();
  259.                     SysStatusTemp = g_System_ram.SysStatus;
  260.                 }
  261.             }
  262.         }
  263.         else
  264.         {
  265.             g_Time_ram.TimeForOutage_100ms = 0;
  266.         }
  267.         /////////////////////////////////////////////////////////////////////////
  268.         if ((p_MenuMode == IdleMode)||(p_MenuMode == DisarmMode)
  269.             ||(p_MenuMode == DoorOpenMode))//关闭LED常亮3秒,报警提示状态
  270.         {
  271.             if (g_Time_ram.TimeForLEDoff_100ms >= 30)
  272.             {
  273.                 P_LedOut = FALSE;
  274.             }
  275.         }
  276.         /////////////////////////////////////////////////////////////////////////
  277.         if (WRC.KeyCode != REWORD4)
  278.         {
  279.             WRC.KeyCode = FALSE;
  280.         }
  281.         }
  282. }


  283. void CheckInPut(void)
  284. {
  285.     ///////////////////////////////////////////////////////////////
  286.         if ((P_AccIn)&&(g_Time_ram.CheckAccOnPasitiveTime >= 2))
  287.     {
  288.         WRC.AccInBit = 1;
  289.     }
  290.     else
  291.     {
  292.         if (!P_AccIn)
  293.         {
  294.             g_Time_ram.CheckAccOnPasitiveTime = 0;
  295.             WRC.AccInBit = 0;
  296.         }
  297.     }
  298.     //////////////////ACC边沿信号检测//////////////////////////////
  299.     if (P_AccIn)
  300.     {
  301.         if (WRC.AccInStatusTemp)
  302.         {
  303.             if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)
  304.                 &&(p_MenuMode != ArmMode)&&(WRC.DoorInBit_N))
  305.             {
  306.                 WRC.TriggerCount++;
  307.             }
  308.             WRC.AccInStatusTemp = FALSE;
  309.             WRC.AccInHiGoingEdgeBit = 1;
  310.             powerOnBti = FALSE;
  311.         }
  312.     }
  313.     else
  314.     {
  315.         if (!WRC.AccInStatusTemp)
  316.         {
  317.             WRC.AccInStatusTemp = TRUE;
  318.             
  319.             if (!powerOnBti)
  320.             {
  321.                 WRC.AccInLowGoingEdgeBit = 1;
  322.             }
  323.             
  324.             /*if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)
  325.                 &&(p_MenuMode != ArmMode)&&(WRC.DoorInBit_N))
  326.             {
  327.                 WRC.TriggerCount++;
  328.             }*/
  329.         }
  330.     }
  331.    
  332.     /////////////////////////////////////////////////////////////
  333.     //////////////////边门负检测///////////////////////////////
  334.     if ((!P_DoorIn_N)&&(g_Time_ram.CheckDoorNagetiveTime >= 2))
  335.     {
  336.         WRC.DoorInBit_N = 0;
  337.     }
  338.     else
  339.     {
  340.         if (P_DoorIn_N)
  341.         {
  342.             g_Time_ram.CheckDoorNagetiveTime = 0;
  343.             WRC.DoorInBit_N = 1;
  344.         }
  345.     }
  346.     ///////////////边门边沿信号检测///////////////////////////
  347.     if (!P_DoorIn_N)
  348.     {
  349.         if (WRC.DoorInStatus)
  350.         {
  351.             if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)&&(p_MenuMode != ArmMode))
  352.             {
  353.                 WRC.TriggerCount++;
  354.             }
  355.             WRC.DoorInStatus = FALSE;
  356.             WRC.DoorInHiGoingEdgeBit = 1;
  357.         }
  358.     }
  359.     else
  360.     {
  361.         if (!WRC.DoorInStatus)
  362.         {
  363.             WRC.DoorInStatus = TRUE;
  364.             WRC.DoorInLowGoingEdgeBit = 1;
  365.             /*if ((p_MenuMode != AlarmMode)&&(p_MenuMode != AlarmForShockMode)&&(p_MenuMode != ArmMode))
  366.             {
  367.                 WRC.TriggerCount++;
  368.             }*/
  369.         }
  370.     }
  371.     /////////////////////////////////////////////////////////////
  372.     /////////////////////////////////////////////////////////////
  373.     if ((P_BrakeIn)&&(g_Time_ram.CheckBrakeTime >= 2))
  374.     {   
  375.         WRC.BrakeInBit = 1;
  376.     }
  377.     else
  378.     {
  379.         if (!P_BrakeIn)
  380.         {
  381.             g_Time_ram.CheckBrakeTime = 0;
  382.             WRC.BrakeInBit = 0;
  383.         }
  384.     }
  385.     //////////////////脚刹边沿信号检测//////////////////////////////
  386.     if (P_BrakeIn)
  387.     {
  388.         if (WRC.BrakeInStatusTemp)
  389.         {
  390.             WRC.BrakeInStatusTemp = FALSE;
  391.             WRC.BrakeInHiGoingEdgeBit = 1;
  392.         }
  393.     }
  394.     else
  395.     {
  396.         if (!WRC.BrakeInStatusTemp)
  397.         {
  398.             WRC.BrakeInStatusTemp = TRUE;
  399.             WRC.BrakeInLowGoingEdgeBit = 1;
  400.         }
  401.     }
  402.     /////////////////////////////////////////////////////////////
  403.     /////////////////////////////////////////////////////////////
  404.     if ((!P_ShockIn)&&(g_Time_ram.CheckShockInTime >= 10))
  405.     {
  406.         WRC.ShockSensorBit = 1;
  407.         g_Time_ram.CheckShockInTimeTemp = 0;
  408.     }
  409.     else
  410.     {
  411.         if ((P_ShockIn)&&(g_Time_ram.CheckShockInTimeTemp >= 20))
  412.         {
  413.             g_Time_ram.CheckShockInTime = 0;
  414.             WRC.ShockSensorBit = 0;
  415.         }
  416.     }
  417.     /////////////////////////////////////////////////////////////
  418.     ////////////////////////////////////////////////////////////
  419.     if ((!P_ResetIn)&&(g_Time_ram.CheckResetInTime >= 1))
  420.     {
  421.         WRC.RestBit = 1;
  422.     }
  423.     else
  424.     {
  425.         if (P_ResetIn)
  426.         {
  427.             g_Time_ram.CheckResetInTime = 0;
  428.             WRC.RestBit = 0;
  429.         }
  430.     }
  431.     if (WRC.RestBit)
  432.     {
  433.         if (WRC.RestInStatus)
  434.         {
  435.             WRC.RestInStatus = FALSE;
  436.             WRC.RestInHiGoingEdgeBit = 1;
  437.         }
  438.     }
  439.     else
  440.     {
  441.         if (!WRC.RestInStatus)
  442.         {
  443.             WRC.RestInStatus = TRUE;
  444.             WRC.RestInHiGoingEdgeBit = 0;
  445.         }
  446.     }
  447.     ///////////////////////////////////////////////////////
  448.     if ((!P_ManualLockIn)&&(g_Time_ram.ManualLockTime >= 2))
  449.     {   
  450.         WRC.ManualLock = 1;
  451.     }
  452.     else
  453.     {
  454.         if (P_ManualLockIn)
  455.         {
  456.             g_Time_ram.ManualLockTime = 0;
  457.             WRC.ManualLock = 0;
  458.         }
  459.     }
  460.     if ((!P_ManualUnLockIn)&&(g_Time_ram.ManualUnLockTime >= 2))
  461.     {   
  462.         WRC.ManualUnLock = 1;
  463.     }
  464.     else
  465.     {
  466.         if (P_ManualUnLockIn)
  467.         {
  468.             g_Time_ram.ManualUnLockTime = 0;
  469.             WRC.ManualUnLock = 0;
  470.         }
  471.     }
  472.     //////////////////////////////////////////////////////////////////
  473. }

  474. void Check_KeyCode(void)
  475. {
  476.     static INT8U keyBit = 0;
  477.    
  478.     if (ReceiveBuffer[2] != 0)
  479.     {
  480.         if (WRC.K_OldKeyCode == ReceiveBuffer[2])
  481.         {
  482.             if (ReceiveBuffer[2] != REWORD4)
  483.             {
  484.                             if (g_Time_ram.TimeForContinueKey_100ms >= 15)                                       
  485.                             {
  486.                                     g_Time_ram.TimeForContinueKey_100ms = 0;
  487.                                    
  488.                     if (!keyBit)
  489.                     {
  490.                         keyBit = 1;
  491.                         WRC.KeyCode = ReceiveBuffer[2]|0x30;
  492.                     }
  493.                         }
  494.                     }
  495.                     else
  496.                     {
  497.                 if (g_Time_ram.TimeForContinueKey_100ms >= 20)                                       
  498.                             {
  499.                                     g_Time_ram.TimeForContinueKey_100ms = 0;
  500.                                    
  501.                     if (!keyBit)
  502.                     {
  503.                         keyBit = 1;
  504.                         WRC.KeyCode = ReceiveBuffer[2]|0x30;
  505.                     }
  506.                         }
  507.                         
  508.                         g_Time_ram.TimeForContinueKey_10ms = 0;
  509.                     }
  510.                 }
  511.             else
  512.             {
  513.             if (((ReadBuffer[0] == ReceiveBuffer[0])&&(ReadBuffer[1] == ReceiveBuffer[1])&&(ReadBuffer[2] == ReceiveThirdData))
  514.                 ||((ReadBuffer[3] == ReceiveBuffer[0])&&(ReadBuffer[4] == ReceiveBuffer[1])&&(ReadBuffer[5] == ReceiveThirdData))
  515.                 ||((ReadBuffer[6] == ReceiveBuffer[0])&&(ReadBuffer[7] == ReceiveBuffer[1])&&(ReadBuffer[8] == ReceiveThirdData))
  516.                 ||((ReadBuffer[9] == ReceiveBuffer[0])&&(ReadBuffer[10] == ReceiveBuffer[1])&&(ReadBuffer[11] == ReceiveThirdData))
  517.                 ||(WRC.WriteCodeBit))
  518.             {
  519.                 WRC.KeyCode = ReceiveBuffer[2];     
  520.                 WRC.K_OldKeyCode = ReceiveBuffer[2];  
  521.                 g_Time_ram.TimeForContinueKey_100ms = 0;
  522.                 g_Time_ram.TimeForContinueKey_10ms = 0;
  523.                 keyBit = 0;
  524.             }   
  525.             }
  526.     }
  527.     else
  528.     {
  529.         WRC.K_OldKeyCode = 0;
  530.         g_Time_ram.TimeForContinueKey_100ms = 0;
  531.     }
  532. }
复制代码

所有资料51hei提供下载:
无线解码程序.zip (431.34 KB, 下载次数: 37)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2018-9-20 17:34 | 只看该作者
补全原理图或者详细说明一下电路连接即可获得100+黑币
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表