在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,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è)計應用 > 讀寫24LCxx系列的EEPROM的C語言程序?qū)嵗?/p>

      讀寫24LCxx系列的EEPROM的C語言程序?qū)嵗?/h1>
      作者: 時間:2012-07-18 來源:網(wǎng)絡(luò) 收藏

      #pragma code

      本文引用地址:http://www.biyoush.com/article/171142.htm

      //************************************************
      //* Function: isr_high(void) *
      //* High priority interrupt for Timer2 *
      //************************************************
      #pragma interrupt isr_high

      void isr_high(void)
      {
      PIR1bits.TMR2IF=0; // Clear Timer2 interrupt Flag

      if (Debounce==0)
      {
      if (!SW2)
      { P_SW2=1; Debounce =Bounce_Time; }
      if (!SW6)
      { P_SW6=1; Debounce =Bounce_Time; }
      }
      else if (SW2 SW6)Debounce--;
      else Debounce =Bounce_Time;
      }
      #pragma code

      //***********************************************
      //* Write a Byte to
      //* - ctrl : Control Byte of
      //* - addr : Location of
      //* - data : Data Byte of EEPROM
      //***********************************************

      void Initialize_Timer2(void)
      {

      RCONbits.IPEN=1; // Enable Interrupt Priority bit
      IPR1bits.TMR2IP=1; // Set Timer2 for High Priority
      INTCONbits.GIEH=1; // Enable High Priority Interrupt

      OpenTimer2 (TIMER_INT_ON // Turn On the Timer2 with Interrupt
      T2_PS_1_4 // (4Mhz/4) [4*10*(99+1)] = 4mS */
      T2_POST_1_10);

      PR2 = 99;
      }

      //***********************************************
      //* Write a Byte to EEPROM *
      //* - ctrl : Control Byte of EEPROM *
      //* - addr : Location of EEPROM *
      //* - data : Data Byte of EEPROM *
      //***********************************************
      void EEPROM_Write(unsigned char ctrl,unsigned char addr,unsigned char data)
      {
      IdleI2C(); // ensure module is idle
      StartI2C(); // Start condition
      I2C_Done(); // Wait Start condition completed and clear SSPIF flag

      WriteI2C(ctrl); // Write Control+Write to EEPROM Check BF flag
      while(SSPCON2bits.ACKSTAT); // wait until received the Acknowledge from EEPROM
      I2C_Done(); // Clear SSPIF flag

      WriteI2C(addr); // Write Address to EEPROM
      while(SSPCON2bits.ACKSTAT); // wait until received the Acknowledge from EEPROM
      I2C_Done();

      WriteI2C(data); // Write Data to EEPROM
      while(SSPCON2bits.ACKSTAT); // wait until received the Acknowledge from EEPROM
      I2C_Done();

      StopI2C(); // Stop condition
      I2C_Done(); // Wait the Stop condition completed
      }

      //***********************************************
      //* Pae Write to EEPROM
      //*
      //* - ctrl : Control Byte of EEPROM
      //* - addr : Location of EEPROM
      //* - length : Write counter
      //* - *dptr : RAM point --> EEPROM
      //*
      //***********************************************
      void EE_Page_Write(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

      WriteI2C(ctrl); // Write Control+Write to EEPROM Check BF flag
      while(SSPCON2bits.ACKSTAT); // wait until received the Acknowledge from EEPROM
      I2C_Done(); // Clear SSPIF flag

      WriteI2C(addr); // Write Address to EEPROM
      while(SSPCON2bits.ACKSTAT); // wait until received the Acknowledge from EEPROM
      I2C_Done();

      while (length!=0) // Check write completed ?
      {
      WriteI2C(*dptr); // Write data to EEPROM
      while(SSPCON2bits.ACKSTAT); // wait until received the Acknowledge from EEPROM
      I2C_Done();
      dptr++; // Point to next byte
      length--;
      }

      StopI2C(); // Stop condition
      I2C_Done(); // Wait the Stop condition completed
      }

      //***********************************************
      //* EEPROM Acknowledge Polling *
      //* -- The routine will polling the ACK *
      //* response from EEPROM *
      //* -- ACK=0 return *
      //* -- ACK=1 send Restart loop check *
      //***********************************************
      void EEPROM_ACK(unsigned char ctrl)
      {
      unsigned char i;

      IdleI2C(); // ensure module is idle
      StartI2C(); // Start condition
      I2C_Done(); // Wait Start condition completed

      WriteI2C(ctrl); // Write Control to EEPROM (WRITE)
      I2C_Done(); // Clear SSPIF flag

      while (SSPCON2bits.ACKSTAT) // test for Acknowledge from EEPROM
      {
      for (i=0;i100;i++); // Delay for next Repet-Start

      RestartI2C(); // initiate Repet-Start condition
      I2C_Done(); // Wait Repet-Start condition completed

      WriteI2C(ctrl); // Write Control to EEPROM (WRITE)
      I2C_Done(); // Clear SSPIF flag
      }
      StopI2C(); // send STOP condition
      I2C_Done(); // wait until stop condition is over
      }

      //***********************************************
      //* Random Read a Byte from EEPROM *
      //* - ctrl : Control Byte of EEPROM (Write) *
      //* (Ctrl +1 ) : Read Command *
      //* - addr : Address Byte of EEPROM *
      //* - Return : Read Data from EEPROM *
      //***********************************************
      unsigned char EEPROM_Read(unsigned char ctrl,unsigned char addr)
      {
      unsigned char f;

      IdleI2C(); // ensure module is idle
      StartI2C(); // Start condition
      I2C_Done(); // Wait Start condition completed

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

      WriteI2C(addr); // Write Address to EEPROM
      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 EEPROM
      while(SSPCON2bits.ACKSTAT); // test for ACK condition, if received
      I2C_Done(); // Clear SSPIF flag

      f=ReadI2C(); // Enable I2C Receiver wait BF=1 until received data
      I2C_Done(); // Clear SSPIF flag

      NotAckI2C(); // Genarate Non_Acknowledge to EEPROM
      I2C_Done();

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

      return(f); // Return Data from EEPROM
      }

      //***********************************************
      //* Sequential Read from EEPROM
      //*
      //* - ctrl : Control Byte of EEPROM
      //* - addr : Location of EEPROM
      //* - length : Read counter
      //* - *dptr : Store EEPROM data to RAM

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




      評論


      相關(guān)推薦

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

      關(guān)閉
      ×

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