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

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

?? i2c8583.c

?? pcf8583實時時鐘芯片單片機C51幾口程序
?? C
字號:
//------------------------------------------------------------------------------------
//
// Copyright 2001 Cygnal Integrated Products, Inc.
//
// FILE NAME      : SMB_Ex2.c
// TARGET DEVICE  : C8051F000
// CREATED ON     : 2/20/01
// CREATED BY     : JS
//
//
// Example code for interfacing a C8051F0xx to three EEPROMs via the SMBus.
// Code assumes that three 16-bit address space EEPROMs are connected
// on the SCL and SDA lines, and configured so that their slave addresses
// are as follows:
// CHIP_A = 1010000
// CHIP_B = 1010001
// CHIP_C = 1010010
//
// Slave and arbitration states are not defined.  Assume the CF000 is the only
// master in the system.
// Functions: SM_Send performs a 1-byte write to the specified EEPROM
// SM_Receive performs a 1-byte read of the specified EEPROM address (both include
// memory address references).
//
// Includes test code section.

//------------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------------
#include <c8051f020.h>              // SFR declarations

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

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

// Device addresses (7 bits, lsb is a don't care)
#define CHIP_A 0xA0                 // Device address for chip A
//#define CHIP_B 0xA2                 // Device address for chip B
//#define CHIP_C 0xA4                 // Device address for chip C

// SMBus states:
// MT = Master Transmitter
// MR = Master 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


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

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

unsigned char BYTE_NUMBER;                   // Used by ISR to check what data has just been
                                    // sent - High address byte, Low byte, or data
                                    // byte

unsigned char HIGH_ADD, LOW_ADD;    // High & Low byte for EEPROM memory address

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.
unsigned char  second,minute,hour;

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

void SMBus_ISR (void);
void SM_Send (unsigned char chip_select, unsigned char byte_address, unsigned char out_byte);
unsigned char SM_Receive (unsigned char chip_select, unsigned char byte_address);
void delay(unsigned int ys);
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
//
// Main routine configures the crossbar and SMBus, and tests
// the SMBus interface between the three EEPROMs
void main (void)
{
   //unsigned char second;             // Used for testing purposes

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

   OSCICN |= 0x03;                  // Set internal oscillator to highest setting
                                    // (16 MHz)

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

   SMB0CN = 0x44;                   // Enable SMBus with ACKs on acknowledge 
                                    // cycle
   SMB0CR = -80;                    // SMBus clock rate = 100kHz.

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

   SM_BUSY = 0;                     // Free SMBus for first transfer.


//	SM_Send(CHIP_A,0x00,0x80);
//	SM_Send(CHIP_A,0x02,0x30);
//	SM_Send(CHIP_A,0x03,0x31);
//	SM_Send(CHIP_A,0x04,0x09);
//	SM_Send(CHIP_A,0x00,0x00);
   while(1)
   {//second=SM_Receive(CHIP_A,2);
    //second_h=(SM_Receive(CHIP_A,2))/16;
    //second_l=(SM_Receive(CHIP_A,2))%16;
//	SM_Send(CHIP_A,0x10,0x48);
//	SM_Send(CHIP_A,0x20,0x50);
//	SM_Send(CHIP_A,0x30,0x38);
//	SM_Send(CHIP_A,0x10,0x55);
//	SM_Send(CHIP_A,0x20,0x50);
	//second=SM_Receive(CHIP_A,0x20);
	hour=SM_Receive(CHIP_A,0x04);
	minute=SM_Receive(CHIP_A,0x03);
	second=SM_Receive(CHIP_A,0x02);
    delay(1000);

   }
}

