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

          關(guān) 閉

          新聞中心

          EEPW首頁 > 工控自動(dòng)化 > 設(shè)計(jì)應(yīng)用 > 無線傳感組網(wǎng)技術(shù)

          無線傳感組網(wǎng)技術(shù)

          作者: 時(shí)間:2013-07-22 來源:網(wǎng)絡(luò) 收藏

          【主要程序文件】:

          //******************************SJA1000初始化***********************************

          void SJA1000_Init(void)
          {
          uchar i,a,b,i_temp=0,TempData,j_temp=0;

          CLI();
          SJA100HardWareRest(); //硬件復(fù)位
          //Read_SJA1000(CAN_IR); //讀中斷寄存器,清除中斷位
          SJAEntryResetMode(); //進(jìn)入復(fù)位模式
          DelayUs(5);
          SR_status = Read_SJA1000(CAN_SR); //讀狀態(tài)
          //進(jìn)入Pelican模式
          Write_SJA1000(CAN_CDR,0xc0); //選擇Pelican模式,CBP=1,激活RX0; 關(guān)閉TX1中斷與時(shí)鐘輸出。
          SR_status = Read_SJA1000(CAN_SR); //讀狀態(tài)
          DelayUs(5);

          //自檢模式,自發(fā)自收檢測
          //Write_SJA1000(CAN_MOD,0x04); //配置模式寄存器,雙濾波,自發(fā)自收

          //接收所有報(bào)文
          Write_SJA1000(CAN_AMR0,0xff); //配置驗(yàn)收屏蔽AMR0=0FFH
          Write_SJA1000(CAN_AMR1,0xff); //配置驗(yàn)收屏蔽AMR1=0FFH
          Write_SJA1000(CAN_AMR2,0xff); //配置驗(yàn)收屏蔽AMR2=0FFH
          Write_SJA1000(CAN_AMR3,0xff); //配置驗(yàn)收屏蔽AMR3=0FFH
          Write_SJA1000(CAN_ACR0,0x00); //配置驗(yàn)收代碼ACR1=0:
          Write_SJA1000(CAN_ACR1,0x00); //配置驗(yàn)收代碼ACR1=0:
          Write_SJA1000(CAN_ACR2,0x00); //配置驗(yàn)收代碼ACR1=0:
          Write_SJA1000(CAN_ACR3,0x00); //配置驗(yàn)收代碼ACR3=0;


          Write_SJA1000(CAN_TXERR,0x00);
          Write_SJA1000(CAN_RXERR,0x00);
          Write_SJA1000(CAN_ECC,0x00);
          Write_SJA1000(CAN_RBSA,0x00);

          //設(shè)置波特率(16MHZ晶振,125Kb)
          Write_SJA1000(CAN_BTR0,0x03); //配置總線定時(shí)--1255kbps 0x6e03
          Write_SJA1000(CAN_BTR1,0x1C); // 0xffaf
          Write_SJA1000(CAN_OCR,0xaa); //配置輸出控制
          Write_SJA1000(CAN_EWLR,0xff); //配置錯(cuò)誤報(bào)警限制為255
          Write_SJA1000(CAN_CMR,0x0c); // 清楚數(shù)據(jù)溢出和釋放接收緩沖器

          // 退出復(fù)位模式,進(jìn)入工作模式
          SJAQuitResetMode();
          SR_status = Read_SJA1000(CAN_SR); //讀狀態(tài)
          //Write_SJA1000(CAN_TXB+4,ID3); //配置發(fā)送緩沖區(qū)的ID3-
          // Write_SJA1000(CAN_IER,0x01); //配置SJA10000中斷-錯(cuò)誤報(bào)警/發(fā)送/接收中斷0x07
          Write_SJA1000(CAN_IER,0x81); //使能SJA1000接收中斷位,和總線錯(cuò)誤中斷位
          SEI();

          }

          //******************************SJA1000發(fā)送程序*********************************
          void send_sja1000(void)
          {
          uchar s,i,canstatus,canstatus1,canstatus2,canstatus3,canstatus4;
          //CLI();
          canstatus= Read_SJA1000(CAN_SR); //讀狀態(tài)
          canstatus1 = Read_SJA1000(CAN_MOD); //讀模式
          canstatus2 =Read_SJA1000(15); //TX錯(cuò)誤計(jì)數(shù)
          canstatus3 =Read_SJA1000(14); //RX錯(cuò)誤計(jì)數(shù)
          canstatus4 =Read_SJA1000(12); //錯(cuò)誤代碼捕捉

          for( i=0;i5;i++ );
          {
          canstatus = Read_SJA1000(CAN_SR);
          }

          if((canstatus 0x0C)== 0x0C) //查詢SJA1000是否處于接收狀態(tài),當(dāng)SJA1000不處于接收狀態(tài)時(shí)才可繼續(xù)執(zhí)行
          { //SR.3=0,發(fā)送請求未處理完,等待直到SR.3=1
          goto SJA1000; //SR.2=0,發(fā)送緩沖器被鎖
          }
          else
          {
          LEDSysMode = 0;
          return;
          }

          SJA1000:

          //發(fā)送數(shù)據(jù)寫進(jìn)發(fā)送緩沖區(qū)中
          WriteSJARegBlock(16,Send_CAN_Info_ID,5); //擴(kuò)展幀,向發(fā)送緩沖區(qū)寫入5個(gè)識(shí)別碼
          Write_SJA1000(21,DataText[0]); //擴(kuò)展幀,向發(fā)送緩沖區(qū)寫入8個(gè)數(shù)據(jù)
          Write_SJA1000(22,DataText[1]);
          Write_SJA1000(23,DataText[2]);
          Write_SJA1000(24,DataText[3]);
          Write_SJA1000(25,DataText[4]);
          Write_SJA1000(27,DataText[6]);
          Write_SJA1000(26,DataText[5]);
          Write_SJA1000(28,DataText[7]);
          // 啟動(dòng)發(fā)送
          Write_SJA1000(CAN_CMR,0x01);//使能發(fā)送請求,發(fā)送數(shù)據(jù)。(0x03,單次發(fā)送,有錯(cuò)誤不重新發(fā)送;0x01發(fā)送請求命令,當(dāng)錯(cuò)誤時(shí)可重發(fā);0x10產(chǎn)生一次自接收性質(zhì)的報(bào)文發(fā)送)
          SEI();
          DataText[7]=0x00;
          while((canstatus0x08) ==0) //檢測是否發(fā)送完畢
          {
          canstatus = Read_SJA1000(CAN_SR); //讀狀態(tài)
          }
          LEDSysMode = 1;

          }

          【總結(jié)】:

          本系統(tǒng)主要是RF和CAN總線兩大塊,功能都能實(shí)現(xiàn)。部分代碼如上所示,若網(wǎng)友希望進(jìn)一步了解,可以站內(nèi)信聯(lián)系。

          原帖地址:http://bbs.21ic.com/icview-584206-1-1.html


          上一頁 1 2 3 下一頁

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