⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iic.lst

📁 单片机实现消息队列的例子
💻 LST
📖 第 1 页 / 共 2 页
字号:
 197   1              {
 198   2                      return(FALSE);
 199   2              }
 200   1              
 201   1              for(i = 0; i < len; i++)
 202   1              {   
 203   2                      if(!SendByte(*source))               /*发送数据*/
 204   2                      {
 205   3                              return(FALSE);
 206   3                      }
 207   2                      source++;
 208   2              } 
 209   1              StopI2c();                 /*结束总线*/ 
 210   1              return(TRUE);
 211   1      }
 212          
 213          
 214          
 215          extern bool iic_rcv_str(byte SlaveAddress, byte address, byte *source, byte len)
 216          {
 217   1              byte i;
 218   1      
 219   1              StartI2c();               /*启动总线*/
 220   1              
 221   1              if(!SendByte(SlaveAddress))           /*发送器件地址*/
 222   1              {
 223   2                      return(FALSE);
 224   2              }
 225   1              
 226   1              if(!SendByte(address))            /*发送器件子地址*/
 227   1              {
 228   2                      return(FALSE);
 229   2              }
 230   1              
 231   1              StartI2c();
 232   1              
 233   1              if(!SendByte(SlaveAddress+1))
 234   1              {
 235   2                      return(FALSE);
 236   2              }
 237   1              
 238   1              for(i = 0; i < len - 1; i++)
 239   1              {   
 240   2                      *source = RcvByte();               /*接收数据*/
C51 COMPILER V7.10   IIC                                                                   12/14/2004 10:51:17 PAGE 5   

 241   2                      AckI2c(FALSE);                /*发送就答位*/  
 242   2                      source++;
 243   2              } 
 244   1              
 245   1              *source = RcvByte();
 246   1              
 247   1              AckI2c(TRUE);                 /*发送非应位*/
 248   1              
 249   1              StopI2c();                    /*结束总线*/ 
 250   1              return(TRUE);
 251   1      }
 252          
 253          
 254          extern bool iiv_send_long_str(byte SlaveAddress, word address, byte *source, byte len)
 255          {
 256   1              byte i;
 257   1      
 258   1              StartI2c();               /*启动总线*/
 259   1              
 260   1              if(!SendByte(SlaveAddress))            /*发送器件地址*/
 261   1              {
 262   2                      return(FALSE);
 263   2              }
 264   1      
 265   1              if(!SendByte(HBYTE(address)))            /*发送器件地址*/
 266   1              {
 267   2                      return(FALSE);
 268   2              }
 269   1              
 270   1              if(!SendByte(LBYTE(address)))            /*发送器件子地址*/
 271   1              {
 272   2                      return(FALSE);
 273   2              }
 274   1              
 275   1              for(i = 0; i < len; i++)
 276   1              {   
 277   2                      if(!SendByte(*source))               /*发送数据*/
 278   2                      {
 279   3                              return(FALSE);
 280   3                      }
 281   2                      source++;
 282   2              } 
 283   1              StopI2c();                 /*结束总线*/ 
 284   1              return(TRUE);
 285   1      }
 286          
 287          
 288          extern bool iic_rcv_long_str(byte SlaveAddress, word address, byte *source, byte len)
 289          {
 290   1              byte i;
 291   1      
 292   1              StartI2c();               /*启动总线*/
 293   1              
 294   1              if(!SendByte(SlaveAddress))           /*发送器件地址*/
 295   1              {
 296   2                      return(FALSE);
 297   2              }
 298   1              
 299   1              if(!SendByte(HBYTE(address)))            /*发送器件子地址*/
 300   1              {
 301   2                      return(FALSE);
 302   2              }
C51 COMPILER V7.10   IIC                                                                   12/14/2004 10:51:17 PAGE 6   

 303   1              
 304   1              if(!SendByte(LBYTE(address)))            /*发送器件子地址*/
 305   1              {
 306   2                      return(FALSE);
 307   2              }
 308   1              
 309   1              StartI2c();
 310   1              
 311   1              if(!SendByte(SlaveAddress+1))
 312   1              {
 313   2                      return(FALSE);
 314   2              }
 315   1              
 316   1              for(i = 0; i < len - 1; i++)
 317   1              {   
 318   2                      *source = RcvByte();               /*发送数据*/
 319   2                      AckI2c(FALSE);                /*发送就答位*/  
 320   2                      source++;
 321   2              } 
 322   1              
 323   1              *source = RcvByte();
 324   1              
 325   1              AckI2c(TRUE);                 /*发送非应位*/
 326   1              
 327   1              StopI2c();                    /*结束总线*/ 
 328   1              return(TRUE);
 329   1      }
 330          
 331          
 332          extern bool iic_24c64_write(word wAddr, byte *source, byte len)
 333          {       
 334   1              byte idata i;
 335   1              byte idata j;
 336   1              byte idata temp;
 337   1              temp = (byte)wAddr & 0x1F;
 338   1              
 339   1              if((32-temp) > len)
 340   1              {
 341   2                      return(iiv_send_long_str(CAT24WC64, wAddr, source, len));
 342   2              }
 343   1              else
 344   1              {
 345   2                      if(!iiv_send_long_str(CAT24WC64, wAddr, source, 32 - temp))
 346   2                      {
 347   3                              return(FALSE);
 348   3                      }
 349   2              }
 350   1              
 351   1              j = (len + temp -32) >> 5;
 352   1              //printf("%x\n", (word)j);
 353   1              wAddr = (wAddr & 0xFFE0) + 0x20;
 354   1              source = source + (32 - temp);
 355   1              
 356   1              if(j)
 357   1              {
 358   2                      for(i = 0; i < j; i++)
 359   2                      {
 360   3                              delay(1000);
 361   3                              if(!iiv_send_long_str(CAT24WC64, wAddr, source, 32))
 362   3                              {
 363   4                                      return(FALSE);
 364   4                              }
C51 COMPILER V7.10   IIC                                                                   12/14/2004 10:51:17 PAGE 7   

 365   3                              wAddr = wAddr + 0x20;
 366   3                              source = source + 0x20;
 367   3                      }
 368   2              }
 369   1      
 370   1              temp = (len + temp - 32) & 0x1F;
 371   1              //printf("%x\n", (word)wAddr);
 372   1              //printf("%x\n", (word)source);
 373   1              //printf("%x\n", (word)temp);
 374   1              if(temp)
 375   1              {
 376   2                      delay(1000);
 377   2                      return(iiv_send_long_str(CAT24WC64, wAddr, source, temp));
 378   2              }
 379   1      }
 380          
 381          
 382          extern bool iic_24c64_read(word wAddr, byte *source, byte len)
 383          {
 384   1              return(iic_rcv_long_str(CAT24WC64, wAddr, source, len));
 385   1      }
 386          
 387          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    779    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----      38
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       3
   IDATA SIZE       =   ----       3
   BIT SIZE         =      1       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -