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

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

?? f31x_smbus_slave.c

?? C8051F31系列單片機的例子
?? C
字號:
//-----------------------------------------------------------------------------
// F31x_SMBus_Slave.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Example software to demonstrate the C8051F30x SMBus interface in Slave mode
// - Interrupt-driven SMBus implementation
// - Only slave states defined
// - 1-byte SMBus data holder used for both transmit and receive
// - Timer1 used as SMBus clock rate (used only for free timeout detection)
// - Timer3 used by SMBus for SCL low timeout detection
// - ARBLOST support included
// - Pinout:
//    P0.0 -> SDA (SMBus)
//    P0.1 -> SCL (SMBus)
//
//    P3.0 -> C2D (debugging interface)
//
//    P3.3 -> LED (on the 'F310 TB)
//
//    all other port pins unused
//
// How To Test:
//
// 1) Download code to a 'F31x device that is connected to a SMBus master.
// 2) Run the code.  The slave code will write data and read data from the
//    same data byte, so a successive write and read will effectively echo the
//    data written.  To verify that the code is working properly, verify on the
//    master that the data written is the same as the data received.
//
//
// FID:            31X000004
// Target:         C8051F31x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -02 MAR 2006
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <C8051F310.h>

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define  SYSCLK         24500000       // System clock frequency in Hz

#define  SMB_FREQUENCY  10000          // Target SMBus frequency
                                       // This example supports between 10kHz
                                       // and 100kHz

#define  WRITE          0x00           // SMBus WRITE command
#define  READ           0x01           // SMBus READ command

#define  SLAVE_ADDR     0xF0           // Device addresses (7 bits,
                                       // lsb is a don't care)

// Status vector - top 4 bits only
#define  SMB_SRADD      0x20           // (SR) slave address received
                                       //    (also could be a lost
                                       //    arbitration)
#define  SMB_SRSTO      0x10           // (SR) STOP detected while SR or ST,
                                       //    or lost arbitration
#define  SMB_SRDB       0x00           // (SR) data byte received, or
                                       //    lost arbitration
#define  SMB_STDB       0x40           // (ST) data byte transmitted
#define  SMB_STSTO      0x50           // (ST) STOP detected during a
                                       //    transaction; bus error
// End status vector definition

//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------

unsigned char SMB_DATA;                // Global holder for SMBus data.
                                       // All receive data is written
                                       // here;
                                       // all transmit data is read
                                       // from here

bit DATA_READY = 0;                    // Set to '1' by the SMBus ISR
                                       // when a new data byte has been
                                       // received.

// 16-bit SFR declarations
sfr16    TMR3RL   = 0x92;              // Timer3 reload registers
sfr16    TMR3     = 0x94;              // Timer3 counter registers

sbit LED = P3^3;                       // LED on port P3.3

//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------

void SMBus_Init (void);
void Timer1_Init (void);
void Timer3_Init (void);
void Port_Init (void);

void SMBus_ISR (void);
void Timer3_ISR (void);

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//
// Main routine performs all configuration tasks, then waits for SMBus
// communication.
//
void main (void)
{
   PCA0MD &= ~0x40;                    // WDTE = 0 (Disable watchdog
                                       // timer)




   OSCICN |= 0x03;                     // Set internal oscillator to highest
                                       // setting of 24500000

   Port_Init();                        // Initialize Crossbar and GPIO
   Timer1_Init();                      // Configure Timer1 for use
                                       // with SMBus baud rate

   Timer3_Init ();                     // Configure Timer  for use with
                                       // SCL low timeout detect

   SMBus_Init ();                      // Configure and enable SMBus


   EIE1 |= 0x01;                       // Enable the SMBus interrupt

   LED = 0;

   EA = 1;                             // Global interrupt enable

   SMB_DATA = 0xFD;                    // Initialize SMBus data holder

   while(1)
   {
      while(!DATA_READY);              // New SMBus data received?
      DATA_READY = 0;
      LED = ~LED;
   }
}

//-----------------------------------------------------------------------------
// Initialization Routines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// SMBus_Init()
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// SMBus configured as follows:
// - SMBus enabled
// - Slave mode not inhibited
// - Timer1 used as clock source. The maximum SCL frequency will be
//   approximately 1/3 the Timer1 overflow rate
// - Setup and hold time extensions enabled
// - Bus Free and SCL Low timeout detection enabled
//
void SMBus_Init (void)
{
   SMB0CF = 0x1D;                      // Use Timer1 overflows as SMBus clock
                                       // source;
                                       // Enable slave mode;
                                       // Enable setup & hold time
                                       // extensions;
                                       // Enable SMBus Free timeout detect;
                                       // Enable SCL low timeout detect;

   SMB0CF |= 0x80;                     // Enable SMBus;
}

