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

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

?? f31x_smbus_eeprom.c

?? C8051F31系列單片機的例子
?? C
?? 第 1 頁 / 共 2 頁
字號:
//-----------------------------------------------------------------------------
// F31x_SMBus_EEPROM.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This example demonstrates how the C8051F31x SMBus interface can communicate
// with a 256 byte I2C Serial EEPROM (Microchip 24LC02B).
// - Interrupt-driven SMBus implementation
// - Only master states defined (no slave or arbitration)
// - Timer1 used as SMBus clock source
// - Timer3 used by SMBus for SCL low timeout detection
// - SCL frequency defined by <SMB_FREQUENCY> constant
// - 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 24LC02B serial
//    EEPROM (see the EEPROM datasheet for the pinout information).
// 2) Run the code:
//         a) the test will indicate proper communication with the EEPROM by
//            turning on the LED at the end the end of the test
//         b) the test can also be verified by running to the if statements
//            in main and checking the sent and received values by adding
//            the variables to the Watch Window
//
//
// FID:            31X000008
// 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  50000          // 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  EEPROM_ADDR    0xA0           // Device address for slave target
                                       // Note: This address is specified
                                       // in the Microchip 24LC02B
                                       // datasheet.
// SMBus Buffer Size
#define  SMB_BUFF_SIZE  0x08           // Defines the maximum number of bytes
                                       // that can be sent or received in a
                                       // single transfer

// 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* pSMB_DATA_IN;           // Global pointer for SMBus data
                                       // All receive data is written here

unsigned char SMB_SINGLEBYTE_OUT;      // Global holder for single byte writes.

unsigned char* pSMB_DATA_OUT;          // Global pointer for SMBus data.
                                       // All transmit data is read from here

unsigned char SMB_DATA_LEN;            // Global holder for number of bytes
                                       // to send or receive in the current
                                       // SMBus transfer.

unsigned char WORD_ADDR;               // Global holder for the EEPROM word
                                       // address that will be accessed in
                                       // the next transfer

unsigned char TARGET;                  // Target SMBus slave address

bit SMB_BUSY = 0;                      // Software flag to indicate when the
                                       // EEPROM_ByteRead() or
                                       // EEPROM_ByteWrite()
                                       // functions have claimed the SMBus

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

bit SMB_SENDWORDADDR;                  // When set, this flag causes the ISR
                                       // to send the 8-bit <WORD_ADDR>
                                       // after sending the slave address.


bit SMB_RANDOMREAD;                    // When set, this flag causes the ISR
                                       // to send a START signal after sending
                                       // the word address.
                                       // For the 24LC02B EEPROM, a random read
                                       // (a read from a particular address in
                                       // memory) starts as a write then
                                       // changes to a read after the repeated
                                       // start is sent. The ISR handles this
                                       // switchover if the <SMB_RANDOMREAD>
                                       // bit is set.

bit SMB_ACKPOLL;                       // When set, this flag causes the ISR
                                       // to send a repeated START until the
                                       // slave has acknowledged its address

sfr16    TMR3RL   = 0x92;              // Timer3 reload registers
sfr16    TMR3     = 0x94;              // Timer3 counter registers

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 Timer1_Init(void);
void Timer3_Init(void);
void Port_Init(void);

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

void EEPROM_ByteWrite(unsigned char addr, unsigned char dat);
void EEPROM_WriteArray(unsigned char dest_addr, unsigned char* src_addr,
                       unsigned char len);
unsigned char EEPROM_ByteRead(unsigned char addr);
void EEPROM_ReadArray(unsigned char* dest_addr, unsigned char src_addr,
                      unsigned char len);

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------
//
// Main routine performs all configuration tasks, then loops forever sending
// and receiving SMBus data to the slave EEPROM.

