亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? f31x_smbus_multimaster.c

?? C8051F31系列單片機的例子
?? C
?? 第 1 頁 / 共 2 頁
字號:
//
// Timer3 configured for use by the SMBus low timeout detect feature as
// follows:
// - Timer3 in 16-bit auto-reload mode
// - SYSCLK/12 as Timer3 clock source
// - Timer3 reload registers loaded for a 25ms overflow period
// - Timer3 pre-loaded to overflow after 25ms
// - Timer3 enabled
//
void Timer3_Init (void)
{
   TMR3CN = 0x00;                      // Timer3 configured for 16-bit auto-
                                       // reload, low-byte interrupt disabled

   CKCON &= ~0x40;                     // Timer3 uses SYSCLK/12

   TMR3RL = -(SYSCLK/12/40);           // Timer3 configured to overflow after
   TMR3 = TMR3RL;                      // ~25ms (for SMBus low timeout detect):
                                       // 1/.025 = 40

   EIE1 |= 0x80;                       // Timer3 interrupt enable
   TMR3CN |= 0x04;                     // Start Timer3
}

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configure the Crossbar and GPIO ports.
//
// P0.0   digital   open-drain    SMBus SDA
// P0.1   digital   open-drain    SMBus SCL
//
// P0.7   digital   open-drain    SW (switch)
//
// P3.3   digital   push-pull     LED
//
// all other port pins unused
//
// Note: If the SMBus is moved, the SCL and SDA sbit declarations must also
// be adjusted.
//
void PORT_Init (void)
{
   P0MDOUT = 0x00;                     // All P0 pins open-drain output

   P3MDOUT |= 0x08;                    // Make the LED (P3.3) a push-pull
                                       // output

   XBR0 = 0x04;                        // Enable SMBus pins
   XBR1 = 0x40;                        // Enable crossbar and weak pull-ups

   P0 = 0xFF;
}

//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Timer0 Interrupt Service Routine (ISR)
//-----------------------------------------------------------------------------
//
// Timer0 blinks the LED when instructed by the other multimaster.
//
void Timer0_ISR (void) interrupt 1
{
   static unsigned char count = 0;     // Count up to 256 Timer0 interrupts
                                       // before switching the LED
                                       // otherwise, it won't be visible to
                                       // the eye
   if (count == 255)
   {
      LED = ~LED;                      // Turn the LED on and off

      count = 0;
   }
   else
   {
      count++;
   }
}

