Wireless module data encryption, anti-code check, send string "Abcdefghijklmnop" led strobe

Source: Internet
Author: User

"The original post must look, otherwise you can not understand this post"

Single chip microcomputer coded wireless module sending and receiving program



"description":

[Send side]:

LED on-off following send status

Send string "Abcdefghijklmnop"

Send the process, with "Brother Chun" GBK code to the string XOR operation encryption

Data verification: The use of anti-code verification, first send the source code, and then send anti-code, anti-jamming


[Receiving end]

Receive the encrypted source code, with "spring elder brother" GBK code to the string XOR operation Decrypt, obtains the source code

Receive anti-code, anti-code and source comparison

Receive string

Determines the string, each character controls the corresponding led to illuminate


【】

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/75/4E/wKioL1Y2EtSj7sKJACUlnSme2mc479.jpg "title=" string. jpg "alt=" wkiol1y2etsj7skjaculnsme2mc479.jpg "/>




"Send Side"

/************************************ Program name:    Wireless Module "Transmitter" program writer:    Brother Chun compilation Time: October 31, 2015 hardware support: stc12c5a60s2  external Crystal 12MHz Interface Description: P0.0 interface transmitter, send led on, send end led off encryption text:     spring Brother &NBSP;--&GT;GBK:B4  ba b8 e7 Check mode:     send data:     send string "Abcdefghijklmnop"/ /#include  <stc12c5a60s2. h> //single-Chip header file sbit out  = p1 ^ 0;   sbit led   = P0 ^ 0;  void DELAY_MS  (Unsigned int a) {     unsigned int i;    while ( a-- != 0) {         for (i = 0; i < 600; i++);     }}void ST  (void) {//Start code     OUT = 1; //     DELAY_MS  (6); &NBSP;&NBSP;&NBSP;&NBSP;OUT&NBSP;=&NBSP;0;&NBsp;//    delay_ms  (4);}  void BT  (bit s) {//Data bit code     OUT = 1;      led=! led;  // led=~led Send status Indication       DELAY_MS  (1);     OUT = 0;     DELAY_MS  (1);     if (s)    DELAY_MS  (1);}  void MT  (unsigned char a) {&NBSP;&NBSP;//8-bit data send     unsigned  char b,i,n;  a=a^0xB4^0xBA^0xB8^0xE7;//  Data encryption   GBK encoding corresponding to spring kanji is  0xb4 0xba  0xB8 0xE7;    b=~a;                    //  Reverse Code     for (i=0;i<8;i++ ) {       //  Send Source         n  = a & 0x80;        a = a << 1;         if (n == 0x80) &NBSP;BT (1); &NBSP;&NBSP;&NBSP;ELSE&NBSP;&NBSP;BT (0);     }    for (i=0;i<8;i++) {       //Send anti-code          n = b & 0x80;         b = b << 1;        if (n &NBSP;==&NBSP;0X80) &NBSP;BT (1); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ELSE&NBSP;BT (0);     }}void END  (void) {MT (0xff);} Void str (UNSIGNED&NBSP;CHAR&NBSP;*STR) {  while (*str !=  ')  MT  (*str++);     *str = 0;}  void main  (void) {    while (1) {         st ();    str ("Abcdefghijklmnop");         end ();         delay_ ms  (+);     }}



"Receiving End"

/************************************ Program name:    Wireless Module "Receive" program writer:    Brother Chun compilation Time: October 31, 2015 hardware support: stc12c4052ad  external Crystal 12MHz Interface Description: P3.4 interface   Connect wireless data ,led   Decryption:     chun brother  -- >gbk:b4 ba b8 e7 receives the character:     receives the string "Abcdefghijklmnop" to determine the string "ABCDEFGHIJKLMNOP", Control LED light off ***************************************/#include  <stc12c2052ad. h> //single-Chip header file Sbit in =p3^4;sbit led1=p1^0;sbit led2=p1^1;sbit led3=p1^2;sbit  LED4=P1^3;sbit LED5=P1^4;sbit LED6=P1^5;sbit LED7=P1^6;sbit LED8=P1^7;unsigned  The char ir_buf[16]; //is used to save 16 8-bit source results unsigned char ir_bak[16]; //for 16 8-bit decoding results unsigned  char re_char[]={"Abcdefghijklmnop"}; //the string to be validated unsigned char length=16; //  Defines the length of the string for use with void delay_ms  (Unsigned int a) {    unsigned int  I;    while ( a-- ! = 0)  for (i = 0; i < 600; i++);}  unsigned int ir_get_low () {    tl1=0;    th1=0;     TR1=1;     //  if it is 0 cycles, cannot exceed 32.768ms     while (! in &&  (th1&0x80) ==0);                     TR1=0;         &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;TH1*256+TL1;}  unsigned int ir_get_high () {    tl1=0;    th1=0;     TR1=1;    //  if it is 1 cycles, it cannot exceed 32.768ms    while (in  &&  (th1&0x80) ==0);     tr1=0;    return th1 *256+TL1;}  void main (void) {Unsigned int temp;unsigned char i,j; The tmod=0x10; //  uses timer 1 to set 16-bit timing/counter while (1) {Restart:while (! in); Temp=ir_get_high ();  if (temp<5000 | |  temp>8000) { goto restart;  }temp=ir_get_low ();   if (temp<3000 | |  temp>6000) { goto restart;  }    //Only the above two tags are passed, indicating the sending end   Ready for (i=0;i<length;i++) {    //receives a length of bytes for (j=0;j<8;j++) {        //receive source Temp=ir_get_high ();  if (temp<500 | |  temp>1500)  goto restart;temp=ir_get_low ();   if (temp<500 | |  temp>2500)  goto restart;ir_buf[i]<<=1;  if (temp>1500)   Ir_Buf[ I]|=0x01;  }for (j=0;j<8;j++) {        //receive anti-code temp=ir_get_ High ();   if (temp<500 | |  temp>1500)  goto restart;temp=ir_get_low ();    if (temp<500 | |  temp>2500)  gOto restart;ir_bak[i]<<=1;       if (temp>1500)   Ir_ bak[i]|=0x01;} if (Ir_buf[i] != ~ir_bak[i])  goto restart; //Anti-code character check ir_buf[i]=ir_buf[i]^0xb4^0xba^0xb8^ 0xe7;  //data decryption   Brother Chun corresponding GBK character is 0xb4 0xba 0xb8 0xe7}if (ir_buf[0]== ' A ')  LED1=0;  if (ir_buf[1]== ' B ')  led2=0; delay_ms ( delay_ms);  if (ir_buf[2]== ' C ')  LED3= 0; delay_ms, if (ir_buf[3]== ' D ')  led4=0; delay_ms,  if (ir_buf[4]== ' E ')  LED5=0;  if (ir_buf[5]== ' F ')  led6=0; delay_ms ( delay_ms);  if (ir_buf[6]== ' G ')  LED7=  if (ir_buf[7]== ' H ')  led8=0; delay_ms (0; delay_ms),  if (ir_buf[8]== ' I ')    if (ir_buf[9]== ' J ')  led2=1; delay_ms (Led1=1; delay_ms);  if (Ir_Buf[10]== ' K ')  if (ir_buf[11]== ' L ')  led4=1; delay_ms ( led3=1; delay_ms);  if (Ir_Buf[12]== ' M ') &nbsP  if (ir_buf[13]== ' N ')  led6=1; delay_ms (Led5=1; delay_ms);  if (Ir_Buf[14]== ' O ')  if (ir_buf[15]== ' P ')  led8=1; delay_ms ( led7=1; delay_ms);      }}















This article comes from "Life is endless, tossing and turning." "blog, declined reprint!"

Wireless module data encryption, anti-code check, send string "Abcdefghijklmnop" led strobe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.