void delay(unsigned int ys)
{unsigned int i;
 for(i=0;i<ys;i++);
}
// SMBus byte write function-----------------------------------------------------
// Writes a single byte at the specified memory location.
//
// out_byte = data byte to be written
// byte_address = memory location to be written into (2 bytes)
// chip_select = device address of EEPROM chip to be written to
void SM_Send (unsigned char chip_select, unsigned char byte_address, unsigned char out_byte)
{
   while (SM_BUSY);                          // Wait for SMBus to be free.
   SM_BUSY = 1;                              // Occupy SMBus (set to busy)
   SMB0CN = 0x44;                            // SMBus enabled,
                                             // ACK on acknowledge cycle

   BYTE_NUMBER = 1;//2                          // 1 address byte.
   COMMAND = (chip_select | WRITE);          // Chip select + WRITE

   //HIGH_ADD = ((byte_address >> 8) & 0x00FF);// Upper 8 address bits
   LOW_ADD = (byte_address & 0xFF);        // Lower 4 address bits

   WORD = out_byte;                          // Data to be writen
   
   STO = 0;
   STA = 1;                                  // Start transfer

}

// SMBus random read function------------------------------------------------------
// Reads 1 byte from the specified memory location.
//
// byte_address = memory address of byte to read
// chip_select = device address of EEPROM to be read from
unsigned char SM_Receive (unsigned char chip_select, unsigned char byte_address)
{
   while (SM_BUSY);                          // Wait for bus to be free.
   SM_BUSY = 1;                              // Occupy SMBus (set to busy)
   SMB0CN = 0x44;                            // SMBus enabled, ACK on acknowledge cycle

   BYTE_NUMBER = 1;  //2                        // 1 address byte
   COMMAND = (chip_select | READ);           // Chip select + READ

  // HIGH_ADD = ((byte_address >> 8) & 0x00FF);// Upper 8 address bits
   LOW_ADD = (byte_address & 0xFF);        // Lower 4 address bits
   
   STO = 0;
   STA = 1;                                  // Start transfer
   while (SM_BUSY);                          // Wait for transfer to finish
   return WORD;
}


//------------------------------------------------------------------------------------
// Interrupt Service Routine
//------------------------------------------------------------------------------------


// SMBus interrupt service routine:

