找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索

C51解析天貓精靈隊(duì)友的協(xié)議用于改裝語音控制開關(guān) 附單片機(jī)程序

查看數(shù): 859 | 評(píng)論數(shù): 2 | 收藏 4
關(guān)燈 | 提示:支持鍵盤翻頁<-左 右->
    組圖打開中,請(qǐng)稍候......
發(fā)布時(shí)間: 2024-11-5 17:28

正文摘要:

事情是這樣的,某魚淘了一些一兩塊錢的天貓精靈隊(duì)友香薰機(jī)主板, 可以用天貓精靈控制,但是只能噴霧用,噴霧呢,又是間歇的,間隔幾分鐘噴一次。 想用他這個(gè)噴霧信號(hào)來改裝排插開關(guān)是不可能了。 于是用電腦抓了一 ...

回復(fù)

ID:433219 發(fā)表于 2024-11-6 10:05
  分析協(xié)議,找出規(guī)律,,,好玩的DIY
ID:512651 發(fā)表于 2024-11-5 17:30
代碼寫的比較爛,湊合也能用,見笑了 N79E8132天貓精靈解析開關(guān)執(zhí)行UART.zip (69.98 KB, 下載次數(shù): 4)
  1. #define Uart_Port_Sel   0x00
  2. #include <stdio.h>
  3. #include "N79E81x.h"
  4. #include "Typedef.h"
  5. #include "Define.h"
  6. #include "Common.h"
  7. #include "Delay.h"
  8. #include "Version.h"

  9. UINT8 u8Uart_Data;

  10. u8 RxBuf[16];
  11. u8 TxBuf[16];
  12. u8 StuNum[] = "201918060210";
  13. bit bRxFlag = 0;
  14. u8 RxLth = 0;
  15. u8 TxLth = 0;
  16. u8 Rxcounter = 0;
  17. u8 Txcounter = 0;
  18. u8 RxStus = 0;
  19. u8 RxFunc = 0;


  20. void Delay_ms(u16 ms)
  21. {
  22.         unsigned char i, j;

  23.         while(ms--)
  24.         {
  25.                 ;;//_nop_();
  26.                 i = 2;
  27.                 j = 199;
  28.                 do
  29.                 {
  30.                         while (--j);
  31.                 } while (--i);
  32.         }
  33. }

  34. //-----------------------------------------------------------------------------------------------------------
  35. void main (void)
  36. {
  37.     AUXR1 |= Uart_Port_Sel;             // Select P10/P11 as UART pin(default)
  38.     InitialUART0_Timer1(9600);          // 9600 Baud Rate @ 11.0592MHz
  39.        
  40.                 TxBuf[0] = 0x4a;                //前導(dǎo)    0x4a  
  41.                 TxBuf[1] = 0x43;                //前導(dǎo)    0x43
  42.                 TxBuf[2] = 0x0a;                //地址    0x0a        學(xué)號(hào):10
  43.                 TxBuf[3] = 0x01;                //功能號(hào)  1
  44.                 TxBuf[4] = 0x01;                //長(zhǎng)度    1
  45.        
  46.     Show_Version_Number_To_PC();
  47.     printf ("\n*===================================================================");
  48.     printf ("\n*  Name: N79E84x Series UART Sample Code.");
  49.     printf ("\n*===================================================================");
  50.     printf ("\n UART receive a byte and transmit the same byte to PC.\n");
  51.     ES = 1;                             // Enable serial interrupt
  52.     EA = 1;                             // Enable global interrupt

  53.     while(1);                          // Endless

  54. }

  55. //開
  56. //FF 00 00 06 82 02 01 CE 41 00 9A
  57. //關(guān)
  58. //FF 00 00 06 82 02 00 CF 41 00 9A

  59. void UART_ISR(void) interrupt 4
  60. {
  61.         u8 tmp;
  62.         static u8 sum = 0;
  63.         if(RI){
  64.                 RI = 0;
  65.                 tmp = SBUF;
  66.                 switch(RxStus){
  67.                         case 0 :        //前導(dǎo)
  68.                                 if(tmp == 0xFF)
  69.                                         RxStus = 1;
  70.                                 break;
  71.                         case 1 :        //前導(dǎo)
  72.                                 if(tmp == 0x0)
  73.                                         RxStus = 2;
  74.                                 break;
  75.                         case 2 :        //地址
  76.                                 if(tmp == 0x0){       
  77.                                         RxStus = 3;
  78.                                         sum = tmp;
  79.                                 }
  80.                                 break;
  81.                         case 3 :        //功能號(hào)
  82.                                 if(tmp == 0x06){
  83.                                         RxStus = 4;
  84.                                         sum = tmp;
  85.                                 }
  86.                                 break;
  87.                         case 4 :        //長(zhǎng)度
  88.                                 if(tmp == 0x82){       
  89.                                         RxStus = 5;
  90.                                         sum = tmp;
  91.                                 }
  92.                                 break;
  93.                         case 5 :        //數(shù)據(jù)
  94.                                 if(tmp == 0x02){
  95.                                         RxStus = 6;
  96.                                         sum = tmp;
  97.                                 }
  98.                                 break;
  99.                         case 6 :        //校驗(yàn)
  100.                                 if(tmp == 0x01)        P02=0;                       
  101.                                 else if(tmp == 0x00)P02=1;
  102.                                
  103.                                 RxStus = 7;
  104.                                 sum = tmp;
  105.                                
  106.                                 break;
  107.                                
  108.                                
  109.                         default :
  110.                                 RxStus = 0;
  111.                                 Rxcounter = 0;
  112.                                 break;
  113.                 }
  114.         }
  115.        
  116.        
  117.         if(TI){
  118.                 TI = 0;
  119.                 if(Txcounter < TxLth){
  120.                         SBUF = TxBuf[Txcounter++];
  121.                 }
  122.                 else{
  123.                         Txcounter = 0;
  124.                         TxLth = 0;
  125.                 }
  126.         }
  127. }
復(fù)制代碼




小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表