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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC:讀寫24LCxx系列的EEPROM的實(shí)例C語(yǔ)言程序

          PIC:讀寫24LCxx系列的EEPROM的實(shí)例C語(yǔ)言程序

          作者: 時(shí)間:2011-05-06 來(lái)源:網(wǎng)絡(luò) 收藏

          //*
          //***********************************************
          void EE_SEQU_Read(unsigned char ctrl,unsigned char addr,unsigned char length,unsigned char *dptr)
          {
          IdleI2C(); // ensure module is idle
          StartI2C(); // Start condition
          I2C_Done(); // Wait Start condition completed

          本文引用地址:http://cafeforensic.com/article/172809.htm

          WriteI2C(ctrl); // Write Control to
          while(SSPCON2bits.ACKSTAT); // test for ACK condition, if received
          I2C_Done(); // Clear SSPIF flag

          WriteI2C(addr); // Write Address to
          while(SSPCON2bits.ACKSTAT); // test for ACK condition, if received
          I2C_Done(); // Clear SSPIF flag

          RestartI2C(); // initiate Restart condition
          I2C_Done();

          WriteI2C(ctrl+1); // Write Control to
          while(SSPCON2bits.ACKSTAT); // Test for ACK condition, if received
          I2C_Done(); // Clear SSPIF flag

          while (length!=0)
          {
          *dptr=ReadI2C(); // Enable I2C Receiver Store EEPROM data to Point buffer
          I2C_Done();
          dptr++;
          length--;

          if (length==0) NotAckI2C();
          else AckI2C(); // Continue read next data, send a acknowledge to EEPROM

          I2C_Done();
          }

          StopI2C(); // send STOP condition
          I2C_Done(); // wait until stop condition is over
          }

          //***********************************************
          //* Check I2C action that is completed *
          //***********************************************
          void I2C_Done(void)
          {
          while (!PIR1bits.SSPIF); // Completed the action when the SSPIF is Hi.
          PIR1bits.SSPIF=0; // Clear SSPIF
          }

          //************************************************
          //* Initial I2C Master Mode with 7 bits Address *
          //* Clock Speed : 100KHz @4MHz *
          //************************************************
          void Initialize_I2C_Master(void)
          {
          OpenI2C(MASTER,SLEW_ON);
          SSPADD= 9;
          }

          c語(yǔ)言相關(guān)文章:c語(yǔ)言教程



          上一頁(yè) 1 2 3 下一頁(yè)

          評(píng)論


          相關(guān)推薦

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

          關(guān)閉