void main (void)
{
   char in_buff[8] = {0};              // Incoming data buffer
   char out_buff[8] = "ABCDEFG";       // Outgoing data buffer

   unsigned char temp_char;            // Temporary variable
   bit error_flag = 0;                 // Flag for checking EEPROM contents
   unsigned char i;                    // Temporary counter variable


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


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

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

   LED = 0;                            // Turn off the LED before the test
                                       // starts


   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

   EA = 1;                             // Global interrupt enable



   // Read and write some bytes to the EEPROM and check for proper
   // communication

   // Write the value 0xAA to location 0x25 in the EEPROM
   EEPROM_ByteWrite(0x25, 0xAA);

   // Read the value at location 0x25 in the EEPROM
   temp_char = EEPROM_ByteRead(0x25);

   // Check that the data was read properly
   if (temp_char != 0xAA)
   {
      error_flag = 1;
   }

   // Write the value 0xBB to location 0x25 in the EEPROM
   EEPROM_ByteWrite(0x25, 0xBB);

   // Write the value 0xCC to location 0x38 in the EEPROM
   EEPROM_ByteWrite(0x38, 0xCC);

   // Read the value at location 0x25 in the EEPROM
   temp_char = EEPROM_ByteRead(0x25);

   // Check that the data was read properly
   if (temp_char != 0xBB)
   {
      error_flag = 1;
   }

   // Read the value at location 0x38 in the EEPROM
   temp_char = EEPROM_ByteRead(0x38);

   // Check that the data was read properly
   if (temp_char != 0xCC)
   {
      error_flag = 1;
   }

   // Store the outgoing data buffer at EEPROM address 0x50
   EEPROM_WriteArray(0x50, out_buff, sizeof(out_buff));

   // Fill the incoming data buffer with data starting at EEPROM address 0x50
   EEPROM_ReadArray(in_buff, 0x50, sizeof(in_buff));

   // Check that the data that came from the EEPROM is the same as what was
   // sent
   for (i = 0; i < sizeof(in_buff); i++)
   {
      if (in_buff[i] != out_buff[i])
      {
         error_flag = 1;
      }
   }

   // Indicate communication is good
   if (error_flag == 0)
   {
      // LED = ON indicates that the test passed
      LED = 1;
   }

   while(1);

}

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

