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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? f32x_smbus_master.c

?? silicon 單片機C8051F320的I2C總線控制程序
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// F32x_SMBus_Master.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Example software to demonstrate the C8051F32x SMBus interface in
// Master mode.
// - Interrupt-driven SMBus implementation
// - Only master states defined (no slave or arbitration)
// - 1-byte SMBus data holders used for each transmit and receive
// - Timer1 used as SMBus clock source
// - Timer2 used by SMBus for SCL low timeout detection
// - SCL frequency defined by <SMB_FREQUENCY> constant
// - 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 slave.
// 2) Run the code:
//         a) The test will indicate proper communication with the slave by
//            toggling the LED on and off each time a value is sent and
//            received.
//         b) The best method to view the proper functionality is to run to
//            the indicated line of code in the TEST CODE section of main and
//            view the SMB_DATA_IN and SMB_DATA_OUT variables in the Watch
//            Window.
//
//
// FID:            32X000050
// 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 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  SLAVE_ADDR     0xF0           // Device address for slave 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
// End status vector definition

//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------
unsigned char SMB_DATA_IN;             // Global holder for SMBus data
                                       // All receive data is written here

unsigned char SMB_DATA_OUT;            // Global holder for SMBus data.
                                       // All transmit data is read from here

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

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

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

void SMB_Write (void);
void SMB_Read (void);
void T0_Wait_ms (unsigned char ms);

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//
// Main routine performs all configuration tasks, then loops forever sending
// and receiving SMBus data to the slave <SLAVE_ADDR>.
//
void main (void)
{
   volatile unsigned char dat;         // Test counter
   unsigned char i;                    // Dummy variable counters

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

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

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

   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

   LED = 0;

   EA = 1;                             // Global interrupt enable

// TEST CODE-------------------------------------------------------------------

   dat = 0;                            // Output data counter
   NUM_ERRORS = 0;                     // Error counter
   while (1)
   {
      // SMBus Write Sequence
      SMB_DATA_OUT = dat;              // Define next outgoing byte
      TARGET = SLAVE_ADDR;             // Target the Slave for next SMBus
                                       // transfer
      SMB_Write();                     // Initiate SMBus write

      // SMBus Read Sequence
      TARGET = SLAVE_ADDR;             // Target the Slave for next SMBus
                                       // transfer
      SMB_Read();

      // Check transfer data
      if(SMB_DATA_IN != SMB_DATA_OUT)  // Received data match transmit data?
      {
         NUM_ERRORS++;                 // Increment error counter if no match
      }

      // Indicate that an error has occurred (LED no longer lit)
      if (NUM_ERRORS > 0)
      {
         LED = 0;
      }
      else
      {
         LED = ~LED;
      }

      // Run to here to view the SMB_DATA_IN and SMB_DATA_OUT variables

      dat++;

      T0_Wait_ms (1);
   }

// END TEST CODE---------------------------------------------------------------

}

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

