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

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

?? f500_smbus_master.c

?? C8051F500開發編程:MCU全部資源應用實例
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// F500_SMBus_Master.c
//-----------------------------------------------------------------------------
// Copyright 2008 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Example software to demonstrate the C8051F500 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
// - Timer3 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)
//    P1.3 -> LED
//
//    all other port pins unused
//
// How To Test:
//
// 1) Verify that J22 is not populated.
// 2) Download code to a 'F500 device that is connected to a SMBus slave.
// 3) 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.
//
//
// Target:         C8051F500 (Side A of a C8051F500-TB)
// Tool chain:     Keil C51 8.0 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0 / 07 JUL 2008 (GP)
//    -Initial Revision
//

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

#include <compiler_defs.h>
#include <C8051F500_defs.h>            // SFR declarations

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

#define  SYSCLK         24000000       // 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
//-----------------------------------------------------------------------------
U8 SMB_DATA_IN;                        // Global holder for SMBus data
                                       // All receive data is written here

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

U8 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

U16 NUM_ERRORS;                        // Counter for the number of errors.

SBIT (LED, SFR_P1, 3);                 // LED==1 means ON

SBIT (SDA, SFR_P0, 0);                 // SMBus on P0.0
SBIT (SCL, SFR_P0, 1);                 // and P0.1

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

void SMBUS0_Init (void);
void TIMER1_Init (void);
void TIMER3_Init (void);
void PORT_Init (void);

INTERRUPT_PROTO (TIMER3_ISR, INTERRUPT_TIMER3);
INTERRUPT_PROTO (SMBUS0_ISR, INTERRUPT_SMBUS0);

void SMB_Write (void);
void SMB_Read (void);
void T0_Wait_ms (U8 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 U8 dat;                    // Test counter
   U8 i;                               // Dummy variable counters

   SFRPAGE = ACTIVE_PAGE;              // Set SFR Page for PCA0

   PCA0MD = 0x00;                      // Disable watchdog timer

   SFRPAGE = CONFIG_PAGE;              // Set SFR Page for XBR and port pins

   OSCICN |= 0x07;                     // Set internal oscillator to 24 MHz


   // 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.
      XBR2 = 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
      XBR2 = 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

   SMBUS0_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 F3xx/Si8250 Slave for next
                                       // SMBus transfer
      SMB_Write();                     // Initiate SMBus write

      // SMBus Read Sequence
      TARGET = SLAVE_ADDR;             // Target the F3xx/Si8250 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 (50);                  // Wait 50 ms until the next cycle
                                        // so that LED blinks slow enough to see

   }

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

}

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

//-----------------------------------------------------------------------------
// SMBUS0_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 SMBUS0_Init (void)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = ACTIVE_PAGE;

   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;

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// 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)
{
   U8 SFRPAGE_save = SFRPAGE;
   SFRPAGE = ACTIVE_PAGE;

// 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 = -(S8)(SYSCLK/SMB_FREQUENCY/SCALE/3);

   TL1 = TH1;                          // Init Timer1

   TR1 = 1;                            // Timer1 enabled

   SFRPAGE = SFRPAGE_save;
}

