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

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

?? smb_ex3.c

?? c8051f020 i2c 源碼。對其操作有詳細描述。
?? C
?? 第 1 頁 / 共 2 頁
字號:
//------------------------------------------------------------------------------------
//
// Copyright 2001 Cygnal Integrated Products, Inc.
//
// FILE NAME      : SMB_Ex3.c
// TARGET DEVICE  : C8051F000
// CREATED ON     : 2/20/01
// CREATED BY     : JS
//
// Example code to demonstrate the use of the SMBus interface between two CF000 devices.
// The devices operate in a peer-to-peer configuration.
//
// Demonstration includes use of op codes for each device to command the other to:
//
// 1) Write a byte to DAC0
// 2) Write a byte to a data buffer
// 3) Perform an ADC conversion
// 4) Read a byte from a data buffer
//
// These op codes are can be tested easily if each chip has DAC0 routed to AIN0.
// With this configuration, a READ_ADC command can be used to test the output
// of a WRITE_DAC command.
//
// Code assumes that two CF0xx devices are connected via SCL and SDA, with
// slave addresses (held by register SMB0ADR)
// CHIP_A = 1111000
// CHIP_B = 1110000
//
// Test code is included.  For testing purposes, the test code should be omitted
// in one device, and run in the other.  This can be accomplished by commenting
// the OP_CODE_HANDLER() call before the test code in the device that will assume
// the master role.
//
// PLEASE NOTE that the constant MY_ADD must correspond with the
// current device - change it to CHIP_B when downloading code to CHIP_B.
//
//------------------------------------------------------------------------------------


//------------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------------
#include <c8051f000.h>                    // SFR declarations
//------------------------------------------------------------------------------------
// Global CONSTANTS
//------------------------------------------------------------------------------------

#define  WRITE       0x00                 // WRITE direction bit
#define  READ        0x01                 // READ direction bit

// Device addresses
#define  CHIP_A      0xF0
#define  CHIP_B      0xE0
#define  MY_ADD      CHIP_A               // Corresponds to the chip currently
                                          // being programmed.

// Peer-to-Peer OP_CODEs
#define  READ_ADC    0x01                 // OP_CODE to read from slave ADC
#define  WRITE_DAC   0x02                 // OP_CODE to write to slave DAC
#define  WRITE_BUF   0x03                 // OP_CODE to write to slave buffer
#define  READ_BUF    0x04                 // OP_CODE to read from slave buffer

//SMBus states:
// MT = Master Transmitter
// MR = Master Receiver
// ST = Slave Transmitter
// SR = Slave Receiver

#define  SMB_BUS_ERROR  0x00              // (all modes) BUS ERROR
#define  SMB_START      0x08              // (MT & MR) START transmitted
#define  SMB_RP_START   0x10              // (MT & MR) repeated START
#define  SMB_MTADDACK   0x18              // (MT) Slave address + W transmitted;
                                          //  ACK received
#define  SMB_MTADDNACK  0x20              // (MT) Slave address + W transmitted;
                                          //  NACK received
#define  SMB_MTDBACK    0x28              // (MT) data byte transmitted; ACK rec'vd
#define  SMB_MTDBNACK   0x30              // (MT) data byte transmitted; NACK rec'vd
#define  SMB_MTARBLOST  0x38              // (MT) arbitration lost
#define  SMB_MRADDACK   0x40              // (MR) Slave address + R transmitted;
                                          //  ACK received
#define  SMB_MRADDNACK  0x48              // (MR) Slave address + R transmitted;
                                          //  NACK received
#define  SMB_MRDBACK    0x50              // (MR) data byte rec'vd; ACK transmitted
#define  SMB_MRDBNACK   0x58              // (MR) data byte rec'vd; NACK transmitted
#define  SMB_SROADACK   0x60              // (SR) SMB's own slave address + W rec'vd;
                                          //  ACK transmitted
#define  SMB_SROARBLOST 0x68              // (SR) SMB's own slave address + W rec'vd;
                                          //  arbitration lost
