在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<abbr id="27omo"></abbr>

<menu id="27omo"><dl id="27omo"></dl></menu>
    • <label id="27omo"><tt id="27omo"></tt></label>

      新聞中心

      EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 用戶態(tài)應(yīng)用程序直接訪問I2C驅(qū)動

      用戶態(tài)應(yīng)用程序直接訪問I2C驅(qū)動

      作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
      #include "stdio.h"
      #include "stdlib.h"
      #include "string.h"
      #include "sys/types.h"
      #include "sys/stat.h"
      #include "fcntl.h"
      #include "i2c-dev.h" //調(diào)用來自“i2c-tools-3.1.0.tar.bz2”,包含操作I2C函數(shù)的聲明
      // i2c_usr_test r addr
      * i2c_usr_test w addr val
      //
      void print_usage(char *file)
      {
      printf("%s r addrn", file);
      printf("%s w addr valn", file);
      }
      int main(int argc, char **argv)
      {
      int fd;
      unsigned char addr, data;
      int dev_addr;
      if ((argc != 5) && (argc != 6))
      {
      print_usage(argv[0]);
      return -1;
      }
      fd = open(argv[1], O_RDWR);
      if (fd < 0)
      {
      printf("cant open %sn", argv[1]);
      return -1;
      }
      dev_addr = strtoul(argv[2], NULL, 0);
      if (ioctl(fd, I2C_SLAVE, dev_addr) < 0)
      {
      // ERROR HANDLING; you can check errno to see what went wrong //
      printf("set addr error!n");
      return -1;
      }
      if (strcmp(argv[3], "r") == 0)
      {
      addr = strtoul(argv[4], NULL, 0);
      data = i2c_smbus_read_word_data(fd, addr);
      printf("data: %c, %d, 0x%2xn", data, data, data);
      }
      else if ((strcmp(argv[3], "w") == 0) && (argc == 6))
      {
      addr = strtoul(argv[4], NULL, 0);
      data = strtoul(argv[5], NULL, 0);
      i2c_smbus_write_byte_data(fd, addr, data);
      }
      else
      {
      print_usage(argv[0]);
      return -1;
      }
      return 0;
      }


      評論


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

      關(guān)閉
      ×

      “芯”朋友见面大会
      珠海|11.14|泰克“芯”朋友见面大会珠海站|泰克带您从测试角度看半导体的整条产业链,快来报名抢位吧>>