//-----------------------------------------------------------------------------
// SMBus Interrupt Service Routine (ISR)
//-----------------------------------------------------------------------------
//
// SMBus ISR state machine
// - Master only implementation - no slave or arbitration states defined
// - Incoming master data is written to global variable <SMB_DATA_IN_MASTER>
// - Incoming slave data is written to global variable <SMB_DATA_IN_SLAVE>
// - Outgoing master data is read from global variable <SMB_DATA_OUT_MASTER>
// - Outgoing slave data is read from global variable <SMB_DATA_OUT_SLAVE>
//
void SMBus_ISR (void) interrupt 7
{
   bit M_FAIL = 0;                     // Used by the master states to flag a
                                       // bus error condition
                                       // transfers

   static bit ADDR_SEND = 0;           // Used by the ISR to flag byte
                                       // transmissions as slave addresses

   static bit arbitration_lost = 0;    // Used by the ISR to flag whether
                                       // arbitration was lost and the transfer
                                       // should be rescheduled

   // Normal operation
   switch (SMB0CN & 0xF0)              // Status vector
   {
      // MASTER ---------------------------------------------------------------

      // Master Transmitter/Receiver: START condition transmitted.
      case SMB_MTSTA:
         SMB0DAT = TARGET;             // Load address of the target slave
         SMB0DAT &= 0xFE;              // Clear the LSB of the address for the
                                       // R/W bit
         SMB0DAT |= SMB_RW;            // Load R/W bit
         STA = 0;                      // Manually clear START bit
         ADDR_SEND = 1;

         break;

      // Master Transmitter: Data byte transmitted
      case SMB_MTDB:

         if (ARBLOST == 0)             // Check for a bus error
         {
            if (ACK)                   // Slave ACK?
            {
               if (ADDR_SEND)          // If the previous byte was a slave
               {                       // address,
                  ADDR_SEND = 0;       // Next byte is not a slave address
                  if (SMB_RW == WRITE) // If this transfer is a WRITE,
                  {
                     // Send data byte
                     SMB0DAT = SMB_DATA_OUT_MASTER;
                  }
                  else {}              // If this transfer is a READ,
                                       // proceed with transfer without
                                       // writing to SMB0DAT (switch
                                       // to receive mode)
               }
               else                    // If previous byte was not a slave
               {                       // address,
                  STO = 1;             // Set STO to terminate transfer
                  SMB_BUSY = 0;        // And free SMBus interface
               }
            }
            else                       // If slave NACK,
            {
               STO = 1;                // Send STOP condition, followed
               STA = 1;                // By a START
               NUM_ERRORS++;           // Indicate error
            }
         }
         else
         {
            M_FAIL = 1;                // If a bus error occurs, reset
         }

         break;

      // Master Receiver: byte received
      case SMB_MRDB:

         if (ARBLOST == 0)             // Check for a bus error
         {
            // Store received byte
            SMB_DATA_IN_MASTER = SMB0DAT;
            SMB_BUSY = 0;              // Free SMBus interface
            ACK = 0;                   // Send NACK to indicate last byte
                                       // of this transfer

            STO = 1;                   // Send STOP to terminate transfer
         }
         else
         {
            M_FAIL = 1;                // If a bus error occurs, reset
         }

         break;

      // ----------------------------------------------------------------------

      // SLAVE ----------------------------------------------------------------

      // Slave Receiver: Start+Address received
      case  SMB_SRADD:

         if (ARBLOST == 1)
         {
            arbitration_lost = 1;      // Indicate lost arbitration
         }

         STA = 0;                      // Clear STA bit
         if((SMB0DAT&0xFE) == (MY_ADDR&0xFE)) // Decode address
         {                             // If the received address matches,
            ACK = 1;                   // ACK the received slave address
            if((SMB0DAT&0x01) == READ) // If the transfer is a master READ
            {
               // Prepare outgoing byte
               SMB0DAT = SMB_DATA_OUT_SLAVE;
            }
         }
         else                          // If received slave address does not
         {                             // match,
            ACK = 0;                   // NACK received address
         }

         break;

      // Slave Receiver: Data received
      case  SMB_SRDB:

         if (ARBLOST == 0)             // No bus error
         {

            // Store incoming data
            SMB_DATA_IN_SLAVE = SMB0DAT;

            DATA_READY = 1;            // Indicate new data received
            ACK = 1;                   // ACK received data
         }
         else                          // Bus error detected
         {
            STA = 0;
            STO = 0;
            ACK = 0;
         }

         break;

      // Slave Receiver: Stop received while either a Slave Receiver or Slave
      // Transmitter
      case  SMB_SRSTO:

         if (arbitration_lost == 1)
         {
            STA = 1;                   // The ARBLOST bit indicated the master
                                       // lost arbitration
                                       // reschedule the transfer

            arbitration_lost = 0;
         }

         STO = 0;                      // STO must be cleared by software when
                                       // a STOP is detected as a slave
         break;

      // Slave Transmitter: Data byte transmitted
      case  SMB_STDB:
                                       // No action required;
                                       // one-byte transfers
                                       // only for this example
         break;

      // Slave Transmitter: Arbitration lost, Stop detected
      //
      // This state will only be entered on a bus error condition.
      // In normal operation, the slave is no longer sending data or has
      // data pending when a STOP is received from the master, so the TXMODE
      // bit is cleared and the slave goes to the SRSTO state.
      case  SMB_STSTO:

         STO = 0;                      // STO must be cleared by software when
                                       // a STOP is detected as a slave
         break;

      // Default: all other cases undefined

      // ----------------------------------------------------------------------

      default:
         M_FAIL = 1;                   // Indicate failed transfer
                                       // and handle at end of ISR
         break;

   } // end switch

   if (M_FAIL)                         // If the transfer failed,
   {
      SMB0CF &= ~0x80;                 // Reset communication
      SMB0CF |= 0x80;
      STA = 0;
      STO = 0;
      ACK = 0;

      SMB_BUSY = 0;                    // Free SMBus

      M_FAIL = 0;
      LED = 0;

      NUM_ERRORS++;                    // Indicate an error occurred
   }

   SI = 0;                             // Clear interrupt flag
}