void SMBUS_ISR (void) interrupt 7
{  if(SI==1)
   {switch (SMB0STA){                   // Status code for the SMBus (SMB0STA register)

      // Master Transmitter/Receiver: START condition transmitted.
      // The R/W bit of the COMMAND word sent after this state will
      // always be a zero (W) because for both read and write,
      // the memory address must be written first.
      case SMB_START:
         SMB0DAT = (COMMAND & 0xFE);   // Load address of the slave to be accessed.
         STA = 0;                      // Manually clear START bit
         break;

      // Master Transmitter/Receiver: Repeated START condition transmitted.
      // This state should only occur during a read, after the memory address has been
      // sent and acknowledged.
      case SMB_RP_START:
         SMB0DAT = COMMAND;            // COMMAND should hold slave address + R.
         STA = 0;
         break;

      // Master Transmitter: Slave address + WRITE transmitted.  ACK received.
      case SMB_MTADDACK:
        // SMB0DAT = HIGH_ADD;           // Load high byte of memory address
         SMB0DAT = LOW_ADD;                              // to be written.
         break;

      // Master Transmitter: Slave address + WRITE transmitted.  NACK received.
      // The slave is not responding.  Send a STOP followed by a START to try again.
      case SMB_MTADDNACK:
         STO = 1;
         STA = 1;
         break;

      // Master Transmitter: Data byte transmitted.  ACK received.
      // This state is used in both READ and WRITE operations.  Check BYTE_NUMBER
      // for memory address status - if only HIGH_ADD has been sent, load LOW_ADD.
      // If LOW_ADD has been sent, check COMMAND for R/W value to determine 
      // next state.
      case SMB_MTDBACK:
         switch (BYTE_NUMBER){
      //      case 2:                    // If BYTE_NUMBER=2, only HIGH_ADD
        //       SMB0DAT = LOW_ADD;      // has been sent.
        //       BYTE_NUMBER--;          // Decrement for next time around.
        //       break;
            case 1:                    // If BYTE_NUMBER=1, LOW_ADD was just sent.
               if (COMMAND & 0x01){    // If R/W=READ, sent repeated START.
                  STO = 0;
                  STA = 1;

               } else { 
                  SMB0DAT = WORD;      // If R/W=WRITE, load byte to write.
                  BYTE_NUMBER--;
               }
               break;
            default:                   // If BYTE_NUMBER=0, transfer is finished.
               STO = 1;
               SM_BUSY = 0;            // Free SMBus
            }
         break;


      // Master Transmitter: Data byte transmitted.  NACK received.
      // Slave not responding.  Send STOP followed by START to try again.
      case SMB_MTDBNACK:
         STO = 1;
         STA = 1;
         break;

      // Master Transmitter: Arbitration lost.
      // Should not occur.  If so, restart transfer.
      case SMB_MTARBLOST:
         STO = 1;
         STA = 1;
         break;

      // Master Receiver: Slave address + READ transmitted.  ACK received.
      // Set to transmit NACK after next transfer since it will be the last (only)
      // byte.
      case SMB_MRADDACK:
         AA = 0;                       // NACK sent on acknowledge cycle.
         break;

      // Master Receiver: Slave address + READ transmitted.  NACK received.
      // Slave not responding.  Send repeated start to try again.
      case SMB_MRADDNACK:
         STO = 0;
         STA = 1;
         break;

      // Data byte received.  ACK transmitted.
      // State should not occur because AA is set to zero in previous state.
      // Send STOP if state does occur.
      case SMB_MRDBACK:
         STO = 1;
         SM_BUSY = 0;
         break;

      // Data byte received.  NACK transmitted.
      // Read operation has completed.  Read data register and send STOP.
      case SMB_MRDBNACK:
         WORD = SMB0DAT;
         STO = 1;
         SM_BUSY = 0;                  // Free SMBus
         break;

      // All other status codes meaningless in this application. Reset communication.
      default:
         STO = 1;                      // Reset communication.
         SM_BUSY = 0;
         break;
      }

   SI=0;                               // clear interrupt flag
   
   }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久99久久精品| 在线亚洲一区二区| 一区二区成人在线观看| 国产午夜精品美女毛片视频| 亚洲三级在线看| 水野朝阳av一区二区三区| 日韩综合小视频| 久久99九九99精品| 国产九色精品成人porny| 国产精华液一区二区三区| 成人av影视在线观看| 欧美午夜理伦三级在线观看| 欧美精品一级二级| 国产亚洲一区字幕| 亚洲精品国产成人久久av盗摄| 亚洲午夜精品在线| 国产a区久久久| 日韩欧美一区二区免费| 国产亚洲污的网站| 奇米影视一区二区三区小说| 成人一级片网址| 日韩一区二区三区视频在线观看| 久久久三级国产网站| 亚洲国产精品高清| 国产一区二区三区久久悠悠色av| 91黄视频在线观看| 精品国产一区二区三区久久影院| 亚洲欧美国产三级| 大白屁股一区二区视频| 日韩女优制服丝袜电影| 亚洲成人你懂的| av男人天堂一区| 亚洲日本乱码在线观看| 成人午夜免费av| 久久久久国产精品厨房| 日本不卡不码高清免费观看| 99精品视频一区| 亚洲欧美在线aaa| 91在线视频网址| 亚洲男人都懂的| 欧美视频在线播放| 一区二区三区四区蜜桃| 成人av片在线观看| 亚洲美女区一区| 欧美三级日韩在线| 五月婷婷激情综合网| 91麻豆精品国产91久久久使用方法 | 色婷婷精品久久二区二区蜜臂av| 国产日产欧产精品推荐色| 国产一区二区调教| 国产日韩欧美高清在线| 色成人在线视频| 日韩一区欧美二区| 久久久久国产免费免费| 成人h精品动漫一区二区三区| 亚洲精品视频在线看| 91精品国产免费| 国产成人在线电影| 亚洲在线视频一区| 91精品国产综合久久小美女| 从欧美一区二区三区| 性做久久久久久免费观看欧美| 久久欧美中文字幕| 欧美视频三区在线播放| 国产一区二区三区黄视频 | 国产成人精品影视| 亚洲国产色一区| 2020国产精品| 欧美伊人久久大香线蕉综合69| 国产在线麻豆精品观看| 麻豆成人久久精品二区三区红 | 成人高清视频免费观看| 免费看日韩精品| 日韩福利视频网| 亚洲成av人影院| 一区二区三区四区蜜桃| 亚洲成人av中文| 亚洲国产美女搞黄色| 亚洲一级在线观看| 亚洲国产美女搞黄色| 亚洲精品视频免费看| 国产精品毛片无遮挡高清| 欧美大片顶级少妇| 日韩欧美一级特黄在线播放| 欧美军同video69gay| 精品视频一区三区九区| 欧美日韩高清影院| 91麻豆精品国产91久久久久久久久| 欧美日韩夫妻久久| 51久久夜色精品国产麻豆| 精品久久久久久久一区二区蜜臀| 欧美成人r级一区二区三区| 欧美r级在线观看| 欧美精品一区二区三区在线| 久久综合丝袜日本网| 国产精品久久久久久久第一福利 | 爽爽淫人综合网网站| 久草精品在线观看| 成人免费不卡视频| 91成人免费电影| 国产日韩欧美制服另类| 亚洲成人高清在线| 狠狠色综合日日| 91精品国产综合久久久蜜臀粉嫩| 久久久一区二区| 日韩精品一级中文字幕精品视频免费观看 | 91精品国产色综合久久ai换脸 | 一区二区三区.www| 久久精品国产一区二区| 成人18视频日本| 91.成人天堂一区| 中文字幕永久在线不卡| 奇米影视一区二区三区| 91在线你懂得| 欧美国产一区视频在线观看| 免费人成精品欧美精品| 欧美日韩精品电影| 亚洲va欧美va人人爽| 欧美色男人天堂| 亚洲乱码国产乱码精品精的特点 | 国产乱码精品一区二区三区av | 99久久精品情趣| 国产欧美日韩三级| 欧美在线你懂得| 亚洲卡通欧美制服中文| 欧美亚洲国产一区二区三区| 欧美mv日韩mv国产网站app| 亚洲1区2区3区视频| 欧美蜜桃一区二区三区 | 日韩精品综合一本久道在线视频| 婷婷久久综合九色国产成人| 91精品国产入口| 福利电影一区二区| 国产精品国模大尺度视频| 99精品在线免费| 亚洲电影一区二区三区| 欧美精品18+| 奇米777欧美一区二区| 欧美国产精品一区| 99天天综合性| 久久激情五月婷婷| 日韩一区二区电影网| 色欧美88888久久久久久影院| 亚洲在线成人精品| 亚洲国产成人在线| 日韩欧美综合在线| 色综合天天天天做夜夜夜夜做| 夜夜嗨av一区二区三区网页| 欧美va天堂va视频va在线| 91香蕉国产在线观看软件| 免费看欧美女人艹b| 国产精品午夜在线观看| 91精品欧美久久久久久动漫| 不卡一区二区三区四区| 久久狠狠亚洲综合| 亚洲一区二区三区在线看 | 一级女性全黄久久生活片免费| 欧美videossexotv100| 欧美一级二级三级蜜桃| 欧美一区二区国产| 日韩欧美色综合网站| 91日韩一区二区三区| 久久国产生活片100| 蜜臀av一区二区在线免费观看 | 91福利国产成人精品照片| caoporm超碰国产精品| 国产精品亚洲午夜一区二区三区| 亚洲国产日产av| 日本欧美一区二区| 日韩高清不卡在线| 一二三四社区欧美黄| 一区二区三区丝袜| 亚洲永久精品大片| 激情伊人五月天久久综合| 国产一区二区三区日韩| 日韩va欧美va亚洲va久久| 天天爽夜夜爽夜夜爽精品视频| 五月激情综合色| 国内精品久久久久影院色| 丰满白嫩尤物一区二区| 成人高清视频免费观看| 在线免费观看日韩欧美| 欧美午夜精品一区二区三区| 欧美一区二区三区在线看| 337p日本欧洲亚洲大胆精品 | 欧美体内she精高潮| 2017欧美狠狠色| 亚洲大片精品永久免费| 美女视频黄免费的久久| 国产一区二区女| 欧美性淫爽ww久久久久无| 久久综合给合久久狠狠狠97色69| 国产精品免费观看视频| 婷婷综合五月天| 色噜噜夜夜夜综合网| 欧美本精品男人aⅴ天堂| 亚洲美女精品一区| 激情综合网av| 欧美一区二区三区在线观看视频| 亚洲精品乱码久久久久久日本蜜臀|