//-----------------------------------------------------------------------------
// SMBus_Init()
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// The SMBus peripheral is configured as follows:
// - SMBus enabled
// - Slave mode disabled
// - Timer1 used as clock source. The maximum SCL frequency will be
//   approximately 1/3 the Timer1 overflow rate
// - Setup and hold time extensions enabled
// - 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 is configured as the SMBus clock source as follows:
// - Timer1 in 8-bit auto-reload mode
// - SYSCLK / 12 as Timer1 clock source
// - Timer1 overflow rate => 3 * SMB_FREQUENCY
// - The maximum 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

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

   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)

   EIE1 |= 0x80;                       // Timer3 interrupt enable
   TMR3CN |= 0x04;                     // Start Timer3

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www.日韩av| 午夜电影一区二区| 成人动漫一区二区| 欧美国产综合一区二区| 国产精品一区二区x88av| 91.麻豆视频| 男女性色大片免费观看一区二区| 欧美日本乱大交xxxxx| 人人精品人人爱| 欧美一区二区国产| 精品一区二区免费看| 精品电影一区二区三区| 丁香亚洲综合激情啪啪综合| 国产日产精品1区| 一本大道久久a久久精二百 | 国产精品欧美综合在线| 美女视频免费一区| 久久综合中文字幕| 99久久精品国产观看| 午夜久久久久久电影| 精品久久久久一区二区国产| 国产精品1区2区3区在线观看| 国产精品二三区| 欧美日韩五月天| 国产激情一区二区三区桃花岛亚洲| www精品美女久久久tv| 一道本成人在线| 六月婷婷色综合| 国产精品女人毛片| 欧美在线视频你懂得| 婷婷综合另类小说色区| 久久久www成人免费无遮挡大片 | 欧美精品xxxxbbbb| 国产一区二区三区免费播放| 亚洲精品高清在线观看| 欧美日韩日日摸| 国产成人精品免费视频网站| 亚洲午夜久久久久久久久电影院| 欧美变态口味重另类| 欧美影院午夜播放| 成人高清免费观看| 亚洲大片在线观看| 国产欧美一区二区在线| 91精品国产黑色紧身裤美女| 成人午夜电影久久影院| 首页国产丝袜综合| 日韩理论片在线| 久久久电影一区二区三区| 日韩三级电影网址| 欧美肥妇bbw| 在线观看亚洲精品视频| 国产不卡在线播放| 蜜桃一区二区三区在线观看| 亚洲欧美日韩国产另类专区| 久久久久久久久一| 国产日韩精品一区二区浪潮av| 884aa四虎影成人精品一区| 欧美日韩一区三区四区| 欧美日韩一级片在线观看| 欧美性色欧美a在线播放| 色先锋久久av资源部| 在线精品国精品国产尤物884a| 97精品电影院| 在线观看一区日韩| 欧美日韩视频一区二区| 91.成人天堂一区| 日韩网站在线看片你懂的| 欧美一区二区观看视频| 欧美刺激午夜性久久久久久久| 91精品国产aⅴ一区二区| 日韩一区二区三区电影在线观看| 91精品国产一区二区三区香蕉| 制服.丝袜.亚洲.另类.中文| 欧美另类久久久品| 精品久久一二三区| 久久精品一区二区三区av| 久久人人超碰精品| 亚洲女与黑人做爰| 午夜欧美大尺度福利影院在线看| 免费成人在线网站| 国产麻豆精品theporn| 国产毛片精品视频| 成人精品一区二区三区中文字幕| a级精品国产片在线观看| 欧美三级乱人伦电影| 欧美成人三级在线| 日韩一区有码在线| 中文字幕亚洲区| 日本成人在线一区| av不卡免费在线观看| 精品成a人在线观看| 偷拍与自拍一区| 欧洲av一区二区嗯嗯嗯啊| 国产日韩综合av| 免费成人小视频| 欧美日产国产精品| 亚洲综合无码一区二区| 成av人片一区二区| 久久精品网站免费观看| 久久不见久久见免费视频7 | 欧美乱熟臀69xxxxxx| 亚洲免费三区一区二区| jlzzjlzz亚洲日本少妇| 国产欧美日韩视频在线观看| 极品美女销魂一区二区三区免费| 欧美精品视频www在线观看| 亚洲五月六月丁香激情| 欧美体内she精高潮| 亚洲亚洲人成综合网络| 91久久久免费一区二区| 亚洲精品国产a久久久久久| jlzzjlzz欧美大全| 亚洲精品国产无套在线观| 91麻豆国产自产在线观看| 国产精品的网站| 91在线免费看| 一区二区欧美视频| 欧美色电影在线| 亚洲123区在线观看| 欧美理论在线播放| 亚洲综合图片区| 在线精品亚洲一区二区不卡| 亚洲成va人在线观看| 欧美精品久久久久久久久老牛影院| 亚洲不卡av一区二区三区| 欧美一区二区三区爱爱| 韩国理伦片一区二区三区在线播放 | 麻豆成人综合网| 亚洲国产高清aⅴ视频| 欧美亚州韩日在线看免费版国语版| 日韩成人一级片| 国产亚洲人成网站| 欧美体内she精高潮| 精品制服美女丁香| 亚洲人123区| 日韩欧美一区二区不卡| 91免费视频网址| 毛片基地黄久久久久久天堂| 午夜精品久久久久久久| 日韩亚洲国产中文字幕欧美| 懂色av一区二区夜夜嗨| 天堂va蜜桃一区二区三区漫画版| 精品国产免费一区二区三区四区| 99久久综合精品| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产精品美女久久久久av爽李琼| 欧美猛男超大videosgay| 丁香婷婷综合五月| 久久99精品国产91久久来源| 亚洲综合清纯丝袜自拍| 国产精品伦一区| 国产欧美一区视频| 欧美精品成人一区二区三区四区| 96av麻豆蜜桃一区二区| 国产成人日日夜夜| 美女尤物国产一区| 亚洲国产精品尤物yw在线观看| 中文字幕色av一区二区三区| 精品少妇一区二区三区视频免付费 | 亚洲国产一区二区视频| 日韩一区在线免费观看| 国产精品成人一区二区艾草 | 国产性色一区二区| 日韩一区二区免费在线电影| 色综合 综合色| 色综合久久久久综合| www.欧美色图| 91蝌蚪porny| 99久久99久久精品免费看蜜桃| 高清不卡在线观看| 成人小视频在线| 成人国产在线观看| 一本色道久久综合亚洲精品按摩| eeuss鲁片一区二区三区| 99麻豆久久久国产精品免费| 97se亚洲国产综合在线| 色综合久久88色综合天天| 欧洲另类一二三四区| 欧美日韩精品专区| 日韩欧美精品在线视频| 久久影院电视剧免费观看| 国产亚洲婷婷免费| 亚洲视频一二区| 亚洲精品国产品国语在线app| 亚洲另类春色国产| 日本不卡中文字幕| 国产一本一道久久香蕉| 91首页免费视频| 欧美精品一卡二卡| 国产色综合久久| 亚洲高清免费观看| 国产精品一区二区久久精品爱涩| 国产成人啪午夜精品网站男同| 国产一区二区剧情av在线| 成人免费视频视频在线观看免费| 91久久人澡人人添人人爽欧美 | 国产在线精品免费| 91香蕉视频污| 日韩欧美专区在线| 亚洲精品菠萝久久久久久久|