//-----------------------------------------------------------------------------
// TIMER3_Init

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产jizzjizz一区二区| 久久精品欧美日韩| 国产精品电影一区二区| 国产69精品久久99不卡| 久久一夜天堂av一区二区三区| 秋霞影院一区二区| 欧美一级片在线看| 麻豆成人久久精品二区三区红| 欧美精品v日韩精品v韩国精品v| 久久久蜜臀国产一区二区| 国产成人免费av在线| 久久久久久久网| 成人美女视频在线观看18| 国产精品区一区二区三区| av在线不卡免费看| 日韩美女视频19| 欧美午夜电影一区| 日本欧美在线观看| 久久久久久免费网| 高清久久久久久| 成人欧美一区二区三区白人| 色婷婷综合五月| 午夜久久久久久| 欧美不卡一区二区三区| 国产老肥熟一区二区三区| 中文久久乱码一区二区| 一本久道中文字幕精品亚洲嫩 | 国产精品久久久久久久久久久免费看| 顶级嫩模精品视频在线看| 中文字幕亚洲区| 色婷婷狠狠综合| 日本不卡视频在线观看| 欧美经典三级视频一区二区三区| 色域天天综合网| 日韩中文字幕不卡| 久久精品国产秦先生| 国产精品污网站| 欧美日韩精品系列| 国产成人啪免费观看软件| 国产精品国产三级国产| 欧美人伦禁忌dvd放荡欲情| 国产一区999| 亚洲一区二区三区美女| 久久青草国产手机看片福利盒子| 成人高清视频免费观看| 日韩中文字幕1| 亚洲欧洲成人自拍| 欧美大片一区二区| 在线精品亚洲一区二区不卡| 韩国精品主播一区二区在线观看| 国产精品久久久久久妇女6080| 欧美二区在线观看| 99久久婷婷国产综合精品| 青青草成人在线观看| 亚洲欧洲av在线| 7777精品久久久大香线蕉| 成人黄色小视频| 精品一区二区在线免费观看| 亚洲一级片在线观看| 欧美国产成人在线| 日韩一区二区电影| 欧美午夜精品电影| 99久久99久久精品免费看蜜桃| 六月丁香婷婷色狠狠久久| 亚洲久本草在线中文字幕| 久久久.com| 欧美电影免费观看高清完整版在 | 精品一区二区在线视频| 亚洲一区在线观看免费观看电影高清| 国产午夜亚洲精品午夜鲁丝片| 欧美日韩国产综合一区二区三区| 日韩片之四级片| 成人爱爱电影网址| 麻豆专区一区二区三区四区五区| 亚洲一区视频在线| 亚洲婷婷综合久久一本伊一区| 久久精品一区八戒影视| 日韩欧美一级在线播放| 在线91免费看| 欧美日韩国产a| 色欧美日韩亚洲| 91免费国产在线| 91在线你懂得| 色婷婷激情综合| 色妹子一区二区| 日本精品一区二区三区四区的功能| 国产乱色国产精品免费视频| 蜜臀久久久久久久| 免费观看日韩av| 老司机精品视频在线| 麻豆精品一区二区三区| 久草在线在线精品观看| 九九精品视频在线看| 国产综合色在线视频区| 国产综合久久久久久久久久久久| 精品一区二区久久| 国产综合久久久久久鬼色| 国产成人综合在线| 国产成人免费在线视频| 成人av在线观| 色综合久久99| 亚洲图片激情小说| 一区二区三区中文免费| 亚洲一区二区三区爽爽爽爽爽 | 91久久免费观看| 91网站最新网址| 欧美色综合天天久久综合精品| 欧美系列亚洲系列| 555www色欧美视频| 精品精品国产高清一毛片一天堂| 精品国产污网站| 欧美高清在线一区二区| 亚洲欧洲精品天堂一级 | 亚洲国产精品久久久久秋霞影院| 日日夜夜一区二区| 美女mm1313爽爽久久久蜜臀| 国产精品一区二区久久不卡| av在线不卡免费看| 欧美美女一区二区| 久久品道一品道久久精品| 国产精品久久久久久久午夜片| 国产日韩精品一区| 一区二区三区产品免费精品久久75| 日韩 欧美一区二区三区| 韩国一区二区在线观看| 不卡的av在线| 欧美一二三区在线观看| 亚洲国产激情av| 中文字幕亚洲在| 午夜天堂影视香蕉久久| 国产69精品一区二区亚洲孕妇| 日本精品免费观看高清观看| 精品日韩欧美在线| 亚洲欧美另类综合偷拍| 美腿丝袜亚洲色图| 91视频精品在这里| 91啪亚洲精品| 日韩欧美色综合网站| 亚洲一区二区视频在线| av在线这里只有精品| 久久伊人蜜桃av一区二区| 日韩高清一区二区| 欧美日韩一区二区三区四区五区| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 成人一区二区视频| 日韩一区二区三区精品视频 | 午夜精品免费在线| 91免费版在线看| 国产精品你懂的在线欣赏| 欧美精品在欧美一区二区少妇| 亚洲欧洲精品成人久久奇米网| 久久99精品久久久久| 欧美一区二区三区四区高清| 亚洲精品乱码久久久久久黑人 | 久久精品国产一区二区三| 欧美日本国产一区| 亚洲超丰满肉感bbw| 91成人免费在线视频| 伊人性伊人情综合网| 一本久道中文字幕精品亚洲嫩| 国产精品无码永久免费888| 成人深夜视频在线观看| 国产欧美日韩视频在线观看| 国产成人鲁色资源国产91色综 | 成人国产精品免费网站| 国产亚洲成av人在线观看导航| 国模套图日韩精品一区二区 | 中文字幕欧美激情| 国产成人免费视频一区| 亚洲国产精品精华液2区45| 国产一区免费电影| 中文字幕电影一区| 北条麻妃国产九九精品视频| 亚洲视频 欧洲视频| 日本黄色一区二区| 亚洲v中文字幕| 91麻豆精品国产91久久久使用方法| 首页亚洲欧美制服丝腿| 欧美成人免费网站| 国产福利一区二区三区视频| 国产精品日日摸夜夜摸av| 99re热这里只有精品视频| 亚洲免费观看高清在线观看| 精品视频资源站| 久久狠狠亚洲综合| 国产精品入口麻豆原神| 在线观看亚洲成人| 美女一区二区视频| 久久久久久**毛片大全| 99久久国产综合精品色伊| 亚洲精品日日夜夜| 日韩一区二区三区在线| 国产精品系列在线播放| 亚洲精品高清在线观看| 欧美一区二区视频在线观看 | 91传媒视频在线播放| 日韩高清在线电影| 久久久久久综合| 在线亚洲一区二区| 麻豆精品久久精品色综合|