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

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

?? f32x_smbus_slave.c

?? silicon 單片機C8051F320的I2C總線控制程序
?? C
字號:
//-----------------------------------------------------------------------------
// F32x_SMBus_Slave.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Example software to demonstrate the C8051F32x 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)
// - Timer2 or Timer3 used by SMBus for SCL low timeout detection
// - ARBLOST support included
// - Pinout:
//    P0.0 -> SDA (SMBus)
//    P0.1 -> SCL (SMBus)
//
//    P2.2 -> LED
//
//    P3.0 -> C2D (debug interface)
//
//    all other port pins unused
//
// How To Test:
//
// 1) Download code to a 'F32x 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:            32X000047
// Target:         C8051F32x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -30 MAR 2006
//

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

#include <C8051F320.h>

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

#define  SYSCLK         12000000       // 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 = P2^2;                       // LED on port P2.2

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

// VERIFY
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 12000000

   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
//
// P2.2   digital   push-pull     LED
//
// all other port pins unused
//
void PORT_Init (void)
{
   P0MDOUT = 0x00;                     // All P0 pins open-drain output

   P2MDOUT |= 0x04;                    // Make the LED (P2.2) 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一区二区三区免费野_久草精品视频
欧美国产一区视频在线观看| 自拍偷拍国产精品| 国产精品久久777777| 亚洲国产人成综合网站| 国产精品系列在线观看| 欧美亚洲日本一区| 国产精品久久久久精k8 | 欧美男男青年gay1069videost| 欧美xxxxxxxx| 亚洲超碰精品一区二区| 波多野结衣一区二区三区| 欧美一区二区三区喷汁尤物| 亚洲欧美一区二区三区孕妇| 国产乱子轮精品视频| 欧美日韩精品一区视频| 亚洲综合免费观看高清完整版| 国产精品1区二区.| 久久综合九色综合欧美98| 亚洲福利一区二区三区| 91精品办公室少妇高潮对白| 国产清纯美女被跳蛋高潮一区二区久久w | 久久在线免费观看| 免费人成精品欧美精品| 欧美日韩一区不卡| 自拍偷拍亚洲欧美日韩| 成人黄色一级视频| 国产日产欧美一区二区三区| 国内精品第一页| 日韩美女视频在线| 久草在线在线精品观看| 911国产精品| 日日嗨av一区二区三区四区| 在线观看国产一区二区| 亚洲女与黑人做爰| 色综合久久久久综合体| 亚洲欧美激情视频在线观看一区二区三区 | 色哟哟一区二区| 亚洲日本电影在线| 日本精品视频一区二区| 一区二区三区四区乱视频| 日本高清无吗v一区| 一区二区免费看| 欧美日韩国产天堂| 免费观看30秒视频久久| 日韩欧美卡一卡二| 国产福利一区二区三区| 国产精品久线观看视频| 色欧美片视频在线观看在线视频| 亚洲欧美成人一区二区三区| 欧美性生活影院| 免费视频最近日韩| 国产网红主播福利一区二区| 国产成人在线视频网址| 国产精品久线在线观看| 欧日韩精品视频| 秋霞成人午夜伦在线观看| 2014亚洲片线观看视频免费| 国产.欧美.日韩| 一区二区三区欧美视频| 欧美一级视频精品观看| 国产伦理精品不卡| 亚洲男人天堂一区| 欧美三级韩国三级日本三斤| 三级一区在线视频先锋 | 91麻豆精品久久久久蜜臀| 韩国女主播成人在线| 亚洲欧洲日产国产综合网| 欧美在线视频不卡| 国产一区二区三区美女| 亚洲欧美日韩在线| 日韩一区二区在线观看视频 | 在线亚洲高清视频| 美女性感视频久久| 日韩毛片一二三区| 日韩免费一区二区三区在线播放| 国产·精品毛片| 日韩国产精品大片| 日日摸夜夜添夜夜添亚洲女人| 精品国产乱码久久| 欧洲亚洲精品在线| 国产精品一区一区| 亚洲777理论| 国产精品你懂的在线| 欧美一区二区三区电影| bt欧美亚洲午夜电影天堂| 日韩福利视频导航| 一区二区在线电影| 日本一区二区三区四区| 欧美一区二区在线免费播放| 不卡的av网站| 精品系列免费在线观看| 亚洲一级二级三级在线免费观看| 久久久久国产精品麻豆ai换脸| 欧美高清视频一二三区 | 亚洲国产精品精华液2区45| 欧美日韩精品一区视频| 91丨porny丨首页| 国产成人精品1024| 久久av中文字幕片| 日本不卡免费在线视频| 亚洲国产成人av好男人在线观看| 国产精品另类一区| www激情久久| 日韩免费高清电影| 3d动漫精品啪啪1区2区免费 | 色综合视频在线观看| 国产成人在线视频网站| 国产在线精品一区二区夜色 | 国产亚洲午夜高清国产拍精品| 91精品国产综合久久精品图片| 日本久久一区二区| 91久久精品网| 色诱亚洲精品久久久久久| 97精品视频在线观看自产线路二| 国产91富婆露脸刺激对白| 国产91丝袜在线18| www.在线欧美| 97久久久精品综合88久久| 99免费精品在线| 99re热视频这里只精品| 色综合天天性综合| 欧美日免费三级在线| 宅男在线国产精品| 欧美成人伊人久久综合网| 欧美精品一区二| 欧美国产禁国产网站cc| 中文字幕制服丝袜成人av| 亚洲欧美电影一区二区| 亚洲一线二线三线视频| 亚洲国产va精品久久久不卡综合 | 欧美美女网站色| 欧美一区二区播放| 久久久777精品电影网影网 | 久久精品国产秦先生| 日本91福利区| 青青草国产成人99久久| 午夜精品在线看| 亚洲精品国产视频| 日韩电影免费一区| 另类中文字幕网| 国产综合成人久久大片91| 狠狠色狠狠色综合日日91app| 成人免费视频国产在线观看| 福利视频网站一区二区三区| 成人午夜av影视| www.在线欧美| 久久久综合激的五月天| 久久综合九色综合97婷婷| 久久久蜜桃精品| 国产精品网站在线| 国产午夜亚洲精品理论片色戒| 1000部国产精品成人观看| 一区二区在线观看视频| 亚洲午夜羞羞片| 青娱乐精品视频| 91原创在线视频| 欧美一区二视频| 国产日韩欧美精品电影三级在线| 国产亚洲精品福利| 日韩av一级电影| 国模少妇一区二区三区| kk眼镜猥琐国模调教系列一区二区| av中文字幕在线不卡| 51精品秘密在线观看| 久久亚洲春色中文字幕久久久| 国产视频911| 亚洲欧美偷拍卡通变态| 久久综合视频网| 日本欧美肥老太交大片| 国v精品久久久网| 欧美高清一级片在线| 亚洲日本va午夜在线影院| 午夜精品国产更新| 国产精品小仙女| 在线观看91精品国产麻豆| 日韩毛片精品高清免费| 久久国产精品一区二区| 97se亚洲国产综合自在线观| 正在播放一区二区| 夜夜精品浪潮av一区二区三区| 蜜桃视频免费观看一区| 色综合色狠狠天天综合色| 欧美大片日本大片免费观看| 视频一区视频二区中文字幕| 国产精品一级黄| 在线不卡的av| 亚洲三级免费电影| av中文字幕不卡| 精品黑人一区二区三区久久 | 欧美一三区三区四区免费在线看 | 欧美综合色免费| 亚洲日本成人在线观看| 国产制服丝袜一区| 在线电影一区二区三区| 久久久久国产精品人| 国产a级毛片一区| 久久综合九色综合97婷婷女人| 亚洲成人自拍偷拍| 成a人片国产精品| 国产精品福利一区|