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

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

?? f31x_smbus_multimaster.c

?? C8051F31系列單片機的例子
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// F31x_SMBus_Multimaster.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Example software to demonstrate the C8051F31x SMBus interface in
// a Multi-Master environment.
// - Interrupt-driven SMBus implementation
// - Master and slave states defined
// - 1-byte SMBus data holders used for each transmit and receive
// - Timer1 used as SMBus clock source
// - Timer3 used by SMBus for SCL low timeout detection
// - SCL frequency defined by <SMB_FREQUENCY> constant
// - ARBLOST support included
// - When another master attempts to transmit at the same time:
//      - the 'F31x SMBus master should detect any conflict using ARBLOST
//      - the 'F31x SMBus master should give up the bus, if necessary, and
//        switch to slave receiver mode
//      - the 'F31x SMBus master should transmit after the other master is done
// - Pinout:
//    P0.0 -> SDA (SMBus)
//    P0.1 -> SCL (SMBus)
//
//    P0.7 -> SW
//
//    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 another C8051Fxxx
//    SMBus multimaster.
// 2) Run the code.  The test will indicate proper communication with the
//    other C8051Fxxx device by blinking the LED on the other device on and
//    off each time SW is pressed, even if the buttons on both boards are
//    pressed at the same time.
//
//      'F31x Multimaster                     Other C8051Fxxx Multimaster
//         LED (blinks) <------------------------------ Switch
//              SW --------------------------------> LED (blinks)
//
// NOTE: Before running the test, verify that MY_ADDR and MULTI_ADDR are
// defined to the proper values.
//
// FID:            31X000005
// Target:         C8051F31x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (TP)
//    -15 MAY 2006
//

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

#include <C8051F310.h>                 // SFR declarations

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

#define  SYSCLK         24500000       // System clock frequency in Hz

#define  SMB_FREQUENCY  10000          // Target SCL clock rate
                                       // This example supports between 10kHz
                                       // and 100kHz

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

// Device addresses (7 bits, lsb is a don't care)
#define  MY_ADDR        0x0F           // Device address for this device target
#define  MULTI_ADDR     0xF0           // Device address for other multimaster
                                       // target

// Status vector - top 4 bits only
#define  SMB_MTSTA      0xE0           // (MT) start transmitted
#define  SMB_MTDB       0xC0           // (MT) data byte transmitted
#define  SMB_MRDB       0x80           // (MR) data byte received

#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

// Data to indicate the switch was pressed or released
#define  SW_PRESSED     0x0A
#define  SW_RELEASED    0x50

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

// Global holder for SMBus master data. All receive data is written here
// while in master mode
// Slave->Master
unsigned char SMB_DATA_IN_MASTER = 0x00;

// Global holder for SMBus master data. All transmit data is read from here
// while in master mode
// Master->Slave
unsigned char SMB_DATA_OUT_MASTER = 0x00;

// Global holder for SMBus slave data. All receive data is written here
// while slave mode
// Master->Slave
unsigned char SMB_DATA_IN_SLAVE = 0x00;

// Global holder for SMBus slave data. All transmit data is read from here
// while in slave mode
// Slave->Master
unsigned char SMB_DATA_OUT_SLAVE = 0x00;

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

unsigned char TARGET;                  // Target SMBus slave address

bit SMB_BUSY;                          // Software flag to indicate when the
                                       // SMB_Read() or SMB_Write() functions
                                       // have claimed the SMBus

bit SMB_RW;                            // Software flag to indicate the
                                       // direction of the current transfer

unsigned long NUM_ERRORS;              // Counter for the number of errors.

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

sbit SW = P0^7;                        // Switch on P0.7

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

sbit SDA = P0^0;                       // SMBus on P0.0
sbit SCL = P0^1;                       // and P0.1

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

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

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

