您的位置:首页版主原创无线电技术
内容搜索:
阅读内容
背景:#EDF0F5 #FAFBE6 #FFF2E2 #FDE6E0 #F3FFE1 #DAFAF3 #EAEAEF 默认  

无线收发串口中断服务程序(nRF401)

[日期:2008-08-13 ] [来源:东哥单片机学习网 www.picavr.com 作者:佚名] [字体: (投递新闻)
nRF401无线收发串口中断服务程序
void sioproc() interrupt SIO_VECTOR using 1
{
unsigned char i;
unsigned int crc;
  if (RI) {//接收中断
    RI = 0;
    if (!nRFTXEN && SioBuffers.RXCount) {//每次接收20个数据
      i = SBUF;
      SioBuffers.RXCount --;
      SioBuffers.RXBuffers[19 - SioBuffers.RXCount] = i;
      switch(SioBuffers.RXCount) {
        case 19:
               if (i != 0x55) SioBuffers.RXCount = 20;
                 break;
        case 18:
               if (i != 0xaa) SioBuffers.RXCount = 20;
                 break;
        case 0:
               crc = 0;
               for (i = 1; i <= 8; i ++) {
                 crc = crc16r(GetRXBuffWord(i + i), crc);
               }
               if (crc != GetRXBuffWord(18))
                 SioBuffers.RXCount = 20;
                else {
                 nRFTXEN = 1;//发送
                 for (i = 0; i < 20; i ++) {
                   SioBuffers.TXBuffers = SioBuffers.RXBuffers;
                 }
                 SioBuffers.TXMAXCount = TX_MAXCount;
                 SioBuffers.TXCount = TX_Count + 32;
                 TI = 1;//接收结束立即转为发送
               }
               break;
      }
    } 
  }
  if (TI) {//发送中断
    TI = 0;
    if (nRFTXEN && SioBuffers.TXCount) {
      SioBuffers.TXCount --;
      if (SioBuffers.TXCount > 19) {
        SBUF = 0x00;
      }
      else {
        SBUF = SioBuffers.TXBuffers[19 - SioBuffers.TXCount];
      }
        if (SioBuffers.TXCount == 0) {
        if (SioBuffers.TXMAXCount) {
          SioBuffers.TXMAXCount --;
          SioBuffers.TXCount = TX_Count;
        }
        else {
          nRFTXEN = 0;//发送结束立即转为接收
          SioBuffers.RXCount = 20;
        }
      }
    }
  }   
  
阅读:
录入:petta

推荐 】 【 打印
本文评论
      全部评论
发表评论


点评: 字数
姓名:
站长推荐