//-----------------------------------------------------------------------------
// Timer3 Interrupt Service Routine (ISR)
//-----------------------------------------------------------------------------
//
// A Timer3 interrupt indicates an SMBus SCL low timeout.
// The SMBus is disabled and re-enabled here
//
void Timer3_ISR (void) interrupt 14
{
   SMB0CF &= ~0x80;                    // Disable SMBus
   SMB0CF |= 0x80;                     // Re-enable SMBus
   TMR3CN &= ~0x80;                    // Clear Timer3 interrupt-pending flag
   STA = 0;
   SMB_BUSY = 0;                       // Free SMBus
}

//-----------------------------------------------------------------------------
// Support Functions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// SMB_Write
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Writes a single byte to the slave with address specified by the <TARGET>
// variable.
// Calling sequence:
// 1) Write target slave address to the <TARGET> variable
// 2) Write outgoing data to the <SMB_data_out> variable
// 3) Call SMB_Write()
//
void SMB_Write (void)
{
   while (SMB_BUSY);                   // Wait for SMBus to be free.
   SMB_BUSY = 1;                       // Claim SMBus (set to busy)
   SMB_RW = 0;                         // Mark this transfer as a WRITE
   STA = 1;                            // Start transfer
}

//-----------------------------------------------------------------------------
// Blink_LED
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Starts the LED blinking.
//
void Blink_LED (void)
{
   TR0 = 1;
}