void SMB_Write (void);
void Blink_LED (void);
void Stop_LED (void);

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//
// Main routine performs all configuration tasks, then loops forever checking
// for and sending the LED commands.
//
void main (void)
{
   bit switch_pressed_flag = 0;        // Used to detect when the switch is
                                       // released
   unsigned char i;                    // Dummy variable counters

   PCA0MD &= ~0x40;                    // WDTE = 0 (watchdog timer enable bit)

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

   // If slave is holding SDA low because of an improper SMBus reset or error
   while(!SDA)
   {
      // Provide clock pulses to allow the slave to advance out
      // of its current state. This will allow it to release SDA.
      XBR1 = 0x40;                     // Enable Crossbar
      SCL = 0;                         // Drive the clock low
      for(i = 0; i < 255; i++);        // Hold the clock low
      SCL = 1;                         // Release the clock
      while(!SCL);                     // Wait for open-drain
                                       // clock output to rise
      for(i = 0; i < 10; i++);         // Hold the clock high
      XBR1 = 0x00;                     // Disable Crossbar
   }

   Port_Init ();                       // Initialize Crossbar and GPIO

   Timer0_Init ();                     // Configure Timer0 to blink the LED

   Timer1_Init ();                     // Configure Timer1 for use as SMBus
                                       // clock source

   Timer3_Init();                      // Configure Timer3 for use with SMBus
                                       // low timeout detect

   SMBus_Init ();                      // Configure and enable SMBus


   EIE1 |= 0x01;                       // Enable the SMBus interrupt
   EIP1 |= 0x01;                       // make the SMBus interrupt high
                                       // priority

   ET0 = 1;                            // Enable the Timer0 interrupt (LED)

   LED = 0;

   EA = 1;                             // Global interrupt enable

   while (1)
   {
      // Check if the switch was just pressed
      if ((switch_pressed_flag == 0) && (SW == 0))
      {
          // SMBus Write Sequence

          // Tell the other device the switch was pressed
          SMB_DATA_OUT_MASTER = SW_PRESSED;

          TARGET = MULTI_ADDR;         // Target the other multimaster device
          SMB_Write();                 // Initiate SMBus write

          switch_pressed_flag = 1;
      }

      // Determine if the switch was just released
      if ((switch_pressed_flag == 1) && (SW != 0))
      {
          // SMBus Write Sequence

          // Tell the other device the switch was released
          SMB_DATA_OUT_MASTER = SW_RELEASED;

          TARGET = MULTI_ADDR;         // Target the other multimaster device
          SMB_Write();                 // Initiate SMBus write

          switch_pressed_flag = 0;
      }

      // Check if data was sent to this device from the other multimaster
      // device
      if (DATA_READY == 1)
      {
         if (SMB_DATA_IN_SLAVE == SW_PRESSED)
         {
            Blink_LED();
         }
         else
         {
            if (SMB_DATA_IN_SLAVE == SW_RELEASED)
            {
               Stop_LED();
            }
         }

         DATA_READY = 0;
      }
   }  // Loop forever
}

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

//-----------------------------------------------------------------------------
// SMBus_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// SMBus configured as follows:
// - SMBus enabled
// - 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 setup & hold time
                                       // extensions;
                                       // Enable SMBus Free timeout detect;
                                       // Enable SCL low timeout detect;

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