//-----------------------------------------------------------------------------
// Timer1_Init()
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Timer1 configured as the SMBus clock source as follows:
// - Timer1 in 8-bit auto-reload mode
// - SYSCLK or SYSCLK / 4 as Timer1 clock source
// - Timer1 overflow rate => 3 * SMB_FREQUENCY
// - The resulting SCL clock rate will be ~1/3 the Timer1 overflow rate
// - Timer1 enabled
//
void Timer1_Init (void)
{

// Make sure the Timer can produce the appropriate frequency in 8-bit mode
// Supported SMBus Frequencies range from 10kHz to 100kHz.  The CKCON register
// settings may need to change for frequencies outside this range.
#if ((SYSCLK/SMB_FREQUENCY/3) < 255)
   #define SCALE 1
      CKCON |= 0x08;                   // Timer1 clock source = SYSCLK
#elif ((SYSCLK/SMB_FREQUENCY/4/3) < 255)
   #define SCALE 4
      CKCON |= 0x01;
      CKCON &= ~0x0A;                  // Timer1 clock source = SYSCLK / 4
#endif

   TMOD = 0x20;                        // Timer1 in 8-bit auto-reload mode

   // Timer1 configured to overflow at 1/3 the rate defined by SMB_FREQUENCY
   TH1 = -(SYSCLK/SMB_FREQUENCY/SCALE/3);

   TL1 = TH1;                          // Init Timer1

   TR1 = 1;                            // Timer1 enabled
}

