背景图片
可控硅数波方式程序 - 啊和的博客

可控硅数波方式程序 - 啊和的博客 可控硅数波方式程序 - 啊和的博客

可控硅数波方式程序

  1. #include <cms.h>
  2. #include "io.h"
  3. #include "function.h"
  4.  
  5. bit FLAG_1MS;
  6.  
  7.  
  8. /*******************发送通讯变量*****************************/
  9. unsigned char  Tx_Step;
  10. unsigned char  Start_Count;
  11. bit            Send_One_Bit_Over;
  12. unsigned char  Tx_Low_Count,Tx_High_Count,Send_Count;
  13. bit            Start_Send;
  14. unsigned char  Tx_Data1;
  15. /*******************发送通讯变量*****************************/
  16.  
  17.  
  18. /****************接收板通讯变量**********************/
  19. bit Rx_Read_Once,Rx_Read_Now,Rx_Change,Rx_Dat_Bit,Rx_Dat_Bit1,Rx_Flag;
  20. unsigned char  Rx_Step,Rx_Start_Count,Rx_Start_Count1,RX_Dat_Low_Count,RX_Dat_High_Count,RX_Count;
  21. unsigned char  RX_Dat1,RX_Dat;
  22. /*************************************************************/
  23.  
  24.  
  25. /**************************/
  26. bit       FLAG_ZERO_CHECK;
  27. bit       FLAG_LAST_ZERO_STATE;
  28. bit       FLAG_ZERO_CHANGE;
  29. bit       SCR_OPEN_ONCE;
  30.  
  31. bit       FLAG_QIAN_HEAT_ON;
  32. bit       FLAG_HOU_HEAT_ON;
  33. bit       FLAG_ZUO_HEAT_ON;
  34. bit       FLAG_YOU_HEAT_ON;
  35. bit       FLAG_BAONUAN_HEAT_ON;
  36.  
  37.  
  38. unsigned char OPEN_SCR_DELAY;
  39. unsigned char SCR_OPEN_ONCE_DELAY;
  40.  
  41. unsigned char QIAN_OPEN_GEAR;   //前可控硅开的档位
  42. unsigned char HOU_OPEN_GEAR;   //后可控硅开的档位
  43. unsigned char ZUO_OPEN_GEAR;   //左可控硅开的档位
  44. unsigned char YOU_OPEN_GEAR;   //右可控硅开的档位
  45. unsigned char BAONUAN_OPEN_GEAR;
  46.  
  47.  
  48. unsigned char QIAN_OPEN_GEAR1;   //前可控硅开的档位
  49. unsigned char HOU_OPEN_GEAR1;   //后可控硅开的档位
  50. unsigned char ZUO_OPEN_GEAR1;   //左可控硅开的档位
  51. unsigned char YOU_OPEN_GEAR1;   //右可控硅开的档位
  52. unsigned char BAONUAN_OPEN_GEAR1;
  53.  
  54.  
  55. bit   FLAG_QIAN_OPEN_SCR;
  56. unsigned char QIAN_OPEN_SCR_DELAY,QIAN_OPEN_2CI_COUNT,QIAN_REC_TIME,QIAN_OPEN_SCR_ZERO_DELAY;
  57.  
  58. bit   FLAG_HOU_OPEN_SCR;
  59. unsigned char HOU_OPEN_SCR_DELAY,HOU_OPEN_2CI_COUNT,HOU_REC_TIME,HOU_OPEN_SCR_ZERO_DELAY;
  60.  
  61. bit   FLAG_ZUO_OPEN_SCR;
  62. unsigned char ZUO_OPEN_SCR_DELAY,ZUO_OPEN_2CI_COUNT,ZUO_REC_TIME,ZUO_OPEN_SCR_ZERO_DELAY;
  63.  
  64. bit   FLAG_YOU_OPEN_SCR;
  65. unsigned char YOU_OPEN_SCR_DELAY,YOU_OPEN_2CI_COUNT,YOU_REC_TIME,YOU_OPEN_SCR_ZERO_DELAY;
  66.  
  67. bit   FLAG_BAONUAN_OPEN_SCR;
  68. unsigned char BAONUAN_OPEN_SCR_DELAY,BAONUAN_OPEN_2CI_COUNT,BAONUAN_REC_TIME,BAONUAN_OPEN_SCR_ZERO_DELAY;
  69.  
  70.  
  71.  
  72. bit          FLAG_QIAN_ZERO_COME;
  73. bit          FLAG_HOU_ZERO_COME;
  74. bit          FLAG_ZUO_ZERO_COME;
  75. bit          FLAG_YOU_ZERO_COME;
  76.  
  77. bit          FLAG_BAONUAN_ZERO_COME;
  78.  
  79.  
  80. /**************************/
  81.  
  82.  
  83.  
  84. bit        FLAG_QIAN_SCR_ON,FLAG_HOU_SCR_ON,FLAG_ZUO_SCR_ON,FLAG_YOU_SCR_ON,FLAG_BAONUAN_SCR_ON;
  85.  
  86. unsigned char QIAN_SCR_ON_1MS_DELAY,HOU_SCR_ON_1MS_DELAY,ZUO_SCR_ON_1MS_DELAY,YOU_SCR_ON_1MS_DELAY,BAONUAN_SCR_ON_1MS_DELAY;
  87.  
  88. void IO_INIT()
  89. {
  90.  
  91.   TRISC0=0;
  92.   TRISC1=0;
  93.  
  94.   TRISB0=0;
  95.   TRISB1=0;
  96.   TRISB2=0;
  97.   TRISB3=0;
  98.   TRISB4=0;
  99.  
  100.   TRISA4=0;
  101.   TRISA3=0;
  102.  
  103.   TRISA0=0;
  104.   TRISA1=0;
  105.   TRISA2=0;
  106.   TRISA5=1;
  107.  
  108.  
  109.  
  110.  
  111.  
  112. }
  113.  
  114.  
  115. void TIMER_INIT()
  116. {
  117.   PIE2 = 0;
  118.   PIE1 = 0B00000010;
  119.   PR2 = 250; //8M下将TMR2设置为125us中断
  120.   T2CON = 4; //使能定时器2
  121.   INTCON = 0XC0; //使能中断
  122. }
  123.  
  124. void DEAL_RX_DATA()
  125. {
  126.  
  127.  
  128.   if(Rx_Flag)
  129.   {
  130.     Rx_Flag=0;
  131.     if(RX_Dat&0x01)
  132.     {
  133.  
  134.     } else
  135.     {
  136.  
  137.     }
  138.  
  139.  
  140.  
  141.  
  142.     if(RX_Dat&0x02)
  143.     {
  144.  
  145.     } else
  146.     {
  147.  
  148.     }
  149.  
  150.  
  151.  
  152.   }
  153.  
  154.   FLAG_QIAN_HEAT_ON=1;
  155.   FLAG_HOU_HEAT_ON=1;
  156.   FLAG_ZUO_HEAT_ON=1;
  157.   FLAG_YOU_HEAT_ON=1;
  158.   FLAG_BAONUAN_HEAT_ON=1;
  159.  
  160.   QIAN_OPEN_GEAR=10;     //2的倍数
  161.   HOU_OPEN_GEAR=10;
  162.   ZUO_OPEN_GEAR=10;
  163.   YOU_OPEN_GEAR=10;
  164.   BAONUAN_OPEN_GEAR=10;
  165.  
  166.   COOKING_SCR_IO=1;
  167. }
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. void interrupt time0(void)
  180. {
  181.  
  182.   static unsigned char _1MS_DELAY;
  183.   if(TMR2IF)
  184.   {
  185.     TMR2IF = 0;
  186.  
  187.  
  188.  
  189.     _1MS_DELAY++;
  190.     if(_1MS_DELAY>=8)
  191.     {
  192.       _1MS_DELAY=0;
  193.       FLAG_1MS=1;
  194.     }
  195.  
  196.  
  197.  
  198.     if(FLAG_QIAN_SCR_ON)
  199.     {
  200.       QIAN_SCR_IO=0;
  201.       QIAN_SCR_ON_1MS_DELAY++;
  202.       if(QIAN_SCR_ON_1MS_DELAY>=12)
  203.       {
  204.         QIAN_SCR_ON_1MS_DELAY=0;
  205.         QIAN_SCR_IO=1;
  206.         FLAG_QIAN_SCR_ON=0;
  207.       }
  208.     } else
  209.     {
  210.       QIAN_SCR_ON_1MS_DELAY=0;
  211.       QIAN_SCR_IO=1;
  212.     }
  213.  
  214.  
  215.     if(FLAG_HOU_SCR_ON)
  216.     {
  217.       HOU_SCR_IO=0;
  218.       HOU_SCR_ON_1MS_DELAY++;
  219.       if(HOU_SCR_ON_1MS_DELAY>=12)
  220.       {
  221.         HOU_SCR_ON_1MS_DELAY=0;
  222.         HOU_SCR_IO=1;
  223.         FLAG_HOU_SCR_ON=0;
  224.       }
  225.     } else
  226.     {
  227.       HOU_SCR_ON_1MS_DELAY=0;
  228.       HOU_SCR_IO=1;
  229.     }
  230.  
  231.  
  232.     if(FLAG_ZUO_SCR_ON)
  233.     {
  234.       ZUO_SCR_IO=0;
  235.       ZUO_SCR_ON_1MS_DELAY++;
  236.       if(ZUO_SCR_ON_1MS_DELAY>=12)
  237.       {
  238.         ZUO_SCR_ON_1MS_DELAY=0;
  239.         ZUO_SCR_IO=1;
  240.         FLAG_ZUO_SCR_ON=0;
  241.       }
  242.     } else
  243.     {
  244.       ZUO_SCR_ON_1MS_DELAY=0;
  245.       ZUO_SCR_IO=1;
  246.     }
  247.  
  248.     if(FLAG_YOU_SCR_ON)
  249.     {
  250.       YOU_SCR_IO=0;
  251.       YOU_SCR_ON_1MS_DELAY++;
  252.       if(YOU_SCR_ON_1MS_DELAY>=12)
  253.       {
  254.         YOU_SCR_ON_1MS_DELAY=0;
  255.         YOU_SCR_IO=1;
  256.         FLAG_YOU_SCR_ON=0;
  257.       }
  258.     } else
  259.     {
  260.       YOU_SCR_ON_1MS_DELAY=0;
  261.       YOU_SCR_IO=1;
  262.     }
  263.  
  264.     if(FLAG_BAONUAN_SCR_ON)
  265.     {
  266.       BAONUAN_SCR_IO=0;
  267.       BAONUAN_SCR_ON_1MS_DELAY++;
  268.       if(BAONUAN_SCR_ON_1MS_DELAY>=12)
  269.       {
  270.         BAONUAN_SCR_ON_1MS_DELAY=0;
  271.         BAONUAN_SCR_IO=1;
  272.         FLAG_BAONUAN_SCR_ON=0;
  273.       }
  274.     } else
  275.     {
  276.       BAONUAN_SCR_ON_1MS_DELAY=0;
  277.       BAONUAN_SCR_IO=1;
  278.     }
  279.  
  280.  
  281.  
  282.     /**********************读过零信号******************************/
  283.     if(!FLAG_ZERO_CHECK)
  284.     {
  285.       FLAG_ZERO_CHECK=1;
  286.       FLAG_LAST_ZERO_STATE=(unsigned char)ZERO_IO;
  287.     }
  288.     if(FLAG_ZERO_CHECK)
  289.     {
  290.       if(FLAG_LAST_ZERO_STATE!=ZERO_IO)  //过零来了
  291.       {
  292.         FLAG_ZERO_CHECK=0;
  293.         FLAG_QIAN_ZERO_COME=1;
  294.         FLAG_HOU_ZERO_COME=1;
  295.         FLAG_ZUO_ZERO_COME=1;
  296.         FLAG_YOU_ZERO_COME=1;
  297.         FLAG_BAONUAN_ZERO_COME=1;
  298.       }
  299.     }
  300.     /**********************读过零信号******************************/
  301.  
  302.  
  303.  
  304.  
  305.     /**********************前可控硅驱动*********************/
  306.  
  307.  
  308.  
  309.  
  310.     if(FLAG_QIAN_HEAT_ON) //工作标志位
  311.     {
  312.  
  313.       if(FLAG_QIAN_ZERO_COME)
  314.       {
  315.         FLAG_QIAN_ZERO_COME=0;
  316.         QIAN_OPEN_SCR_ZERO_DELAY=0;
  317.  
  318.         QIAN_OPEN_GEAR1=QIAN_OPEN_GEAR;
  319.         if(QIAN_OPEN_GEAR1<=2)      QIAN_OPEN_GEAR1=2;
  320.         if(QIAN_OPEN_GEAR1>=10)      QIAN_OPEN_GEAR1=10;
  321.  
  322.         if(QIAN_OPEN_GEAR1==10)
  323.         {
  324.           FLAG_QIAN_OPEN_SCR=1;
  325.         } else
  326.         {
  327.           QIAN_OPEN_2CI_COUNT++;
  328.  
  329.           if(QIAN_OPEN_2CI_COUNT<=QIAN_OPEN_GEAR1)
  330.           {
  331.             FLAG_QIAN_OPEN_SCR=1;
  332.           }
  333.           if(QIAN_OPEN_2CI_COUNT==1)
  334.           {
  335.             QIAN_REC_TIME=0;
  336.           } else
  337.           {
  338.             QIAN_REC_TIME=2;
  339.           }
  340.  
  341.           if(QIAN_OPEN_2CI_COUNT>=10) QIAN_OPEN_2CI_COUNT=0;  //最大开10个周期
  342.  
  343.         }
  344.  
  345.       }
  346.  
  347.       if(FLAG_QIAN_OPEN_SCR)
  348.       {
  349.  
  350.         QIAN_OPEN_SCR_ZERO_DELAY++;
  351.         if(QIAN_OPEN_SCR_ZERO_DELAY>=77-QIAN_REC_TIME) //78
  352.         {
  353.           QIAN_OPEN_SCR_ZERO_DELAY=0;
  354.           FLAG_QIAN_SCR_ON=1;
  355.           FLAG_QIAN_OPEN_SCR=0;
  356.  
  357.         }
  358.       }
  359.     } else
  360.     {
  361.       QIAN_OPEN_SCR_ZERO_DELAY=0;
  362.       QIAN_REC_TIME=0;
  363.       FLAG_QIAN_OPEN_SCR=0;
  364.       FLAG_QIAN_ZERO_COME=0;
  365.       FLAG_QIAN_SCR_ON=0;
  366.     }
  367.     /**********************可控硅驱动END******************************/
  368.  
  369.  
  370.     if(FLAG_HOU_HEAT_ON) //工作标志位
  371.     {
  372.       if(FLAG_HOU_ZERO_COME)
  373.       {
  374.         FLAG_HOU_ZERO_COME=0;
  375.         HOU_OPEN_SCR_ZERO_DELAY=0;
  376.  
  377.         HOU_OPEN_GEAR1=HOU_OPEN_GEAR;
  378.         if(HOU_OPEN_GEAR1<=2)      HOU_OPEN_GEAR1=2;
  379.         if(HOU_OPEN_GEAR1>=10)     HOU_OPEN_GEAR1=10;
  380.  
  381.         if(HOU_OPEN_GEAR1==10)
  382.         {
  383.           FLAG_HOU_OPEN_SCR=1;
  384.         } else
  385.         {
  386.           HOU_OPEN_2CI_COUNT++;
  387.  
  388.           if(HOU_OPEN_2CI_COUNT<=HOU_OPEN_GEAR1)
  389.           {
  390.             FLAG_HOU_OPEN_SCR=1;
  391.           }
  392.           if(HOU_OPEN_2CI_COUNT==1)
  393.           {
  394.             HOU_REC_TIME=0;
  395.           } else
  396.           {
  397.             HOU_REC_TIME=2;
  398.           }
  399.  
  400.           if(HOU_OPEN_2CI_COUNT>=10) HOU_OPEN_2CI_COUNT=0;  //最大开10个周期
  401.  
  402.         }
  403.  
  404.       }
  405.  
  406.       if(FLAG_HOU_OPEN_SCR)
  407.       {
  408.  
  409.         HOU_OPEN_SCR_ZERO_DELAY++;
  410.         if(HOU_OPEN_SCR_ZERO_DELAY>=77-HOU_REC_TIME) //78
  411.         {
  412.           HOU_OPEN_SCR_ZERO_DELAY=0;
  413.           FLAG_HOU_SCR_ON=1;
  414.           FLAG_HOU_OPEN_SCR=0;
  415.  
  416.         }
  417.       }
  418.  
  419.  
  420.  
  421.     } else
  422.     {
  423.       HOU_OPEN_SCR_ZERO_DELAY=0;
  424.       HOU_REC_TIME=0;
  425.       FLAG_HOU_OPEN_SCR=0;
  426.       FLAG_HOU_ZERO_COME=0;
  427.       FLAG_HOU_SCR_ON=0;
  428.     }
  429.  
  430.  
  431.     if(FLAG_ZUO_HEAT_ON) //工作标志位
  432.     {
  433.       if(FLAG_ZUO_ZERO_COME)
  434.       {
  435.         FLAG_ZUO_ZERO_COME=0;
  436.         ZUO_OPEN_SCR_ZERO_DELAY=0;
  437.  
  438.         ZUO_OPEN_GEAR1=ZUO_OPEN_GEAR;
  439.         if(ZUO_OPEN_GEAR1<=2)      ZUO_OPEN_GEAR1=2;
  440.         if(ZUO_OPEN_GEAR1>=10)     ZUO_OPEN_GEAR1=10;
  441.  
  442.         if(ZUO_OPEN_GEAR1==10)
  443.         {
  444.           FLAG_ZUO_OPEN_SCR=1;
  445.         } else
  446.         {
  447.           ZUO_OPEN_2CI_COUNT++;
  448.  
  449.           if(ZUO_OPEN_2CI_COUNT<=ZUO_OPEN_GEAR1)
  450.           {
  451.             FLAG_ZUO_OPEN_SCR=1;
  452.           }
  453.           if(ZUO_OPEN_2CI_COUNT==1)
  454.           {
  455.             ZUO_REC_TIME=0;
  456.           } else
  457.           {
  458.             ZUO_REC_TIME=2;
  459.           }
  460.  
  461.           if(ZUO_OPEN_2CI_COUNT>=10) ZUO_OPEN_2CI_COUNT=0;  //最大开10个周期
  462.  
  463.         }
  464.  
  465.       }
  466.  
  467.       if(FLAG_ZUO_OPEN_SCR)
  468.       {
  469.  
  470.         ZUO_OPEN_SCR_ZERO_DELAY++;
  471.         if(ZUO_OPEN_SCR_ZERO_DELAY>=77-ZUO_REC_TIME) //78
  472.         {
  473.           ZUO_OPEN_SCR_ZERO_DELAY=0;
  474.           FLAG_ZUO_SCR_ON=1;
  475.           FLAG_ZUO_OPEN_SCR=0;
  476.  
  477.         }
  478.       }
  479.  
  480.  
  481.  
  482.     } else
  483.     {
  484.       ZUO_OPEN_SCR_ZERO_DELAY=0;
  485.       ZUO_REC_TIME=0;
  486.       FLAG_ZUO_OPEN_SCR=0;
  487.       FLAG_ZUO_ZERO_COME=0;
  488.       FLAG_ZUO_SCR_ON=0;
  489.     }
  490.  
  491.  
  492.     if(FLAG_YOU_HEAT_ON) //工作标志位
  493.     {
  494.       if(FLAG_YOU_ZERO_COME)
  495.       {
  496.         FLAG_YOU_ZERO_COME=0;
  497.         YOU_OPEN_SCR_ZERO_DELAY=0;
  498.  
  499.         YOU_OPEN_GEAR1=YOU_OPEN_GEAR;
  500.         if(YOU_OPEN_GEAR1<=2)      YOU_OPEN_GEAR1=2;
  501.         if(YOU_OPEN_GEAR1>=10)     YOU_OPEN_GEAR1=10;
  502.  
  503.         if(YOU_OPEN_GEAR1==10)
  504.         {
  505.           FLAG_YOU_OPEN_SCR=1;
  506.         } else
  507.         {
  508.           YOU_OPEN_2CI_COUNT++;
  509.  
  510.           if(YOU_OPEN_2CI_COUNT<=YOU_OPEN_GEAR1)
  511.           {
  512.             FLAG_YOU_OPEN_SCR=1;
  513.           }
  514.           if(YOU_OPEN_2CI_COUNT==1)
  515.           {
  516.             YOU_REC_TIME=0;
  517.           } else
  518.           {
  519.             YOU_REC_TIME=2;
  520.           }
  521.  
  522.           if(YOU_OPEN_2CI_COUNT>=10) YOU_OPEN_2CI_COUNT=0;  //最大开10个周期
  523.  
  524.         }
  525.  
  526.       }
  527.  
  528.       if(FLAG_YOU_OPEN_SCR)
  529.       {
  530.  
  531.         YOU_OPEN_SCR_ZERO_DELAY++;
  532.         if(YOU_OPEN_SCR_ZERO_DELAY>=77-YOU_REC_TIME) //78
  533.         {
  534.           YOU_OPEN_SCR_ZERO_DELAY=0;
  535.           FLAG_YOU_SCR_ON=1;
  536.           FLAG_YOU_OPEN_SCR=0;
  537.  
  538.         }
  539.       }
  540.  
  541.  
  542.  
  543.     } else
  544.     {
  545.       YOU_OPEN_SCR_ZERO_DELAY=0;
  546.       YOU_REC_TIME=0;
  547.       FLAG_YOU_OPEN_SCR=0;
  548.       FLAG_YOU_ZERO_COME=0;
  549.       FLAG_YOU_SCR_ON=0;
  550.     }
  551.  
  552.  
  553.     if(FLAG_BAONUAN_HEAT_ON) //工作标志位
  554.     {
  555.       if(FLAG_BAONUAN_ZERO_COME)
  556.       {
  557.         FLAG_BAONUAN_ZERO_COME=0;
  558.         BAONUAN_OPEN_SCR_ZERO_DELAY=0;
  559.  
  560.         BAONUAN_OPEN_GEAR1=BAONUAN_OPEN_GEAR;
  561.         if(BAONUAN_OPEN_GEAR1<=2)      BAONUAN_OPEN_GEAR1=2;
  562.         if(BAONUAN_OPEN_GEAR1>=10)     BAONUAN_OPEN_GEAR1=10;
  563.  
  564.         if(BAONUAN_OPEN_GEAR1==10)
  565.         {
  566.           FLAG_BAONUAN_OPEN_SCR=1;
  567.         } else
  568.         {
  569.           BAONUAN_OPEN_2CI_COUNT++;
  570.  
  571.           if(BAONUAN_OPEN_2CI_COUNT<=BAONUAN_OPEN_GEAR1)
  572.           {
  573.             FLAG_BAONUAN_OPEN_SCR=1;
  574.           }
  575.           if(BAONUAN_OPEN_2CI_COUNT==1)
  576.           {
  577.             BAONUAN_REC_TIME=0;
  578.           } else
  579.           {
  580.             BAONUAN_REC_TIME=2;
  581.           }
  582.  
  583.           if(BAONUAN_OPEN_2CI_COUNT>=10) BAONUAN_OPEN_2CI_COUNT=0;  //最大开10个周期
  584.  
  585.         }
  586.  
  587.       }
  588.  
  589.       if(FLAG_BAONUAN_OPEN_SCR)
  590.       {
  591.  
  592.         BAONUAN_OPEN_SCR_ZERO_DELAY++;
  593.         if(BAONUAN_OPEN_SCR_ZERO_DELAY>=77-BAONUAN_REC_TIME) //78
  594.         {
  595.           BAONUAN_OPEN_SCR_ZERO_DELAY=0;
  596.           FLAG_BAONUAN_SCR_ON=1;
  597.           FLAG_BAONUAN_OPEN_SCR=0;
  598.  
  599.         }
  600.       }
  601.  
  602.  
  603.  
  604.     } else
  605.     {
  606.       BAONUAN_OPEN_SCR_ZERO_DELAY=0;
  607.       BAONUAN_REC_TIME=0;
  608.       FLAG_BAONUAN_OPEN_SCR=0;
  609.       FLAG_BAONUAN_ZERO_COME=0;
  610.       FLAG_BAONUAN_SCR_ON=0;
  611.     }
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.     if (Rx_Read_Once==0)                      //读一次现在的IO口状态
  619.     {
  620.       Rx_Read_Once=1;
  621.       Rx_Read_Now=RX_TX_IO;
  622.     }
  623.  
  624.  
  625.     if (Rx_Read_Now!=RX_TX_IO)        //IO口电平发生了变化
  626.     {
  627.       Rx_Read_Once=0;
  628.       Rx_Change=1;
  629.     }
  630.  
  631.  
  632.     switch (Rx_Step)
  633.     {
  634.     case 0:
  635.       if (RX_TX_IO==0) {
  636.         Rx_Step=1;
  637.       }
  638.       Rx_Start_Count=0;
  639.       break;
  640.     case 1:
  641.       if (RX_TX_IO==0)
  642.       {
  643.         Rx_Start_Count++;
  644.       }
  645.       if (RX_TX_IO==1)
  646.       {
  647.         if (Rx_Start_Count>=21&&Rx_Start_Count<=38) //9ms  9000/125=72
  648.         {
  649.           Rx_Start_Count=0;
  650.           Rx_Step=2;
  651.         } else
  652.         {
  653.           Rx_Start_Count=0;
  654.           Rx_Step=0;
  655.         }
  656.       }
  657.       break;
  658.     case 2:
  659.       if (RX_TX_IO==1)
  660.       {
  661.         Rx_Start_Count1++;
  662.       }
  663.       if (RX_TX_IO==0)
  664.       {
  665.         if (Rx_Start_Count1>=30&&Rx_Start_Count1<=40) //4.5ms  4500/125=36
  666.         {
  667.           Rx_Step=3;
  668.           //UART0_SendByte(Rx_Start_Count1);
  669.           Rx_Start_Count1=0;
  670.           Rx_Change=0;
  671.           Rx_Read_Once=0;
  672.         } else
  673.         {
  674.           Rx_Start_Count1=0;
  675.           Rx_Step=0;
  676.         }
  677.       }
  678.       break;
  679.     case 3:
  680.       if (Rx_Dat_Bit==0)             //数一下低电平的时间
  681.       {
  682.         RX_Dat_Low_Count++;
  683.         if (Rx_Change==1)  //IO口由低变成高了
  684.         {
  685.           Rx_Change=0;
  686.           Rx_Read_Once=0;
  687.           Rx_Dat_Bit=1;
  688.         }
  689.       }
  690.       if (Rx_Dat_Bit==1)         //数完低电平  数高电平
  691.       {
  692.         RX_Dat_High_Count++;
  693.         if (Rx_Change==1)           //IO口由高变成低
  694.         {
  695.           Rx_Change=0;
  696.           Rx_Read_Once=0;
  697.           Rx_Dat_Bit=0;
  698.           Rx_Dat_Bit1=1;
  699.         }
  700.       }
  701.       if (Rx_Dat_Bit1)
  702.       {
  703.         Rx_Dat_Bit1=0;
  704.         RX_Dat1=RX_Dat1<<1;
  705.         if (RX_Dat_Low_Count>=3&&RX_Dat_High_Count>=11) //收到拉低0.5MS 拉高1.5
  706.         {
  707.           RX_Dat=(RX_Dat1 |= 0x01);           //收到1
  708.         }
  709.         if (RX_Dat_Low_Count>=3&&RX_Dat_High_Count<=6&&RX_Dat_High_Count>=3) //收到拉低0.5MS 拉高0.5MS
  710.         {
  711.           RX_Dat=RX_Dat1;                      //收到0
  712.           //0
  713.         }
  714.         RX_Dat_Low_Count=0;
  715.         RX_Dat_High_Count=0;
  716.         RX_Count++;
  717.         if (RX_Count>=8)  //收8位数据
  718.         {
  719.           RX_Count=0;
  720.           RX_Dat=RX_Dat1;
  721.           Rx_Step=0;
  722.           Rx_Flag=1;
  723.           RX_Dat1=0;
  724.  
  725.  
  726.           // FLAG_START_RX=0;
  727.         }
  728.       }
  729.       break;
  730.     default:
  731.       break;
  732.     }
  733.  
  734.   }
  735.   else
  736.   {
  737.     PIR1 = 0;
  738.     PIR2 = 0;
  739.   }
  740.  
  741.  
  742.  
  743. }


评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论