#define  SMB_SRGADACK   0x70              // (SR) general call address rec'vd;
                                          //  ACK transmitted
#define  SMB_SRGARBLOST 0x78              // (SR) arbitration lost when transmitting
                                          //  slave addr + R/W as master; general
                                          //  call address rec'vd; ACK transmitted
#define  SMB_SRODBACK   0x80              // (SR) data byte received under own slave
                                          //  address; ACK returned
#define  SMB_SRODBNACK  0x88              // (SR) data byte received under own slave
                                          //  address; NACK returned
#define  SMB_SRGDBACK   0x90              // (SR) data byte received under general
                                          //  call address; ACK returned
#define  SMB_SRGDBNACK  0x98              // (SR) data byte received under general
                                          //  call address; NACK returned
#define  SMB_SRSTOP     0xa0              // (SR) STOP or repeated START received
                                          //  while addressed as a slave
#define  SMB_STOADACK   0xa8              // (ST) SMB's own slave address + R rec'vd;
                                          //  ACK transmitted
#define  SMB_STOARBLOST 0xb0              // (ST) arbitration lost in transmitting
                                          //  slave address + R/W as master; own
                                          //  slave address rec'vd; ACK transmitted
#define  SMB_STDBACK    0xb8              // (ST) data byte transmitted; ACK rec'ed
#define  SMB_STDBNACK   0xc0              // (ST) data byte transmitted; NACK rec'ed
#define  SMB_STDBLAST   0xc8              // (ST) last data byte transmitted (AA=0);
                                          //  ACK received
#define  SMB_SCLHIGHTO  0xd0              // (ST & SR) SCL clock high timer per
                                          //  SMB0CR timed out (FTE=1)
#define  SMB_IDLE       0xf8              // (all modes) Idle


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

char COMMAND;                             // Holds the slave address + R/W bit for
                                          // use in the SMBus ISR.

char WORD;                                // Holds data to be transmitted by the SMBus
                                          // OR data that has just been received.

char OP_CODE;                             // Holds an op code to be sent or one
                                          // that has just been received.

char LOST_COMMAND, LOST_WORD, LOST_CODE;  // Used to hold relevant data after a
                                          // lost arbitration.

char DATA_BUF[16];                        // Data buffer accessed by OP_CODE_HANDLER

bit LOST;                                 // Arbitration lost flag, set when
                                          // arbitration is lost while in master mode.
                                          // Used to resume a failed transfer.

bit SM_BUSY;                              // This bit is set when a send or receive
                                          // is started. It is cleared by the
                                          // ISR when the operation is finished.

bit VALID_OP;                             // Flag used to determine if byte received
                                          // as a slave is an OP_CODE or data.

bit DATA_READY;                           // Used by OP_CODE handler to flag when
                                          // valid data has been received from the
                                          // master

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

void SMBUS_ISR (void);
char SLA_READ(char chip_select, char out_op);
void SLA_SEND(char chip_select, char out_op, char out_data);
void OP_CODE_HANDLER(void);

//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------