//-----------------------------------------------------------------------------
// Stop_LED
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Stops the LED from blinking.
//
void Stop_LED (void)
{
   TR0 = 0;

   LED = 0;                            // Turn the LED off when it's not
                                       // blinking
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天堂一区二区在线免费观看| 日本电影欧美片| 日韩一级片在线观看| 一区二区在线观看不卡| 成人高清在线视频| 中文字幕在线观看一区| 成人avav在线| 亚洲成a人v欧美综合天堂| 欧美丝袜自拍制服另类| 亚洲综合色成人| 制服丝袜av成人在线看| 蜜乳av一区二区三区| 久久久久国产一区二区三区四区| 韩日欧美一区二区三区| 国产精品嫩草影院av蜜臀| eeuss鲁片一区二区三区 | 欧美午夜精品免费| 久久精品久久99精品久久| 国产精品乱码久久久久久| 色婷婷av久久久久久久| 日韩中文字幕1| 国产精品久久久久久一区二区三区| 欧美影院午夜播放| 国产99久久久精品| 亚洲综合视频网| 欧美大白屁股肥臀xxxxxx| 国产成人精品网址| 日本 国产 欧美色综合| 亚洲欧美视频在线观看视频| 91精品在线免费观看| 91免费看视频| 国产一区二区毛片| 美女爽到高潮91| 亚洲韩国精品一区| 亚洲激情图片小说视频| 国产日产欧美精品一区二区三区| 欧美图区在线视频| 99精品久久免费看蜜臀剧情介绍| 欧美aaa在线| 日本不卡视频在线| 亚洲成人第一页| 亚洲va欧美va人人爽| 亚洲综合色在线| 一区二区免费在线播放| 亚洲主播在线观看| 亚洲黄色性网站| 一区二区三区波多野结衣在线观看 | 亚洲在线视频网站| 亚洲成人av一区二区三区| 亚洲精品第一国产综合野| 亚洲男人都懂的| 午夜电影一区二区三区| 麻豆精品一区二区| 精品亚洲成a人在线观看| 国产精品综合在线视频| aa级大片欧美| 欧美日韩国产免费一区二区 | 7777精品伊人久久久大香线蕉| 欧美日韩视频不卡| 久久久久久久久久电影| 136国产福利精品导航| 亚洲网友自拍偷拍| 黄色资源网久久资源365| 成人高清免费在线播放| 欧美性感一区二区三区| 久久色在线视频| 中文字幕中文字幕在线一区| 亚洲制服欧美中文字幕中文字幕| 久久99久久精品| 91色|porny| 精品久久久久久久一区二区蜜臀| 中文字幕欧美一| 激情久久久久久久久久久久久久久久| 福利一区福利二区| 日韩欧美久久久| 亚洲人成小说网站色在线| 日韩成人伦理电影在线观看| 成人自拍视频在线观看| 日韩一区二区免费电影| 亚洲欧美日韩人成在线播放| 韩国v欧美v日本v亚洲v| 国产色综合一区| 激情五月激情综合网| 欧美日韩美女一区二区| 亚洲天堂福利av| 国产成人精品免费网站| 欧美电视剧在线观看完整版| 亚洲成人www| 欧美日韩一区久久| 亚洲激情中文1区| 一本一道综合狠狠老| 国产精品久久久久久久久动漫 | 精品一区二区三区视频| 日韩精品一区二区三区中文不卡| 亚洲第一电影网| 欧美日韩在线播放一区| 亚洲国产日韩av| 欧美日韩免费不卡视频一区二区三区| 亚洲你懂的在线视频| 欧美三区免费完整视频在线观看| 自拍偷自拍亚洲精品播放| 9191久久久久久久久久久| 日韩福利电影在线| 宅男噜噜噜66一区二区66| 日本成人在线不卡视频| 久久综合网色—综合色88| 丁香激情综合五月| 亚洲一区自拍偷拍| 欧美一区二区在线播放| 免费的国产精品| 欧美国产97人人爽人人喊| 99国产精品国产精品久久| 日日夜夜免费精品| 久久综合久久久久88| 成人av小说网| 日韩精品亚洲一区| 亚洲欧洲国产日本综合| 欧美一区二区三区日韩| 国产成人免费视| 午夜精品视频在线观看| 国产欧美日韩另类一区| 国产精品美女一区二区在线观看| 在线欧美一区二区| 国产九九视频一区二区三区| 亚洲一区二区三区国产| 久久久99精品免费观看不卡| 欧洲一区二区三区免费视频| 国产精品99久| 麻豆成人久久精品二区三区红| 国产精品的网站| 国产亚洲精品久| 欧美综合一区二区三区| 99视频精品免费视频| 国产成人免费在线| 韩国女主播成人在线| 天堂va蜜桃一区二区三区漫画版| 国产精品电影院| 久久久精品综合| 久久久久久久电影| 26uuu精品一区二区| 精品精品国产高清a毛片牛牛| 久久久夜色精品亚洲| 久久亚洲影视婷婷| 91精品国产欧美一区二区| 欧美日韩国产欧美日美国产精品| 一本高清dvd不卡在线观看| 成人丝袜高跟foot| 成人午夜视频福利| 成人免费高清在线观看| 成人性色生活片| 色诱亚洲精品久久久久久| 99久久er热在这里只有精品15| av不卡在线播放| 色狠狠一区二区| 4438成人网| 久久人人爽人人爽| 国产精品久久久久久亚洲伦| 精品一二三四在线| 粉嫩av一区二区三区粉嫩| 色国产综合视频| 制服.丝袜.亚洲.中文.综合| 欧美一区二区三区免费观看视频| 精品国产91久久久久久久妲己 | 激情欧美一区二区三区在线观看| 国产精品一区一区三区| 丰满亚洲少妇av| 欧美日韩你懂的| 欧美激情中文不卡| 麻豆精品一区二区三区| www.欧美日韩| 欧美一级二级三级蜜桃| 中文一区在线播放| 美女视频网站久久| 91久久国产最好的精华液| 欧美成人欧美edvon| 亚洲福利一区二区| 99免费精品在线| 色94色欧美sute亚洲线路一ni | 欧美一区二区三区四区视频| 国产精品美女久久久久aⅴ国产馆| 国产一区日韩二区欧美三区| 欧美成人免费网站| 国产精品1区2区3区| 欧美极品另类videosde| 久久国内精品自在自线400部| 91久久精品一区二区三区| 亚洲精品视频免费看| 一本大道久久精品懂色aⅴ| 中文字幕不卡在线| 丁香婷婷综合激情五月色| 久久九九全国免费| 国产一区二区按摩在线观看| 精品国产亚洲在线| 久久99最新地址| 久久免费美女视频| 国产91对白在线观看九色| 欧美韩国日本不卡| 91精品1区2区| 午夜av电影一区| 久久女同精品一区二区|