//-----------------------------------------------------------------------------
// SMBus_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// SMBus configured as follows:
// - SMBus enabled
// - Slave mode 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 = 0x5D;                      // Use Timer1 overflows as SMBus clock
                                       // source;
                                       // Disable 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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩视频在线一区二区| 国产精品三级av| 精品国产凹凸成av人网站| 最新中文字幕一区二区三区| 亚洲婷婷综合色高清在线| 综合久久一区二区三区| 日本亚洲最大的色成网站www| 亚洲一区二区三区四区的| 中文字幕av资源一区| 一区二区三区免费网站| 久久激情五月激情| 韩国av一区二区| 成人一道本在线| 欧美性极品少妇| 日本亚洲一区二区| 粗大黑人巨茎大战欧美成人| 日韩视频一区二区在线观看| 亚洲日本在线视频观看| 国产精品一区二区在线播放| 日韩一级精品视频在线观看| 国产精品国模大尺度视频| 国产乱理伦片在线观看夜一区| 91成人免费网站| 久久综合精品国产一区二区三区 | 欧美tickling挠脚心丨vk| 日韩精品电影在线观看| 韩国在线一区二区| 一本色道久久综合狠狠躁的推荐| www国产精品av| 91猫先生在线| 青娱乐精品视频在线| 欧美在线综合视频| 日韩一区二区在线观看视频播放| 国产精品美女久久久久高潮| 精品一区二区在线看| 欧美午夜理伦三级在线观看| 懂色av一区二区在线播放| 欧美电影免费观看高清完整版 | 亚洲老妇xxxxxx| 日韩电影在线观看一区| 3751色影院一区二区三区| 成人免费在线视频| 91免费在线看| 1000部国产精品成人观看| 99精品久久久久久| 亚洲高清三级视频| 欧美久久久久中文字幕| 蜜桃视频免费观看一区| 国产日韩欧美麻豆| 国产成a人亚洲精| 亚洲不卡一区二区三区| 欧美一级欧美三级| 国产专区欧美精品| 最新日韩在线视频| 欧美日韩免费观看一区三区| 偷拍一区二区三区四区| 精品99久久久久久| 91麻豆123| 成人av免费网站| 久久成人av少妇免费| 国产精品第四页| 欧美日韩久久久一区| 国产一区在线视频| 国产成人综合亚洲91猫咪| 久久综合视频网| 69成人精品免费视频| 久久电影国产免费久久电影| 国产精品久久久久久久久免费桃花 | 日韩精品1区2区3区| 欧美一级搡bbbb搡bbbb| 成人免费观看视频| 国产不卡在线视频| 精品中文字幕一区二区小辣椒| 欧美国产日本韩| 日韩视频一区二区在线观看| 精品少妇一区二区三区日产乱码| 日韩一级片在线播放| 欧美一级日韩一级| 欧美一级二级三级蜜桃| 一本到不卡精品视频在线观看 | 国产精品中文字幕日韩精品 | 欧美三级在线播放| 成人午夜精品在线| 国产精品伊人色| 国产一区二区调教| 日韩精品色哟哟| 97国产精品videossex| 成人免费精品视频| 99re热视频精品| www.av精品| 1区2区3区欧美| 美国十次了思思久久精品导航| 狠狠色丁香久久婷婷综合_中| 奇米在线7777在线精品| 成人一区二区三区中文字幕| 欧美日韩久久久久久| 欧美成人欧美edvon| 国产午夜亚洲精品理论片色戒| 日韩精品一区国产麻豆| 欧美顶级少妇做爰| 欧美激情一区二区在线| 成人免费一区二区三区视频| 国产成人欧美日韩在线电影| 91麻豆精品国产91久久久久久久久 | 国产一区二三区好的| 在线亚洲一区观看| 国产精品日韩成人| 国产伦精品一区二区三区免费迷 | 一二三区精品视频| 日本v片在线高清不卡在线观看| 成年人网站91| 国产精品羞羞答答xxdd| 不卡一区二区在线| 中文字幕永久在线不卡| 日韩精品一区第一页| 欧美手机在线视频| 久久久久高清精品| 国产成人免费在线视频| 国产亚洲欧美日韩日本| 免费人成黄页网站在线一区二区| a4yy欧美一区二区三区| 欧美高清视频www夜色资源网| 欧美韩国日本综合| 成人一区二区三区在线观看| 国产日韩成人精品| 在线免费一区三区| 国产精品久线在线观看| 成人黄色在线看| 亚洲综合色区另类av| 欧美mv日韩mv国产| 精品制服美女丁香| 欧美电视剧免费观看| 亚洲与欧洲av电影| 久久亚洲一区二区三区明星换脸| 日本亚洲三级在线| 亚洲午夜激情av| 在线播放中文一区| 亚洲午夜久久久久| 精品欧美一区二区久久| 国产一区999| 国产日韩精品视频一区| 99国产欧美久久久精品| 久久久久久免费网| 国产一区欧美二区| 久久伊人中文字幕| 成人性生交大片免费看视频在线 | 韩国v欧美v日本v亚洲v| 欧美主播一区二区三区美女| 亚洲成人资源在线| 欧洲精品在线观看| 亚洲男帅同性gay1069| 在线日韩一区二区| 天堂影院一区二区| 国产婷婷色一区二区三区| 韩国v欧美v亚洲v日本v| 日韩高清一区二区| 久久久精品中文字幕麻豆发布| 91麻豆福利精品推荐| 五月婷婷综合在线| 亚洲色欲色欲www| 国产日韩欧美精品电影三级在线| 欧美在线短视频| 韩国毛片一区二区三区| 日本亚洲电影天堂| 久久精品国产999大香线蕉| 久久久美女毛片| 日韩欧美区一区二| 91精品国产综合久久久久久久久久| 国产成人精品www牛牛影视| 亚洲一区中文日韩| 亚洲一区二区综合| 亚洲精品欧美激情| 亚洲欧美日韩国产综合| 久久久一区二区三区| 久久久久久99久久久精品网站| 国产日本欧洲亚洲| 亚洲国产成人一区二区三区| 91视频.com| 日韩精品一区二区三区中文精品| 成人污污视频在线观看| 国产精品91一区二区| 色成人在线视频| 欧美一区二区三区系列电影| 欧美丝袜自拍制服另类| 色吧成人激情小说| 91麻豆精品国产自产在线| 精品欧美久久久| 91在线国内视频| 欧美一区二区三区色| 精品久久久久久无| 国产精品女主播av| 久久se精品一区精品二区| 国产精品一区二区男女羞羞无遮挡 | 国产成人精品免费网站| 成人短视频下载| 成人高清视频在线观看| 国产综合色在线视频区| 欧美日韩精品欧美日韩精品一 | 欧美另类变人与禽xxxxx| 91麻豆精品国产91久久久使用方法 |