void MAIN (void)
{
   char i, check_1, check_2;              // Variables used for testing purposes only.

   WDTCN = 0xde;                          // disable watchdog timer
   WDTCN = 0xad;

   XBR0 = 0x01;                           // Route SMBus to GPIO pins through crossbar
   XBR2 = 0x40;                           // Enable crossbar and weak pull-ups

   SMB0CN = 0x44;                         // Enable SMBus with acknowledge low (AA = 1)
   SMB0CR = -80;                          // SMBus clock rate = 100 kHz
   SMB0ADR = MY_ADD;                      // Set own slave address.

   ADC0CN = 0x80;                         // Enable ADC, conversions to start with 
                                          // write to ADBUSY.

   ADC0CN |= 0x01;                        // ADC data registers left-justified.

   DAC0CN = 0x84;                         // enable DAC0, with left justified data
                                          // registers.

   REF0CN = 0x03;                         // reference voltage enabled.

   EIE1 |= 2;                             // SMBus interrupt enable
   EA = 1;                                // Global interrupt enable

   SM_BUSY = 0;                           // Free bus for first transfer.
   SI = 0;                                //

// OP_CODE_HANDLER();                     // This line should be commented in only
                                          // one of the two peer devices.  It is
                                          // for testing purposes only.
                                          // In a normal setup, the OP_CODE_HANDLER 
                                          // would be running at all times in order
                                          // to react to OP_CODES being sent to the
                                          // device.

// TEST CODE--------------------------------------------------------------------------
// This code is used only to test the interface between the two devices. If
// the above OP_CODE_HANDLER line is commented out, this device assumes the master 
// role. The other device should be running the OP_CODE_HANDLER at all times, to 
// respond to the OP_CODEs below.

   SLA_SEND(CHIP_B, (0x40 | WRITE_BUF), 0x24);     // Write to index 4
                                                   // in the data buffer
   SLA_SEND(CHIP_B, (0x60 | WRITE_BUF), 0x25);     // Write to index 6
   SLA_SEND(CHIP_B, (0x80 | WRITE_BUF), 0x26);     // Write to index 8
   SLA_SEND(CHIP_B, (0x10 | WRITE_BUF), 0x27);     // Write to index 1

   check_1 = SLA_READ(CHIP_B, (0x40 | READ_BUF));  // Read index 4 from the buffer
   check_1 = SLA_READ(CHIP_B, (0x60 | READ_BUF));  // Read index 6
   check_1 = SLA_READ(CHIP_B, (0x80 | READ_BUF));  // Read index 8
   check_1 = SLA_READ(CHIP_B, (0x10 | READ_BUF));  // Read index 1


// Loop to continuously increase the DAC output on CHIP_B, and read its
// ADC each round. DAC output on CHIP_B should ramp.

   for (i=0;i<50;i++){
      SLA_SEND(CHIP_B, WRITE_DAC, 2*i);            // Write 2*i to DAC0 on CHIP_B
      check_1 = SLA_READ(CHIP_B, READ_ADC);        // Read AIN0 on CHIP_B
      check_2 = 2*i;}                              // check_1 should be approximately
                                                   // the same as check_2.
// END TEST CODE----------------------------------------------------------------------

}

//------------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------------

// Send to slave.
// The send function transmits two bytes to the slave device: an op code, and a data
// byte.  There are two op code choices for sending data: WRITE_DAC and WRITE_BUF.
// If the op code is WRITE_BUF, then the upper 4 bits of the op code should contain
// the buffer index.  For example, to write to index 2 of the data buffer, the
// op_code parameter should be (0x20 | WRITE_BUF).
//
// chip_select = address of slave device.
// out_op = OP_CODE to be sent.
// out_data = data byte to be sent.
void SLA_SEND(char chip_select, char out_op, char out_data){

   while(SM_BUSY);                        // Wait while SMBus is busy.
   SM_BUSY = 1;                           // SMBus busy flag set.
   SMB0CN = 0x44;                         // SMBus enabled, ACK low.
   COMMAND = (chip_select | WRITE);       // COMMAND = 7 address bits + WRITE.
   OP_CODE = out_op;                      // WORD = OP_CODE to be transmitted.
   WORD = out_data;                       // DATA = data to be transmitted.
   STO = 0;
   STA = 1;                               // Start transfer.

}

// Read from slave.
// The read function transmits a 1-byte op code, then issues a repeated start
// to request a 1-byte read.  The two op code choices are READ_ADC and READ_BUF.
// If the op code is READ_BUF, then the upper 4 bits of the op code should
// contain the buffer index.  For example, to read index 5 of the data buffer,
// the op code should be (0x50 | READ_BUF).
//
// chip_select = address of slave device.
// out_op = OP_CODE to be sent.
char SLA_READ(char chip_select, char out_op){

   while(SM_BUSY);                        // Wait while SMBus is busy.
   SM_BUSY = 1;                           // Set busy flag.
   SMB0CN = 0x44;                         // Enable SMBus, ACK low.
   COMMAND = (chip_select | READ);        // COMMAND = 7 address bits + READ
   OP_CODE = out_op;
   STO = 0;
   STA = 1;                               // Start transfer.
   while(SM_BUSY);                        // Wait for transfer to finish.
   return WORD;                           // Return received word.

}


