標(biāo)題: 單片機(jī)16路藍(lán)牙遙控開關(guān)程序 [打印本頁(yè)]

作者: 6313    時(shí)間: 2021-3-4 15:54
標(biāo)題: 單片機(jī)16路藍(lán)牙遙控開關(guān)程序
寫了兩個(gè)程序,一個(gè)是8路的,一個(gè)是16路的。手機(jī)藍(lán)牙串口軟件最多支持12路控制。有會(huì)編寫軟件的可以提供一個(gè)多路的用一下
程序部分預(yù)覽:
  1. #include <REGX52.H>
  2. #define uint unsigned int
  3. #define uchar unsigned char

  4. sbit LED1=P2^0;
  5. sbit LED2=P2^1;
  6. sbit LED3=P2^2;
  7. sbit LED4=P2^3;
  8. sbit LED5=P2^4;
  9. sbit LED6=P2^5;
  10. sbit LED7=P2^6;
  11. sbit LED8=P2^7;

  12. sbit LED9= P1^0;
  13. sbit LED10=P1^1;
  14. sbit LED11=P1^2;
  15. sbit LED12=P1^3;
  16. sbit LED13=P1^4;
  17. sbit LED14=P1^5;
  18. sbit LED15=P1^6;
  19. sbit LED16=P1^7;
  20. void blue_Init()
  21. {
  22.   TMOD=0x20;
  23.     TH1=0xfd;//9600
  24.     TL1=0xfd;
  25.     SM0=0;
  26.     SM1=1;               
  27.     REN=1;
  28.     TR1=1;
  29. }

  30. void main()
  31. {
  32.   int a;
  33.   blue_Init();
  34.         P2=0xff;
  35.         P1=0xff;
  36.     while(1)
  37.         {
  38.                                    if(RI==1)
  39.                                         {  
  40.                                                                 a=SBUF;
  41.                                                                 RI=0;
  42.                                                                                
  43.                                                                  if(a==0x01)         //1
  44.                                                                  {
  45.                                                                    LED1=!LED1;
  46.                                                                  }   
  47.                                                  
  48.                                                                  else if(a==0x02)//2
  49.                                                                  {
  50.                                                             LED2=!LED2;
  51.                                                                  }
  52.                                                                  
  53.                                                                  else if(a==0x03)//3
  54.                                                                  {
  55.                                                             LED3=!LED3;
  56.                                                                  }
  57.                                                                  else if(a==0x04)//4
  58.                                                                  {
  59.                                                             LED4=!LED4;
  60.                                                                  }  if(a==0x05)         //5
  61.                                                                  {
  62.                                                                    LED5=!LED5;
  63.                                                                  }   
  64.                                                  
  65.                                                                  else if(a==0x06)//6
  66.                                                                  {
  67.                                                             LED6=!LED6;
  68.                                                                  }
  69.                                                                  
  70.                                                                  else if(a==0x07)//7
  71.                                                                  {
  72.                                                             LED7=!LED7;
  73.                                                                  }
  74.                                                                  else if(a==0x08)//8
  75.                                                                  {
  76.                                                             LED8=!LED8;
  77.                                                                  }

  78.                                                                  if(a==0x09)         //9
  79.                                                                  {
  80.                                                                    LED9=!LED9;
  81.                                                                  }   
  82.                                                  
  83.                                                                  else if(a==0x0A)//10
  84.                                                                  {
  85.                                                             LED10=!LED10;
  86.                                                                  }
  87.                                                                  
  88.                                                                  else if(a==0x0B)//11
  89.                                                                  {
  90.                                                             LED11=!LED11;
  91.                                                                  }
  92.                                                                  else if(a==0x0C)//12
  93.                                                                  {
  94.                                                             LED12=!LED12;
  95.                                                                  }  if(a==0x0D)         //13
  96.                                                                  {
  97.                                                                    LED13=!LED13;
  98.                                                                  }   
  99.                                                  
  100.                                                                  else if(a==0x0E)//14
  101.                                                                  {
  102.                                                             LED14=!LED14;
  103.                                                                  }
  104.                                                                  
  105.                                                                  else if(a==0x0F)//15
  106.                                                                  {
  107.                                                             LED15=!LED15;
  108.                                                                  }
  109.                                                                  else if(a==0x10)//16
  110.                                                                  {
  111.                                                             LED16=!LED16;
  112.                                                                  }


  113.                                      }  
  114.                                                 }
  115.                                 }
復(fù)制代碼


47A9D1E14BA52A5EF2BEB6EF9233D2E2.jpg (93.91 KB, 下載次數(shù): 167)

1.jpg

1.jpg

47A9D1E14BA52A5EF2BEB6EF9233D2E2.jpg (93.91 KB, 下載次數(shù): 160)

47A9D1E14BA52A5EF2BEB6EF9233D2E2.jpg

IMG_20210121_094959.jpg (80.84 KB, 下載次數(shù): 164)

IMG_20210121_094959.jpg

l藍(lán)牙16路遙控開關(guān)程序.zip

1.59 MB, 下載次數(shù): 45, 下載積分: 黑幣 -5


作者: 6313    時(shí)間: 2021-3-5 20:20
手機(jī)app在壓縮包里面,程序需要配合手機(jī)app才可以正常使用
作者: changhz    時(shí)間: 2021-3-6 10:30
好東西,下來(lái)用下,這太多路了8路都?jí)蛴昧?hr noshade size="2" width="100%" color="#808080"> 作者: 快樂(lè)a123    時(shí)間: 2021-3-9 21:01
1/8路選擇16進(jìn)制,app輸入1/2/3/4/5/7/8




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1