//-----------------------------------------------------------------------------
// Timer3_Init()
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// 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
//
// P3.3   digital   push-pull     LED
//
// all other port pins unused
//
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
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// SMBus Interrupt Service Routine (ISR)
//-----------------------------------------------------------------------------
//
// SMBus ISR state machine
// - Slave only implementation - no master states defined
// - All incoming data is written to global variable <SMB_DATA>
// - All outgoing data is read from global variable <SMB_DATA>
//
void SMBus_ISR (void) interrupt 7
{
   if (ARBLOST == 0)
   {
      switch (SMB0CN & 0xF0)           // Decode the SMBus status vector
      {
         // Slave Receiver: Start+Address received
         case  SMB_SRADD:

            STA = 0;                   // Clear STA bit
            if((SMB0DAT&0xFE) == (SLAVE_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,
               {
                  SMB0DAT = SMB_DATA;  // Prepare outgoing byte
               }
            }
            else                       // If received slave address does not
            {                          // match,
               ACK = 0;                // NACK received address
            }
            break;

         // Slave Receiver: Data received
         case  SMB_SRDB:

            SMB_DATA = SMB0DAT;        // Store incoming data
            DATA_READY = 1;            // Indicate new data received
            ACK = 1;                   // ACK received data

            break;

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

            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:

            SMB0CF &= ~0x80;           // Reset communication
            SMB0CF |= 0x80;
            STA = 0;
            STO = 0;
            ACK = 0;
            break;
      }
   }
   // ARBLOST = 1, Abort failed transfer
   else
   {
      STA = 0;
      STO = 0;
      ACK = 0;
   }

   SI = 0;                             // Clear SMBus 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
}

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久er99热精品一区二区| 一区二区三区在线看| 在线播放日韩导航| 在线免费观看视频一区| 91小视频免费看| 91浏览器在线视频| 91福利区一区二区三区| 欧美一区二区大片| 久久一区二区视频| 国产精品电影院| 亚洲国产婷婷综合在线精品| 亚洲.国产.中文慕字在线| 首页国产欧美日韩丝袜| 美女视频黄久久| 黑人巨大精品欧美黑白配亚洲| 青青青爽久久午夜综合久久午夜| 亚洲va国产天堂va久久en| 婷婷中文字幕综合| 国精品**一区二区三区在线蜜桃| 国产传媒久久文化传媒| 在线观看一区二区精品视频| 日韩欧美成人一区二区| 亚洲精品久久久久久国产精华液| 亚洲成人三级小说| 99精品国产99久久久久久白柏| 欧美日韩卡一卡二| 久久欧美一区二区| 亚洲成av人综合在线观看| 成人毛片老司机大片| 欧美一级二级三级蜜桃| 亚洲综合一区二区| 91在线丨porny丨国产| 欧美成人一区二区三区片免费| 亚洲国产乱码最新视频| k8久久久一区二区三区 | 欧美日韩国产一区| 亚洲欧美韩国综合色| av在线不卡免费看| 中文字幕一区二区三| 成人中文字幕电影| 国产精品国产三级国产有无不卡 | 欧美精品久久久久久久多人混战 | 91蜜桃免费观看视频| 欧美韩国一区二区| 91在线观看一区二区| 国产精品免费人成网站| av中文一区二区三区| 国产精品欧美久久久久一区二区| 国产高清亚洲一区| 亚洲图片欧美激情| 91福利社在线观看| 麻豆久久久久久久| 国产欧美日韩综合| 91国模大尺度私拍在线视频| 亚洲不卡在线观看| 久久蜜桃av一区精品变态类天堂 | 久久这里只有精品视频网| jlzzjlzz欧美大全| 欧美美女一区二区在线观看| 国产午夜精品美女毛片视频| 日韩电影一区二区三区| 91免费在线视频观看| 亚洲第一成年网| 精品亚洲aⅴ乱码一区二区三区| 欧美日韩午夜在线视频| 韩国女主播成人在线观看| 国产亚洲精久久久久久| 欧洲av一区二区嗯嗯嗯啊| 免费高清在线一区| 亚洲精品国产成人久久av盗摄| 91精品国产综合久久精品性色| 高清国产午夜精品久久久久久| 亚洲午夜日本在线观看| 国产精品久久久久久久午夜片| 欧美午夜精品久久久久久超碰| 麻豆91免费观看| 亚洲欧美另类综合偷拍| 日韩一区二区视频在线观看| 色综合夜色一区| 国产91精品入口| 国产美女精品在线| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲欧洲av在线| 欧美国产日韩精品免费观看| 欧美变态凌虐bdsm| 日韩女优视频免费观看| 精品国精品国产尤物美女| 欧美日韩中文一区| 91精品久久久久久久99蜜桃| 欧美网站大全在线观看| 欧美日高清视频| 欧美一级久久久| 欧美成人伊人久久综合网| 9191精品国产综合久久久久久| 欧美三级在线视频| 在线不卡免费av| 精品国产青草久久久久福利| 欧美精品一区二区三区高清aⅴ | 中文字幕中文字幕一区二区 | 成人激情图片网| 91电影在线观看| 欧美电影一区二区| 久久先锋资源网| 亚洲私人黄色宅男| 青青草原综合久久大伊人精品| 久久av老司机精品网站导航| 国产精品一线二线三线精华| 成人免费高清视频| 欧美一区二区三区在线看| 久久综合999| 丝袜美腿成人在线| 91麻豆自制传媒国产之光| 欧美一级二级三级蜜桃| 中文字幕一区二区日韩精品绯色| 肉肉av福利一精品导航| 成人av在线一区二区| 555www色欧美视频| 一区二区成人在线| 成人av午夜影院| 日韩欧美高清一区| 美腿丝袜亚洲三区| 欧美日韩精品二区第二页| 最新成人av在线| 成人美女在线视频| 久久精品免费在线观看| 韩国一区二区三区| 精品国产一区二区在线观看| 亚洲高清免费视频| 色综合久久综合网97色综合| 国产欧美精品国产国产专区 | 日韩欧美一区二区视频| 亚洲一区二区在线播放相泽| 成人av在线观| 一区二区三区精品| 欧美色精品在线视频| 一区二区三区四区亚洲| 欧美中文字幕不卡| 亚洲午夜激情av| 4438x成人网最大色成网站| 午夜精品免费在线| 91.成人天堂一区| 久久99热狠狠色一区二区| 精品国产91洋老外米糕| 国产精品1024| 亚洲一区二区三区四区五区黄 | 国产精品一区专区| 自拍偷拍欧美精品| 日韩欧美在线123| 成人综合在线观看| 午夜精品福利久久久| 日韩欧美在线网站| 91浏览器在线视频| 黄色日韩三级电影| 亚洲综合一区在线| 欧美经典三级视频一区二区三区| 色婷婷av一区二区| 国产成人av电影在线观看| 午夜精品久久久久久久久| 国产欧美一区视频| 欧美一区二区三区日韩视频| av亚洲精华国产精华精华| 麻豆精品视频在线观看视频| 亚洲一区二区视频在线| 欧美一区二区三区在线观看视频 | 欧美日韩国产影片| 国产综合一区二区| 亚洲综合999| 不卡免费追剧大全电视剧网站| 亚洲国产综合91精品麻豆| 国产亚洲一区二区在线观看| 欧美一区二区美女| 欧美日韩国产另类不卡| 91老司机福利 在线| 国产福利精品导航| 国产精品一二三四五| 九一九一国产精品| 国内精品视频666| 捆绑变态av一区二区三区| 蜜臀av性久久久久蜜臀aⅴ流畅| 青青草精品视频| 老鸭窝一区二区久久精品| 麻豆精品精品国产自在97香蕉| 亚洲伦在线观看| 最新国产成人在线观看| 亚洲素人一区二区| 欧美国产欧美亚州国产日韩mv天天看完整| 欧美日韩亚洲不卡| 精品国产三级a在线观看| 亚洲精品一区二区三区影院| 欧美v亚洲v综合ⅴ国产v| 久久综合资源网| 中文字幕亚洲在| 亚洲夂夂婷婷色拍ww47| 首页综合国产亚洲丝袜| 韩国女主播成人在线观看| 成a人片国产精品| 欧美日韩一区二区欧美激情| 欧美美女一区二区| 日本亚洲最大的色成网站www| 日韩精品一区在线|