// OP_CODE handler.
// Decodes incoming op codes and performs tasks according to those op codes.
// A call to this function runs forever.
//
// The VALID_OP bit flags when a valid op code has been received.  Upon receipt,
// the handler decodes the op code, performs the task, then clears
// VALID_OP to wait for another code.
void OP_CODE_HANDLER(void){

   char index;                            // data buffer index
   while (1){                             // run forever
      VALID_OP = 0;                       // Wait for a valid OP_CODE
      while (!VALID_OP);                  //

      // The lower 4 bits of the OP_CODE are used to determine the action, while the
      // upper 4 bits are used to index the DATA_BUF array when the READ_BUF or

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99免费精品视频| 激情偷乱视频一区二区三区| 成人免费视频播放| 精品久久久久av影院| 亚洲成av人片观看| 欧美日韩精品欧美日韩精品一综合| 国产欧美一区二区三区鸳鸯浴| 免费观看91视频大全| 日韩欧美在线不卡| 男女男精品视频| 精品成人a区在线观看| 久久精品72免费观看| 精品久久99ma| 国产一区二区不卡在线 | 婷婷开心久久网| 欧美一级日韩不卡播放免费| 蜜臀av一区二区在线免费观看| 这里只有精品电影| 久久成人免费网站| 国产免费久久精品| 在线这里只有精品| 日韩电影在线观看网站| 久久蜜桃一区二区| 99热在这里有精品免费| 亚洲精品中文在线观看| 欧美精品久久天天躁| 另类小说欧美激情| 国产精品色呦呦| 欧美色窝79yyyycom| 蜜桃精品视频在线| 亚洲三级视频在线观看| 日韩一区二区中文字幕| 国产成人免费av在线| 亚洲最大成人综合| 久久久久久久久久久久久夜| 91污在线观看| 韩国在线一区二区| 五月天久久比比资源色| 久久午夜羞羞影院免费观看| 99久久久久免费精品国产| 亚洲成人免费av| 日韩久久一区二区| 日韩欧美黄色影院| 欧美在线|欧美| 国产91高潮流白浆在线麻豆| 午夜精品久久久久久久| 欧美精品一二三区| 国产精品系列在线播放| 麻豆91小视频| 亚洲资源中文字幕| 最新日韩av在线| 久久久久久久久蜜桃| 精品欧美一区二区三区精品久久| 欧美性受极品xxxx喷水| 91麻豆国产香蕉久久精品| 国产成人99久久亚洲综合精品| 免费高清在线一区| 日韩中文字幕区一区有砖一区| 亚洲免费观看在线视频| 国产精品高潮呻吟| 中文字幕亚洲一区二区av在线| 2020国产精品自拍| 26uuu精品一区二区| 欧美成人国产一区二区| 日韩片之四级片| 亚洲精品在线免费观看视频| 日韩欧美国产高清| 久久综合精品国产一区二区三区| 欧美一二三四在线| 欧美mv和日韩mv的网站| 欧美tk丨vk视频| 久久久精品国产免费观看同学| 久久综合国产精品| 中文字幕一区二区三区在线播放| **网站欧美大片在线观看| 亚洲精选一二三| 婷婷成人激情在线网| 麻豆精品视频在线观看| 国产成人在线观看| 一本大道av伊人久久综合| 在线亚洲高清视频| 日韩欧美亚洲一区二区| 欧美激情综合五月色丁香小说| 国产精品三级视频| 午夜精品一区在线观看| 六月丁香综合在线视频| 成人精品亚洲人成在线| 欧美色综合网站| 久久欧美一区二区| 亚洲色图视频免费播放| 青青草国产成人av片免费| 福利一区福利二区| 欧美精品久久99久久在免费线| 亚洲精品一区二区三区影院| 亚洲天堂av一区| 狠狠狠色丁香婷婷综合激情 | 美国三级日本三级久久99| 成人小视频在线观看| 678五月天丁香亚洲综合网| 久久精品夜色噜噜亚洲a∨| 亚洲国产毛片aaaaa无费看 | 日韩欧美不卡在线观看视频| 国产精品久久久一区麻豆最新章节| 婷婷开心激情综合| 92精品国产成人观看免费| 日韩欧美成人激情| 亚洲午夜影视影院在线观看| 粉嫩高潮美女一区二区三区| 欧美精品tushy高清| 亚洲美女视频一区| 成人avav在线| 欧美极品美女视频| 国产在线精品国自产拍免费| 欧美日韩不卡一区| 亚洲国产日韩精品| 91官网在线免费观看| 亚洲日本在线天堂| 99re6这里只有精品视频在线观看 99re8在线精品视频免费播放 | 亚洲欧洲在线观看av| 国产福利一区二区三区视频| 欧美精品一区男女天堂| 精品亚洲免费视频| 久久综合狠狠综合久久综合88 | 欧美日韩一区二区三区不卡| 一级精品视频在线观看宜春院| 91蜜桃婷婷狠狠久久综合9色| 国产精品电影一区二区| av在线一区二区| 亚洲人午夜精品天堂一二香蕉| 暴力调教一区二区三区| 中文字幕一区二区三| 99久久国产综合色|国产精品| 成人av电影在线| 欧美日韩国产大片| 午夜精品成人在线视频| 欧美一区二区三区在线视频| 蜜桃久久精品一区二区| 精品日韩一区二区三区免费视频| 国产一区啦啦啦在线观看| 久久精品一区二区三区四区| av中文字幕不卡| 午夜视频一区在线观看| 精品国产一二三区| 成人动漫av在线| 日日欢夜夜爽一区| 国产欧美va欧美不卡在线| 色乱码一区二区三区88| 日本午夜精品视频在线观看| 国产亚洲视频系列| 91美女精品福利| 丝袜诱惑制服诱惑色一区在线观看| 欧美电视剧在线看免费| 国产乱码精品一品二品| 一片黄亚洲嫩模| 久久久欧美精品sm网站| 欧美午夜精品一区二区蜜桃| 国产伦精一区二区三区| 亚洲成人tv网| 国产精品欧美久久久久无广告| 欧美日韩国产一级二级| 高清国产一区二区三区| 蜜桃av噜噜一区| 亚洲成人激情自拍| 国产精品理论在线观看| 日韩精品一区国产麻豆| 欧美私人免费视频| 91亚洲国产成人精品一区二三| 久久国产精品无码网站| 午夜精品在线视频一区| 亚洲欧美综合在线精品| xnxx国产精品| 精品国内二区三区| 日韩视频一区二区三区| 欧美午夜精品一区| 93久久精品日日躁夜夜躁欧美| 国产乱码精品一区二区三| 精品一二三四区| 国产在线不卡视频| 精品亚洲国产成人av制服丝袜| 天堂va蜜桃一区二区三区漫画版| 一个色综合av| 亚洲网友自拍偷拍| 午夜精品久久久久| 日韩主播视频在线| 麻豆成人免费电影| 国内精品免费**视频| 国产一区二区福利视频| 国产麻豆日韩欧美久久| 成人激情免费视频| 一本久久a久久免费精品不卡| 91久久精品一区二区三区| 在线观看视频一区二区欧美日韩| 91电影在线观看| 欧美剧情电影在线观看完整版免费励志电影| 94色蜜桃网一区二区三区| 欧美综合在线视频| 日韩欧美在线123| 国产亚洲va综合人人澡精品| 中文字幕一区二区三| 亚洲国产综合色|