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

📄 js001.c

📁 一个很菜的遥控接收程序
💻 C
字号:
/* RF receive
	mode:6122,00ff
	data:05.4.23 */

#include <stdio.h>
#include <reg51.h>

sfr P11=0x91;
sfr P13=0x93;
sfr P16=0X96;
sfr P17=0X97;

 unsigned char in;
 int count1,count2,count3,t_count1,t_count2;
delay(int t)
 {
  int a,b,c;
  for (b=0;b<t;b++) /* 定时0.1ms*/
   {
     for (a=0;a<0xff;a++)
      {
        for (c=0;c<0xff;c++)
        ;
      }
   } 
}

void time0()interrupt 1  /* 0.05ms*/
 {
   TH0=0xce;
   TL0=0xff;
   count3=count3++;
 }

main()
{
  TMOD=0x01;
  EA=1;
  ET0=1;   /* 允许T0中断*/
  P11=1;          /*接收P11=1*/
  P13=0;        /*发射P13=0*/

  /*char in             接收到高电平?  */
  in=P11;            /*待定*/
  count3=0;
  if((in&0x01)==0x01)  /*有高电平到*/
     {
      TH0=0xce;
      TL0=0xff;
      TF0=1;  /*开T0中断*/
      do(in=P11);
      while(in==0);
      break;
     }
  if(count3>0xaa)  /*>8.5ms*/
    {
      if(count3<0xaa)  /*<9.5ms*/
        {
          TF0=0;
          count3==0;
          in=P11;         /*待定*/
          if((in&0x01)==0)
            {
              TH0=0xce;
              TL0=0xff;
              TF0=1;  /*开T0中断*/
              do(in=P11);
              while(in==0x01);
              break;
            }
          if(count3>0x50)     /*>4.0ms*/
            {
              if(count3<0x64)    /*<5.0ms*/
                {
                  in=P11;          /*待定*/
                  if(in==1) /*待定*/
                  for (count1==8;count1>0;count1--) /*引导码正确,开始接收低8位用户码*/
                    {
                      count3=0;
                      TH0=0xce;
                      TL0=0xff;
                      TF0=1;  /*开T0中断*/
                      do(in=P11);
                      while(in==0);
                      if(count3>0x09)     /*>.45ms*/
                        {
                          if(count3<0x0c)    /*<.6ms*/
                            {
                              count3=0;
                              TH0=0xce;
                              TL0=0xff;
                              TF0=1;  /*开T/*将0写入count1*/  中断*/
                              do(in=P11);
                              while(in==1);
                              break;
                            }
                          if(count3>0x09)     /*>.45ms*/
                            {
                          if(count3<0x0c)    /*<.6ms*/
                            {
                              int t=0x00;
                              t<< (8-count1);    /*t=0,t右移8-count1位*/
                              count1 || t ;      /*将0写入count1*/
                            }
                          if(count3>0x20)    /*>1.6ms*/
                            {
                              if(count3<0x24) /*<1.8ms*/
                                {
                                  int t=0x01;
                                  t<< (8-count1);   /*t右移8-count1位*/
                                  count1 || t ;     /*将1写入count1*/
                                 }
                              }
                           }
                        }
                    }
                  for (count2==8;count2>0;count2--)/*引导码正确,开始接收高8位用户码*/
                    {
                      count3=0;
                      TH0=0xce;
                      TL0=0xff;
                      TF0=1;  /*开T0中断*/
                      do(in=P11);
                      while(in==0);
                      if(count3>0x09)     /*>.45ms*/
                        {
                          if((count3<0x0c)!=0)    /*<.6ms*/
                            {
                              count3=0;
                              TH0=0xce;
                              TL0=0xff;
                              TF0=1;  /*开T0中断*/
                              do(in=P11);
                              while(in==1);
                              break;
                            }
                          if(count3>0x09)     /*>.45ms*/
                            {
                              if(count3<0x0c)    /*<.6ms*/
                                {
                                  int t=0x00;
                                  t<< (8-count2);
                                  count2 || t ;
                                }
                              if(count3>0x20)    /*>1.6ms*/
                                {
                                  if(count3<0x24) /*<1.8ms*/
                                    {
                                      int t=0x01;
                                      t<< (8-count2);   /*t右移8-count1位*/
                                      count2 || t ;
                                    }
                                }
                             }
                           }
                        }
                      count1=!count1;
                      if(count1==count2)
                        {
                          count1=0;
                          count2=0;
              /*接收数据码 ----------*/
                          for (count1==8;count1>0;count1--)
                            {
                              count3=0;
                              TH0=0xce;
                              TL0=0xff;
                              TF0=1;  /*开T0中断*/
                              do(in=P11);
                              while(in==0);
                              if(count3>0x09)     /*>.45ms*/
                                {
                                  if((count3<0x0c)!=0)    /*<.6ms*/
                                    {
                                       count3=0;
                                       TH0=0xce;
                                       TF0=1;  /*开T0中断*/
                                       do(in=P11);
                                       while(in==1);
                                       if(count3>0x09)     /*>.45ms*/
                                         {
                                           if((count3<0x0c)!=0)    /*<.6ms*/
                                             {
                                               int t=0x00;
                                               t<< (8-count1);    /*t右移8-count1位*/
                                               count1 || t ;
                                              }
                                           if(count3>0x20)    /*>1.6ms*/
                                             {
                                               int t=0x01;
                                               t<< (8-count1);   /*t右移8-count1位*/
                                               count1 || t ;
                                              }
                                           }
                                       }
                                  }
                                }
                              for (count2==8;count2>0;count2--)
                                {
                                  count3=0;
                                  TH0=0xce;
                                  TL0=0xff;
                                  TF0=1;  /*开T0中断*/
                                  do(in=P11);
                                  while(in==1);
                                  if(count3>0x09)     /*>.45ms*/
                                    {
                                      if(count3<0x0c)    /*<.6ms*/
                                      count3=0;
                                      TH0=0xce;
                                      TL0=0xff;
                                      TF0=1;  /*开T0中断*/
                                      do(in=P11);
                                      while(in==0);
                                      if(count3>0x09)     /*>.45ms*/
                                       {
                                         if((count3<0x0c)!=0)    /*<.6ms*/
                                           {
                                             int t=0x00;
                                             t<< (8-count2);
                                             count2 || t ;
                                           }
                                         }
                                       if(count3>0x20)    /*>1.6ms*/
                                         {
                                           if(count3<0x24) /*<1.8ms*/
                                             {
                                               int t=0x01;
                                               t<< (8-count2);
                                               count2 || t ;
                                              }
                                           }
                                         }
                                       }
                                    if(count1==!count2)
                                      {
                                        for (;count1>0;count1--)
                                          {
                                            count3=4;
                                            count1&&0xf0;     /*count1取高4位*/
                                            P17 | 0x01;
                                            delay(100);
                                            ~P17;
                                            if (count3=0)
                                            break;
                                          }
                                        count2&&0x0f;     /*count2取低4位*/
                                       count3=4;
                                       for (;count1>0;count1--)
                                         {
                                           P16 | 0x01;
                                           delay(100);
                                           ~P16;
                                           if (count3=0)
                                           break;
                                         }
                                       }
                                  }
                             }
                         }
                   }
             }
        }


stopover:      /*错误,退出并延时!*/
count3=0;
TF0=0;      /*关T0定时器*/
  delay(100);
  delay(100);
  delay(100);
  delay(100);

}

⌨️ 快捷键说明

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