//-----------------------------------------------------------------------------
// Timer0_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Timer0 is configured to blink the LED.  Timer0 uses the same CKCON register
// settings at Timer1, since the LED blink frequency is not dependent on
// anything.
//
void Timer0_Init (void)
{
   TMOD = 0x02;                        // Timer0 in 8-bit auto-reload mode

   TH0 = 0x00;                         // Make Timer0 wait the longest time
                                       // between LED blinks.
   TL0 = TH0;                          // Init Timer0

   // Keeper Timer0 off until the switch on the other multimaster device is
   // pushed
}

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区福利| 色婷婷综合久久久中文一区二区| 不卡一区在线观看| 欧美老女人在线| 国产女人18毛片水真多成人如厕| 一区二区三区在线高清| 国产一区二区在线影院| 欧美日韩一区二区在线观看| 国产精品剧情在线亚洲| 捆绑紧缚一区二区三区视频| 91福利在线观看| 一色桃子久久精品亚洲| 国产不卡高清在线观看视频| 欧美一区二区三区爱爱| 亚洲资源中文字幕| 91精品福利在线| 亚洲欧洲综合另类| 日本福利一区二区| 国产精品色在线观看| 国产一区二区美女诱惑| 欧美一区二区女人| 日韩精品一卡二卡三卡四卡无卡| 色婷婷久久久综合中文字幕| 国产精品不卡一区二区三区| 国产黄人亚洲片| 久久久久久免费毛片精品| 蜜臀91精品一区二区三区| 欧美日本一区二区三区四区 | 欧美激情综合五月色丁香小说| 视频一区二区三区在线| 欧美无砖砖区免费| 亚洲第一激情av| 欧美日韩视频专区在线播放| 亚洲bdsm女犯bdsm网站| 欧美三级电影在线看| 亚洲第四色夜色| 在线播放日韩导航| 免费高清不卡av| 2024国产精品视频| 成人黄色小视频| 亚洲欧美一区二区三区国产精品 | 中文字幕一区三区| 91性感美女视频| 亚洲一区二区三区四区在线 | 成人18视频在线播放| 亚洲天天做日日做天天谢日日欢 | 亚洲精品乱码久久久久久黑人| 色婷婷激情综合| 亚洲美女少妇撒尿| 欧美一级理论性理论a| 老司机免费视频一区二区| 久久众筹精品私拍模特| va亚洲va日韩不卡在线观看| 亚洲免费观看高清| 欧美一区午夜视频在线观看| 韩国三级电影一区二区| 亚洲国产精品高清| 欧美无乱码久久久免费午夜一区| 日本91福利区| 中文字幕高清不卡| 欧美久久久久久久久中文字幕| 久久精品国产99| 国产精品久久看| 7777精品伊人久久久大香线蕉经典版下载 | 亚洲综合另类小说| 日韩三级av在线播放| 国产**成人网毛片九色| 一区二区三区高清在线| 精品国产99国产精品| 91一区二区在线观看| 麻豆久久久久久久| 亚洲免费在线播放| 久久久综合视频| 欧美日韩视频在线第一区| 国产精品123| 天天综合日日夜夜精品| 日韩一区在线看| 日韩精品专区在线| 一本色道亚洲精品aⅴ| 久久福利视频一区二区| 亚洲欧洲av另类| 欧美电影免费观看高清完整版在线观看| 国产超碰在线一区| 美女诱惑一区二区| 亚洲国产aⅴ成人精品无吗| 亚洲三级在线免费| 欧美成人官网二区| 91成人免费在线| 成年人国产精品| 国产黑丝在线一区二区三区| 另类欧美日韩国产在线| 一区二区三区在线看| 中文字幕av资源一区| 精品少妇一区二区三区免费观看| 欧美专区日韩专区| 91亚洲精品一区二区乱码| 国产成人自拍在线| 久久成人免费网| 日本大胆欧美人术艺术动态| 一区二区三区四区乱视频| 国产精品久久三| 中文字幕不卡的av| 国产婷婷色一区二区三区| 精品国偷自产国产一区| 欧美乱妇15p| 51精品国自产在线| 欧美日韩亚洲综合在线 | 亚洲一区中文在线| 国产精品视频免费| 国产精品免费看片| 国产精品国产三级国产普通话99 | 精品国一区二区三区| 日韩欧美综合一区| 精品免费视频.| 精品国产一区二区亚洲人成毛片| 精品日本一线二线三线不卡| 欧美tk—视频vk| 久久夜色精品国产噜噜av| 26uuu精品一区二区| 久久久久久久久久看片| 国产嫩草影院久久久久| 中文字幕乱码亚洲精品一区| 中文字幕av不卡| 亚洲欧洲精品一区二区三区不卡| 亚洲色图视频免费播放| 亚洲国产中文字幕| 蜜臀久久99精品久久久久宅男| 久久99国产精品久久99果冻传媒| 精品一区二区在线免费观看| 国产精品一区二区久久不卡| 国产**成人网毛片九色| 91免费版pro下载短视频| 欧美性生活大片视频| 欧美一级一级性生活免费录像| 精品日本一线二线三线不卡| 久久精品夜夜夜夜久久| 综合欧美一区二区三区| 亚洲二区视频在线| 国产在线精品国自产拍免费| 成人精品视频.| 欧美三级中文字幕| 精品国产91亚洲一区二区三区婷婷 | 欧美日韩美女一区二区| 欧美va亚洲va在线观看蝴蝶网| 国产色91在线| 亚洲国产综合色| 国产一区二区三区在线看麻豆| 成人ar影院免费观看视频| 欧美日韩成人激情| 国产欧美精品日韩区二区麻豆天美 | 久久国产人妖系列| av资源站一区| 欧美精品三级在线观看| 久久看人人爽人人| 亚洲午夜国产一区99re久久| 国产一区在线观看视频| 91久久国产综合久久| 精品第一国产综合精品aⅴ| 日韩毛片精品高清免费| 老司机免费视频一区二区 | 成人亚洲一区二区一| 欧美久久久一区| 中文字幕在线一区免费| 麻豆91在线播放免费| 在线一区二区视频| 久久精品视频在线免费观看| 日韩—二三区免费观看av| 色呦呦国产精品| 国产精品网站一区| 韩国三级中文字幕hd久久精品| 欧美性视频一区二区三区| 中文字幕欧美国产| 99视频一区二区| 精品国偷自产国产一区| 日韩精品1区2区3区| 色综合天天视频在线观看| 国产三级一区二区| 极品尤物av久久免费看| 欧美系列在线观看| 亚洲人成精品久久久久久| 国产91在线观看丝袜| 久久一夜天堂av一区二区三区 | 国产成人小视频| 日韩丝袜美女视频| 五月婷婷色综合| 在线观看亚洲专区| 亚洲精品视频在线| 色综合天天性综合| 亚洲婷婷综合色高清在线| 成人综合在线观看| 久久久久国产精品麻豆| 精品一区二区影视| 欧美xxxxxxxxx| 激情综合色综合久久综合| 日韩视频123| 麻豆精品在线观看| 欧美一级二级三级蜜桃| 久久狠狠亚洲综合| 国产网站一区二区三区| 国产999精品久久|