色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 51單片機+315M無線射頻模塊發(fā)射程序

          51單片機+315M無線射頻模塊發(fā)射程序

          作者: 時間:2016-11-30 來源:網絡 收藏

          recv_bit_p--;
          if(recv_bit_p == 0){//接收完一字節(jié)
          recv_bit_p = 8;
          //serial_out(recving_byte);//輸出接收到的字符
          recv_buf[recv_byte_p] = recving_byte;
          recv_byte_p++;
          if(recv_byte_p == recv_byts){
          recv_step = 0;
          recv_stat = RECV_SUCCESS;
          }
          }
          }
          }

          本文引用地址:http://cafeforensic.com/article/201611/323711.htm

          //=============================================================
          //接收程序 結束
          //=============================================================

          #define SEND_DELAY_TIME 20//防碰撞延遲(單位:毫秒)
          unsigned char send_delay = SEND_DELAY_TIME;
          #define VALID_PULS_COUNT 10
          unsigned char valid_puls_counts = VALID_PULS_COUNT;

          //碰撞檢測在該函數中實現.由于無線模塊本身的限制,碰撞檢測為非完全檢測,只能在發(fā)送前
          //檢測是否有其它單元在使用信道,在發(fā)送過程中受到的碰撞干擾是無法檢測到的.經測試,效果還行
          void wirless(){
          if (send_stat == SEND_PROGRESSING && send_delay == 0){
          send();
          if (send_stat == SEND_SUCCESS)
          send_delay = SEND_DELAY_TIME;
          }else{
          recv();
          if (recv_step > HEAD_NEED_RECIVED)//如果檢測到當前有其它單元正在發(fā)送,繼續(xù)等待
          send_delay = SEND_DELAY_TIME;
          else{
          if(TEST_PULS(w_data, PULS_0_WIDTH)//如果檢測到當前有其它單元正在發(fā)送,繼續(xù)等待
          || TEST_PULS(w_data, PULS_1_WIDTH)
          //|| TEST_PULS(w_data, PULS_HEAD_WIDTH)
          || TEST_PULS(w_data, PULS_START_WIDTH)
          //|| TEST_PULS(w_data, PULS_STOP_WIDTH)
          ){
          if (valid_puls_counts)
          valid_puls_counts--;
          else
          send_delay = SEND_DELAY_TIME;
          }else{
          valid_puls_counts = VALID_PULS_COUNT;
          }
          }
          }
          }

          #define SCMD_SET_PORT 0x51
          #define SCMD_GET_PORT 0x52

          #define SCMD_RESET 0x61

          #define SCMD_LCD_OUTSTR 0x71
          #define SCMD_LCD_RESET 0x72
          #define SCMD_LCD_SETXY 0x73
          #define SCMD_LCD_SETLINE 0x74
          #define SCMD_LCD_CLEAR 0x75


          #define SRESP_GET_PORT_ERROR 0x41
          #define SRESP_SET_PORT_ERROR 0x42

          #define HEART_BEAT_INTERVAL 100//心跳間隔 X / 1000 秒
          unsigned int heart_beat_timer = HEART_BEAT_INTERVAL;
          unsigned int last_jiffies=0;

          void main(){

          init_serialcomm();
          //P0=0xff;
          //P2=0x00; ;
          sys_init();

          LED1 = 0;
          LED2 = 1;
          //send_string_com("ok",2);
          //lcd_reset();
          //lcd_power_on();
          //lcd_self_test();

          while(1){

          if (jiffies - last_jiffies >= 50){//每次中斷為50us,所以要20次才為1ms
          last_jiffies = jiffies;
          heart_beat_timer--;

          if (send_stat == 0 ){//碰撞測試

          ET0=0;
          ReadTemperature();

          clock_init_again();

          START_SEND(8);
          send_buf[1]=Te/10+0x30;
          send_buf[2]=Te%10+0x30;
          send_buf[3]=.;
          send_buf[4]=Te_D/10+0x30;
          send_buf[5]=(Te_D%10)+0x30;
          send_buf[6]=D;
          send_buf[7]=