C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 1   


C51 COMPILER V9.54, COMPILATION OF MODULE HS6220_RF
OBJECT MODULE PLACED IN .\release\HS6220_RF.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE port\hs6220\HS6220_RF.c LARGE OMF2 OPTIMIZE(8,SPEED) REGFILE(.\release\B
                    -L003C4.ORC) BROWSE DEBUG PRINT(.\release\listings\HS6220_RF.lst) OBJECT(.\release\HS6220_RF.obj)

line level    source

   1          //------------------------------------------------------------------------------------
   2          // HS6206.c
   3          //------------------------------------------------------------------------------------
   4          // Copyright 2014, HunterSun Electronics Co., Ltd.
   5          // Yufeng. Yao
   6          // 2014-01-16
   7          //
   8          // Program Description:
   9          //
  10          //
  11          //
  12          #include ".\port\port_mcu.h"
  13          #include "HS6220_RF.h"
  14          #include <intrins.h>
  15          
  16          #define rf_csn_pin_att(x)               att_p07(x)
  17          #define rf_sck_pin_att(x)               att_p20(x)      
  18          #define rf_mosi_pin_att(x)              att_p06(x)
  19          #define rf_irq_pin_att(x)               att_p23(x)
  20          #define rf_csn_pin_status(x)    pin_out(P0_7,x)
  21          #define rf_sck_pin_status(x)    pin_out(P2_0,x)
  22          #define rf_mosi_pin_status(x)   pin_out(P0_6,x)
  23          
  24          /* OM6220 模拟SPI(3,4线)接口初始化函数
  25            已经没有硬件CE的控制脚了，
  26            IRQ脚根据需要进行配置
  27          */
  28          
  29          void HS6220_SPI_Init(void)
  30          {
  31   1      // SPI_CSN  -- P0.7             output high
  32   1      // SPI_SCK  -- P2.0             output low
  33   1      // SPI_MOSI -- P0.6             output high
  34   1      // RF_IRQ   -- P2.3             input pull high
  35   1              
  36   1              rf_csn_pin_att(IO_OUT_PUSH_PULL);
  37   1              rf_sck_pin_att(IO_OUT_PUSH_PULL);
  38   1              rf_mosi_pin_att(IO_OUT_PUSH_PULL);
  39   1              rf_irq_pin_att(IO_SMTIN_PULL_UP);
  40   1              
  41   1              rf_csn_pin_status(1);
  42   1              rf_sck_pin_status(0);
  43   1              rf_mosi_pin_status(1);
  44   1      }
  45          
  46          // 3线SPI写操作函数
  47          void SPI_3wire_sendByte(unsigned char TxData)
  48          {
  49   1              unsigned char i;
  50   1              unsigned char data_output_bit;
  51   1              
  52   1      //      设置RF_MOSI为输出
  53   1              rf_mosi_pin_att(IO_OUT_PUSH_PULL);
  54   1              _nop_();
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 2   

  55   1              _nop_();        
  56   1              for(i = 0; i < 8; i ++) 
  57   1              {
  58   2                      data_output_bit = TxData & 0x80 ? 1 : 0;
  59   2                      HS6220_SCK_LOW;
  60   2                      if(data_output_bit){
  61   3                              HS6220_SDIO_HIGH;
  62   3                      }
  63   2                      else{
  64   3                              HS6220_SDIO_LOW;
  65   3                      }
  66   2      
  67   2                      HS6220_SCK_HIGH;
  68   2      //              NOP_DELAY();
  69   2                      TxData = TxData << 1;
  70   2              }
  71   1      
  72   1              HS6220_SDIO_LOW;
  73   1              HS6220_SCK_LOW;
  74   1      //      NOP_DELAY();NOP_DELAY();NOP_DELAY();
  75   1      }
  76          
  77          // 3线SPI读操作函数
  78          unsigned char SPI_3wire_readByte(void)
  79          {
  80   1              unsigned char bit_ctr;
  81   1              unsigned char byte = 0;
  82   1              unsigned char temp = 0;
  83   1              
  84   1      //      设置RF_MOSI为输入上拉
  85   1              rf_mosi_pin_att(IO_SMTIN_PULL_UP);      
  86   1              for(bit_ctr = 0; bit_ctr < 8; bit_ctr ++) // output 8-bit
  87   1              {
  88   2                      byte = byte << 1;
  89   2                      HS6220_SCK_HIGH;   
  90   2                      temp = HS6220_SDIO_STATUS;
  91   2                      byte |= temp;          
  92   2                      HS6220_SCK_LOW;               
  93   2              }
  94   1      
  95   1              return (byte); // return read byte
  96   1      }
  97          
  98          // 封装起来的对外可调用的SPI写函数
  99          void SPI_SendByte(unsigned char Data)
 100          {
 101   1      #if (HS6220_SPI_NWIRE == SPI_3_WIRE)
 102   1              // 3线SPI写
 103   1              SPI_3wire_sendByte(Data);
 104   1      #else
                      // 4线SPI读写
                      spi_4wire_wrd(Data);
              #endif
 108   1      }
 109          
 110          // 封装起来的对外可调用的SPI读函数
 111          unsigned char SPI_ReadByte(void)
 112          {
 113   1      #if (HS6220_SPI_NWIRE == SPI_3_WIRE)
 114   1              // 3线SPI读
 115   1              return SPI_3wire_readByte();
 116   1      #else
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 3   

                      // 4线SPI读
                      return spi_4wire_wrd(0);
              #endif
 120   1      }
 121          
 122          // OM6220写一个寄存器一个值操作函数
 123          void HS6220_write_byte(unsigned char addr,unsigned char D)
 124          {
 125   1              HS6220_CSN_LOW;
 126   1              SPI_SendByte(HS6220_W_REGISTER | addr);
 127   1              SPI_SendByte(D);
 128   1              HS6220_CSN_HIGH;
 129   1      }
 130          
 131          // OM6220写一个寄存器多个数值操作函数
 132          void HS6220_wr_buffer(unsigned char addr,const unsigned char* buf,unsigned char len)
 133          {
 134   1              HS6220_CSN_LOW;
 135   1              SPI_SendByte(HS6220_W_REGISTER | addr);
 136   1              while(len--)
 137   1              {
 138   2                      SPI_SendByte(*buf ++);
 139   2              }
 140   1              HS6220_CSN_HIGH;
 141   1      }
 142          
 143          // OM6220读一个寄存器一个值操作函数
 144          unsigned char HS6220_read_byte(unsigned char addr)
 145          {
 146   1              unsigned char rxdata;
 147   1              
 148   1              HS6220_CSN_LOW;
 149   1              SPI_SendByte(HS6220_R_REGISTER | addr);
 150   1              rxdata = SPI_ReadByte();
 151   1              HS6220_CSN_HIGH;
 152   1              
 153   1              return(rxdata);
 154   1      }
 155          
 156          // OM6220读一个寄存器多个值操作函数
 157          void HS6220_read_buffer(unsigned char addr, unsigned char* buf, unsigned char len)
 158          {
 159   1              HS6220_CSN_LOW;
 160   1              SPI_SendByte(HS6220_R_REGISTER | addr);
 161   1              
 162   1              while(len --)
 163   1              {
 164   2                      *buf ++ = SPI_ReadByte();
 165   2              }
 166   1              HS6220_CSN_HIGH;
 167   1      }
 168          
 169          // OM6220直接发命令函数
 170          void HS6220_Operation(unsigned char opt)
 171          {       
 172   1              HS6220_CSN_LOW;
 173   1              SPI_SendByte(opt);
 174   1              HS6220_CSN_HIGH;
 175   1      }
 176          
 177          
 178          /* OM6220 初始化函数
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 4   

 179          第一版的模块，只做测试用，初始化的内容还有点多
 180          改第二版之后，有些值会作为默认值，初始化内容就会少很多
 181          */
 182          void HS6220_Init(void)
 183          {
 184   1              unsigned char temp[5];
 185   1              HS6220_SPI_Init();
 186   1      
 187   1      //RF软件复位    
 188   1              HS6220_write_byte(HS6220_BANK0_FEATURE, SOFT_RST);       // soft_reset
 189   1      //配置SPI是3线通讯还是4线通讯
 190   1              HS6220_write_byte(HS6220_BANK0_DYNPD, 0x00);
 191   1      //      HS6220_write_byte(HS6220_BANK0_DYNPD, 0x08);
 192   1      //RF芯片上电，设置为工作模式
 193   1              HS6220_CE_Low();        
 194   1              HS6220_write_byte(HS6220_BANK0_CONFIG, 0x8b);           //上电
 195   1              delay_ms(3); // wait 3 ms
 196   1              HS6220_write_byte(HS6220_BANK0_PMU_CTL, 0xa8);          //工作模式
 197   1              delay_ms(2);
 198   1      //必需开启高斯滤波    
 199   1              HS6220_write_byte(HS6220_BANK0_FEATURE, 0x10);
 200   1      
 201   1      //切换到BANK1
 202   1              HS6220_Bank_Switch(HS6220_Bank1);
 203   1      //BANK1的TEST_PKDET(该寄存器共24位)的第5位设置为1
 204   1              HS6220_write_byte(HS6220_BANK1_TEST_PKDET, 0x20);
 205   1      //BANK1的FAGC_CTRL_1(该寄存器共32位)  
 206   1              temp[0] = 0x01;
 207   1              HS6220_wr_buffer(HS6220_BANK1_FAGC_CTRL_1, temp, 1);
 208   1      /*
 209   1      //电机动作的时候 HS6220_BANK1_FAGC_CTRL_1按以下配置
 210   1      //要先拉低CE，切换到Bank1去操作
 211   1      //6220为了提高抗干扰能力, 提高了 VCO的增益, 而这样做, 也增强了 本振泄露, 过认证又不好过了 
 212   1      //一个可行的解决办法: 接收小车在 马达转动的时候才提高VCO, 不转的时候恢复原来的值
 213   1              temp[2] = 0x05;
 214   1              temp[1] = 0xa1;
 215   1              temp[0] = 0xc1; 
 216   1              HS6220_wr_buffer(HS6220_BANK1_FAGC_CTRL_1, temp, 3);
 217   1      */
 218   1      //BANK1的AGC_CTRL(该寄存器共24位)       
 219   1              temp[1] = 0xb2;
 220   1              temp[0] = 0xcf;  
 221   1              HS6220_wr_buffer(HS6220_BANK1_AGC_CTRL, temp, 2);
 222   1      
 223   1      //切换到BANK0
 224   1              HS6220_Bank_Switch(HS6220_Bank0);       
 225   1      //给CE至少40US的脉冲，启动RF校准
 226   1              HS6220_CE_High();
 227   1              delay_us(100);
 228   1              HS6220_CE_Low(); //校准的时候CE是低的
 229   1      //等待校准结束
 230   1              while((HS6220_read_byte(HS6220_BANK0_RF_SETUP) & 0x20) == 0x00);   //wait cal done
 231   1      //      while(1)
 232   1      //      {       //
 233   1      //              if(HS6220_read_byte(HS6220_BANK0_RF_SETUP) & 0x20)
 234   1      //              {
 235   1      //                      break;
 236   1      //              }
 237   1      //              Delay10us(10);
 238   1      //      }
 239   1      //关闭校准(CAL_EN置0)
 240   1              HS6220_write_byte(HS6220_BANK0_RF_SETUP, 0x40);
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 5   

 241   1      
 242   1      //切换到BANK1
 243   1              HS6220_Bank_Switch(HS6220_Bank1);       
 244   1      //设置BANK1的CAL_CTL(该寄存器共32位)
 245   1              temp[2] = 0x75;         //bp_dac =1 bp_rc = 1
 246   1              temp[1] = 0x98;         // bp_vco_amp = 1 bp_vco_ldo=1
 247   1              temp[0] = 0x20;
 248   1              HS6220_wr_buffer(HS6220_BANK1_CAL_CTL, temp, 3);
 249   1      
 250   1      //切换到BANK0
 251   1              HS6220_Bank_Switch(HS6220_Bank0);
 252   1      //设置RX地址
 253   1              temp[0] = 0x46;
 254   1              temp[1] = 0x0b;
 255   1              temp[2] = 0xaf;
 256   1              temp[3] = 0x43;
 257   1              temp[4] = 0x98; 
 258   1      //      temp[0] = 0x65;
 259   1      //      temp[1] = 0x6e;
 260   1      //      temp[2] = 0x54;
 261   1      //      temp[3] = 0x9c;
 262   1      //      temp[4] = 0x52; 
 263   1              HS6220_wr_buffer(HS6220_BANK0_RX_ADDR_P0, temp, 5); // set address
 264   1      //设置TX地址
 265   1              temp[0]=0x46;
 266   1              temp[1]=0x0b;
 267   1              temp[2]=0xaf;
 268   1              temp[3]=0x43;
 269   1              temp[4]=0x98;
 270   1      //      temp[0] = 0x65;
 271   1      //      temp[1] = 0x6e;
 272   1      //      temp[2] = 0x54;
 273   1      //      temp[3] = 0x9c;
 274   1      //      temp[4] = 0x52; 
 275   1              HS6220_wr_buffer(HS6220_BANK0_TX_ADDR, temp, 5);   //set address
 276   1      //必需开启高斯滤波,使能动态数据包长度
 277   1              HS6220_write_byte(HS6220_BANK0_FEATURE, 0x10);
 278   1      //使能RX自动应答
 279   1              HS6220_write_byte(HS6220_BANK0_EN_AA, 0x00);            //禁止RX自动应答
 280   1      //      HS6220_write_byte(HS6220_BANK0_EN_AA, 0x01);            //使能RX自动应答
 281   1      //设置CONFIG(RX MODE : 0xFB;TX MODE : 0xFA)     
 282   1              HS6220_write_byte(HS6220_BANK0_CONFIG, 0xfA);
 283   1      //设置收发数据长度
 284   1              HS6220_write_byte(HS6220_BANK0_RX_PW_P0, D_RF_DATA_LENTH);
 285   1      //设置收发频道
 286   1              HS6220_write_byte(HS6220_BANK0_RF_CH, D_RF_CHANNEL);
 287   1      //使能RX PIPE
 288   1              HS6220_write_byte(HS6220_BANK0_EN_RXADDR, 0x01);
 289   1      //使能自动重传
 290   1              HS6220_write_byte(HS6220_BANK0_SETUP_RETR, 0x43);       //间隔1MS自动重传4次
 291   1      //设置功率
 292   1              HS6220_write_byte(HS6220_BANK0_RF_SETUP, 0x47);         //功率设置最大(8DB)
 293   1      //使能动态数据包 PIPE
 294   1              HS6220_write_byte(HS6220_BANK0_DYNPD, 0x07);
 295   1              
 296   1              HS6220_Clear_All_Irq();
 297   1              HS6220_Flush_Tx();      
 298   1      //      HS6220_CE_High();       
 299   1      }
 300          
 301          /*OM6220 读写寄存器函数
 302           cmd = code; 
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 6   

 303           D = data
 304           */
 305          void HS6220_wr_cmd(unsigned char cmd,unsigned char D)
 306          {
 307   1              HS6220_CSN_LOW;
 308   1              SPI_SendByte(cmd);
 309   1              SPI_SendByte(D);
 310   1              HS6220_CSN_HIGH;
 311   1      }
 312          
 313          // 切换OM6220 BANK
 314          void HS6220_Bank_Switch(HS6220_Bank_TypeDef bank)
 315          {
 316   1              unsigned char sta;
 317   1              
 318   1              sta = HS6220_read_byte(HS6220_BANK0_STATUS);
 319   1              
 320   1              if(bank != HS6220_Bank0)
 321   1              {
 322   2                      if(!(sta & HS6220_Bank1))
 323   2                      {
 324   3                              HS6220_wr_cmd(HS6220_ACTIVATE, HS6220_ACTIVATE_DATA);
 325   3                      }
 326   2              }
 327   1              else
 328   1              {
 329   2                      if(sta & HS6220_Bank1)
 330   2                      {
 331   3                              HS6220_wr_cmd(HS6220_ACTIVATE, HS6220_ACTIVATE_DATA);
 332   3                      }
 333   2              }
 334   1      }
 335          
 336          // OM6220 切换速率
 337          void HS6220_Change_Rate(HS6220_Rate_TypeDef rate)
 338          {
 339   1              unsigned char tmp;
 340   1              
 341   1              tmp = HS6220_read_byte(HS6220_BANK0_RF_SETUP);
 342   1      
 343   1              if(rate == Rate_1M)
 344   1              {
 345   2                      tmp &= 0xf7;
 346   2                      HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 347   2              }
 348   1              else if(rate == Rate_2M)
 349   1              {
 350   2                      tmp |= 0x08;
 351   2                      HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 352   2              }
 353   1      }
 354          
 355          // OM6220 切换信道
 356          void HS6220_Change_CH(unsigned char chn)
 357          {
 358   1              if(chn < 0x80)
 359   1                      HS6220_write_byte(HS6220_BANK0_RF_CH, chn);
 360   1      }
 361          
 362          // OM6220 切换功率
 363          void HS6220_Change_Pwr(HS6220_Pwr_TypeDef pwr)
 364          {
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 7   

 365   1              unsigned char tmp;
 366   1      
 367   1              tmp = HS6220_read_byte(HS6220_BANK0_RF_SETUP);
 368   1              tmp &= ~0x47;
 369   1      
 370   1              switch (pwr)
 371   1              {
 372   2                      case Pwr_8db:
 373   2                              tmp |= 0x47;
 374   2                              HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 375   2                      break;
 376   2      
 377   2                      case Pwr_5db:
 378   2                              tmp |= 0x40;
 379   2                              HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 380   2                      break;
 381   2      
 382   2                      case Pwr_4db:
 383   2                              tmp |= 0x07;
 384   2                              HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 385   2                      break;
 386   2      
 387   2                      case Pwr_0db:
 388   2                              tmp |= 0x03;
 389   2                              HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 390   2                      break;
 391   2      
 392   2                      case Pwr_n6db:
 393   2                              tmp |= 0x01;
 394   2                              HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 395   2                      break;
 396   2              
 397   2                      default: // 默认就设置成0db
 398   2                              tmp |= 0x03;
 399   2                              HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 400   2                      break;
 401   2              }
 402   1      }
 403          
 404          // OM6220 切换地址
 405          void HS6220_Change_Addr(unsigned char *buf, unsigned char len)
 406          {
 407   1              if(len <= 6)
 408   1              HS6220_wr_buffer(HS6220_BANK0_RX_ADDR_P0, buf, len); // set address
 409   1      }
 410          
 411          
 412          /*OM6220 接收数据包函数
 413          buf：读取到的数据存放的地方
 414          return：正常读取之后，返回的是读取到的数据包长度
 415          */
 416          unsigned int rf_reset_cnt = D_RF_RESET_CNT;
 417          unsigned char rf_sleep_cnt = D_RF_SLEEP_CNT;
 418          
 419          unsigned char HS6220_ReceivePack(unsigned char *buf)
 420          {
 421   1              unsigned char sta;
 422   1              unsigned char len;
 423   1      
 424   1              sta = HS6220_read_byte(HS6220_BANK0_STATUS);
 425   1      
 426   1              if(HS6220_STATUS_RX_DR & sta)
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 8   

 427   1              {
 428   2                      rf_sleep_cnt = D_RF_SLEEP_CNT;
 429   2                      rf_reset_cnt = D_RF_RESET_CNT;
 430   2                      
 431   2                      len = HS6220_read_byte(HS6220_R_RX_PL_WID);
 432   2                      if(len == HS6220_FIFO_MAX_PACK_SIZE)
 433   2                      {
 434   3                              HS6220_read_buffer(HS6220_R_RX_PAYLOAD, buf, len);
 435   3                      }
 436   2                      else
 437   2                      {
 438   3                              len = 0;
 439   3                      }
 440   2                      
 441   2                      HS6220_CE_Low();
 442   2                      HS6220_Flush_Rx();
 443   2                      HS6220_Clear_All_Irq();
 444   2                      HS6220_CE_High();
 445   2                      
 446   2                      return len;
 447   2              }
 448   1              
 449   1              //以下的复位RF和让RF睡眠唤醒的动作是必须的，不可缺少
 450   1              if(rf_reset_cnt==0) // 如果400ms都没有收到1包数据，则复位RF重新初始化
 451   1              {       //RESET时间范围300~500MS
 452   2                      HS6220_Init();
 453   2                      HS6220_CE_Low();
 454   2                      HS6220_ModeSwitch(HS6220_PRX_Mode);     
 455   2                      HS6220_CE_High();
 456   2                      
 457   2                      rf_sleep_cnt = D_RF_SLEEP_CNT;
 458   2                      rf_reset_cnt = D_RF_RESET_CNT;
 459   2              }
 460   1      
 461   1              if(rf_sleep_cnt==0)// 如果40ms都没有收到1包数据，则让RF睡眠唤醒一次
 462   1              {       //SLEEP时间范围20~50MS
 463   2                      HS6220_CE_Low();
 464   2                      HS6220_Flush_Rx();
 465   2                      HS6220_Clear_All_Irq();
 466   2                      
 467   2                      HS6220_write_byte(HS6220_BANK0_PMU_CTL, 0xae);          
 468   2                      delay_ms(1);// 这里的1ms延时不可缺少，也不能小 
 469   2                      HS6220_write_byte(HS6220_BANK0_PMU_CTL, 0xac);
 470   2                      delay_ms(1);// 这里的1ms延时不可缺少，也不能小
 471   2                      HS6220_CE_High();
 472   2                      
 473   2                      rf_sleep_cnt = D_RF_SLEEP_CNT;          
 474   2              }
 475   1              //以上的复位RF和让RF睡眠唤醒的动作是必须的，不可缺少
 476   1              
 477   1              return 0;
 478   1      }
 479          
 480          
 481          /* OM6220发送数据包函数
 482            buf:要发送的数据包内容指针 
 483            len:数据包的长度，从1到32字节 
 484            cmd: 发送数据包的命令，HS6220_W_TX_PAYLOAD和HS6220_W_TX_PAYLOAD_NOACK
 485          */
 486          void HS6220_SendPack(unsigned char cmd, unsigned char* buf, unsigned char len)
 487          {
 488   1              unsigned char sta,cnt;
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 9   

 489   1      
 490   1              /*
 491   1              sta = HS6220_read_byte(HS6220_BANK0_STATUS);
 492   1              if(!(sta & HS6220_STATUS_TX_FULL))
 493   1              {
 494   1                      HS6220_wr_buffer(cmd, buf, len);
 495   1              }
 496   1              */
 497   1              HS6220_wr_buffer(cmd, buf, len);
 498   1              HS6220_CE_High();
 499   1              //判断发送是否结束
 500   1              cnt = 50;       //time out 5ms
 501   1              while(cnt)
 502   1              {
 503   2                      delay_us(100);
 504   2                      sta = HS6220_read_byte(HS6220_BANK0_STATUS);
 505   2                      if(sta & HS6220_STATUS_TX_DS)
 506   2                      {       //发送结束
 507   3                              _nop_();
 508   3                              _nop_();
 509   3                              _nop_();
 510   3                              break;
 511   3                      }
 512   2                      cnt--;
 513   2              }
 514   1              HS6220_CE_Low();
 515   1      }
 516          
 517          // OM6220 切换RF工作模式函数
 518          void HS6220_ModeSwitch(HS6220_ModeTypeDef mod)
 519          {
 520   1              unsigned char tmp;
 521   1              
 522   1              tmp = HS6220_read_byte(HS6220_BANK0_CONFIG);
 523   1              if(mod != HS6220_PRX_Mode)
 524   1              {
 525   2                      tmp &= 0xFE;
 526   2              }
 527   1              else
 528   1              {
 529   2                      tmp |= 0x01;
 530   2              }
 531   1              HS6220_write_byte(HS6220_BANK0_CONFIG, tmp);
 532   1      
 533   1              if(mod == HS6220_Carrier_Mode)
 534   1              {
 535   2                      tmp = 0Xc7;//0x80 | HS6220_read_byte(HS6220_BANK0_RF_SETUP);
 536   2                      HS6220_write_byte(HS6220_BANK0_RF_SETUP, tmp);
 537   2                      /* 注意：最高位为载波使能位，设置了载波模式之后，CE要拉高，载波才会出来；
 538   2                         如果不要切换频点，功率等，就不要去在操作RF，否则会看不到载波信号的*/
 539   2                      
 540   2              }
 541   1      }
 542          
 543          // OM6220 清中断标志
 544          void HS6220_Clear_All_Irq(void)
 545          {
 546   1              HS6220_write_byte(HS6220_BANK0_STATUS, 0x70);
 547   1      }
 548          
 549          // OM6220 清空TX FIFO
 550          void HS6220_Flush_Tx(void)
C51 COMPILER V9.54   HS6220_RF                                                             06/16/2023 10:23:33 PAGE 10  

 551          {
 552   1              HS6220_Operation(HS6220_FLUSH_TX);
 553   1      }
 554          
 555          // OM6220 清空RX FIFO
 556          void HS6220_Flush_Rx(void)
 557          {
 558   1              HS6220_Operation(HS6220_FLUSH_RX);
 559   1      }
 560          
 561          // OM6220 CE拉高
 562          void HS6220_CE_High(void)
 563          {
 564   1              HS6220_Operation(HS6220_CMD_CE_HIGH);;
 565   1      }
 566          
 567          // OM6220 CE拉低
 568          void HS6220_CE_Low(void)
 569          {
 570   1              HS6220_Operation(HS6220_CMD_CE_LOW);
 571   1      }
 572          
 573          // 读取MO6220接收到的数据包长度的函数
 574          unsigned char HS6220_read_payload_length(void)
 575          {
 576   1              return HS6220_read_byte(HS6220_R_RX_PL_WID);
 577   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1079    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =      3      21
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
