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

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

?? twi_slave.c

?? avr 單片機TWT從機中斷方式源碼,給大家參考
?? C
字號:
/*****************************************************************************
*
* Atmel Corporation
*
* File              : TWI_Slave.c
* Compiler          : IAR EWAAVR 2.28a/3.10c
* Revision          : $Revision: 1.7 $
* Date              : $Date: Thursday, August 05, 2004 09:22:50 UTC $
* Updated by        : $Author: lholsen $
*
* Support mail      : avr@atmel.com
*
* Supported devices : All devices with a TWI module can be used.
*                     The example is written for the ATmega16
*
* AppNote           : AVR311 - TWI Slave Implementation
*
* Description       : This is sample driver to AVRs TWI module. 
*                     It is interupt driveren. All functionality is controlled through 
*                     passing information to and from functions. Se main.c for samples
*                     of how to use the driver.
*
****************************************************************************/

#include "ioavr.h"              
#include "inavr.h"
#include "TWI_slave.h"
 
static unsigned char TWI_buf[TWI_BUFFER_SIZE];     // Transceiver buffer. Set the size in the header file
static unsigned char TWI_msgSize  = 0;             // Number of bytes to be transmitted.
static unsigned char TWI_state    = TWI_NO_STATE;  // State byte. Default set to TWI_NO_STATE.

union TWI_statusReg TWI_statusReg = {0};           // TWI_statusReg is defined in TWI_Slave.h

/****************************************************************************
Call this function to set up the TWI slave to its initial standby state.
Remember to enable interrupts from the main application after initializing the TWI.
Pass both the slave address and the requrements for triggering on a general call in the
same byte. Use e.g. this notation when calling this function:
TWI_Slave_Initialise( (TWI_slaveAddress<<TWI_ADR_BITS) | (TRUE<<TWI_GEN_BIT) );
The TWI module is configured to NACK on any requests. Use a TWI_Start_Transceiver function to 
start the TWI.
****************************************************************************/
void TWI_Slave_Initialise( unsigned char TWI_ownAddress )
{
  TWAR = TWI_ownAddress;                            // Set own TWI slave address. Accept TWI General Calls.
  TWDR = 0xFF;                                      // Default content = SDA released.
  TWCR = (1<<TWEN)|                                 // Enable TWI-interface and release TWI pins.
         (0<<TWIE)|(0<<TWINT)|                      // Disable TWI Interupt.
         (0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // Do not ACK on any requests, yet.
         (0<<TWWC);                                 //
}    
    
/****************************************************************************
Call this function to test if the TWI_ISR is busy transmitting.
****************************************************************************/
unsigned char TWI_Transceiver_Busy( void )
{
  return ( TWCR & (1<<TWIE) );                  // IF TWI interrupt is enabled then the Transceiver is busy
}

/****************************************************************************
Call this function to fetch the state information of the previous operation. The function will hold execution (loop)
until the TWI_ISR has completed with the previous operation. If there was an error, then the function 
will return the TWI State code. 
****************************************************************************/
unsigned char TWI_Get_State_Info( void )
{
  while ( TWI_Transceiver_Busy() );             // Wait until TWI has completed the transmission.
  return ( TWI_state );                         // Return error state. 
}

/****************************************************************************
Call this function to send a prepared message, or start the Transceiver for reception. Include
a pointer to the data to be sent if a SLA+W is received. The data will be copied to the TWI buffer. 
Also include how many bytes that should be sent. Note that unlike the similar Master function, the
Address byte is not included in the message buffers.
The function will hold execution (loop) until the TWI_ISR has completed with the previous operation,
then initialize the next operation and return.
****************************************************************************/
void TWI_Start_Transceiver_With_Data( unsigned char *msg, unsigned char msgSize )
{
  unsigned char temp;

  while ( TWI_Transceiver_Busy() );             // Wait until TWI is ready for next transmission.

  TWI_msgSize = msgSize;                        // Number of data to transmit.
  for ( temp = 0; temp < msgSize; temp++ )      // Copy data that may be transmitted if the TWI Master requests data.
    TWI_buf[ temp ] = msg[ temp ];
  TWI_statusReg.all = 0;      
  TWI_state         = TWI_NO_STATE ;
  TWCR = (1<<TWEN)|                             // TWI Interface enabled.
         (1<<TWIE)|(1<<TWINT)|                  // Enable TWI Interupt and clear the flag.
         (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|       // Prepare to ACK next time the Slave is addressed.
         (0<<TWWC);                             //
}

/****************************************************************************
Call this function to start the Transceiver without specifing new transmission data. Usefull for restarting
a transmission, or just starting the transceiver for reception. The driver will reuse the data previously put
in the transceiver buffers. The function will hold execution (loop) until the TWI_ISR has completed with the 
previous operation, then initialize the next operation and return.
****************************************************************************/
void TWI_Start_Transceiver( void )
{
  while ( TWI_Transceiver_Busy() );             // Wait until TWI is ready for next transmission.
  TWI_statusReg.all = 0;      
  TWI_state         = TWI_NO_STATE ;
  TWCR = (1<<TWEN)|                             // TWI Interface enabled.
         (1<<TWIE)|(1<<TWINT)|                  // Enable TWI Interupt and clear the flag.
         (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|       // Prepare to ACK next time the Slave is addressed.
         (0<<TWWC);                             //
}
/****************************************************************************
Call this function to read out the received data from the TWI transceiver buffer. I.e. first call
TWI_Start_Transceiver to get the TWI Transceiver to fetch data. Then Run this function to collect the
data when they have arrived. Include a pointer to where to place the data and the number of bytes
to fetch in the function call. The function will hold execution (loop) until the TWI_ISR has completed 
with the previous operation, before reading out the data and returning.
If there was an error in the previous transmission the function will return the TWI State code.
****************************************************************************/
unsigned char TWI_Get_Data_From_Transceiver( unsigned char *msg, unsigned char msgSize )
{
  unsigned char i;

  while ( TWI_Transceiver_Busy() );             // Wait until TWI is ready for next transmission.

  if( TWI_statusReg.lastTransOK )               // Last transmission competed successfully.              
  {                                             
    for ( i=0; i<msgSize; i++ )                 // Copy data from Transceiver buffer.
    {
      msg[ i ] = TWI_buf[ i ];
    }
    TWI_statusReg.RxDataInBuf = FALSE;          // Slave Receive data has been read from buffer.
  }
  return( TWI_statusReg.lastTransOK );                                   
}

// ********** Interrupt Handlers ********** //
/****************************************************************************
This function is the Interrupt Service Routine (ISR), and called when the TWI interrupt is triggered;
that is whenever a TWI event has occurred. This function should not be called directly from the main
application.
****************************************************************************/
#pragma vector=TWI_vect
__interrupt void TWI_ISR( void )
{
  static unsigned char TWI_bufPtr;
  
  switch (TWSR)
  {
    case TWI_STX_ADR_ACK:            // Own SLA+R has been received; ACK has been returned
//    case TWI_STX_ADR_ACK_M_ARB_LOST: // Arbitration lost in SLA+R/W as Master; own SLA+R has been received; ACK has been returned
      TWI_bufPtr   = 0;                                 // Set buffer pointer to first data location
    case TWI_STX_DATA_ACK:           // Data byte in TWDR has been transmitted; ACK has been received
      TWDR = TWI_buf[TWI_bufPtr++];
      TWCR = (1<<TWEN)|                                 // TWI Interface enabled
             (1<<TWIE)|(1<<TWINT)|                      // Enable TWI Interupt and clear the flag to send byte
             (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // 
             (0<<TWWC);                                 //  
      break;
    case TWI_STX_DATA_NACK:          // Data byte in TWDR has been transmitted; NACK has been received. 
                                     // I.e. this could be the end of the transmission.
      if (TWI_bufPtr == TWI_msgSize) // Have we transceived all expected data?
      {
        TWI_statusReg.lastTransOK = TRUE;               // Set status bits to completed successfully. 
      }else                          // Master has sent a NACK before all data where sent.
      {
        TWI_state = TWSR;                               // Store TWI State as errormessage.      
      }        
                                                        // Put TWI Transceiver in passive mode.
      TWCR = (1<<TWEN)|                                 // Enable TWI-interface and release TWI pins
             (0<<TWIE)|(0<<TWINT)|                      // Disable Interupt
             (0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // Do not acknowledge on any new requests.
             (0<<TWWC);                                 //
      break;     
    case TWI_SRX_GEN_ACK:            // General call address has been received; ACK has been returned
//    case TWI_SRX_GEN_ACK_M_ARB_LOST: // Arbitration lost in SLA+R/W as Master; General call address has been received; ACK has been returned
      TWI_statusReg.genAddressCall = TRUE;
    case TWI_SRX_ADR_ACK:            // Own SLA+W has been received ACK has been returned
//    case TWI_SRX_ADR_ACK_M_ARB_LOST: // Arbitration lost in SLA+R/W as Master; own SLA+W has been received; ACK has been returned    
                                                        // Dont need to clear TWI_S_statusRegister.generalAddressCall due to that it is the default state.
      TWI_statusReg.RxDataInBuf = TRUE;      
      TWI_bufPtr   = 0;                                 // Set buffer pointer to first data location
                                                        // Reset the TWI Interupt to wait for a new event.
      TWCR = (1<<TWEN)|                                 // TWI Interface enabled
             (1<<TWIE)|(1<<TWINT)|                      // Enable TWI Interupt and clear the flag to send byte
             (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // Expect ACK on this transmission
             (0<<TWWC);                                 //      
      break;
    case TWI_SRX_ADR_DATA_ACK:       // Previously addressed with own SLA+W; data has been received; ACK has been returned
    case TWI_SRX_GEN_DATA_ACK:       // Previously addressed with general call; data has been received; ACK has been returned
      TWI_buf[TWI_bufPtr++]     = TWDR;
      TWI_statusReg.lastTransOK = TRUE;                 // Set flag transmission successfull.       
                                                        // Reset the TWI Interupt to wait for a new event.
      TWCR = (1<<TWEN)|                                 // TWI Interface enabled
             (1<<TWIE)|(1<<TWINT)|                      // Enable TWI Interupt and clear the flag to send byte
             (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // Send ACK after next reception
             (0<<TWWC);                                 //  
      break;
    case TWI_SRX_STOP_RESTART:       // A STOP condition or repeated START condition has been received while still addressed as Slave    
                                                        // Put TWI Transceiver in passive mode.
      TWCR = (1<<TWEN)|                                 // Enable TWI-interface and release TWI pins
             (0<<TWIE)|(0<<TWINT)|                      // Disable Interupt
             (0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|           // Do not acknowledge on any new requests.
             (0<<TWWC);                                 //
      break;           
    case TWI_SRX_ADR_DATA_NACK:      // Previously addressed with own SLA+W; data has been received; NOT ACK has been returned
    case TWI_SRX_GEN_DATA_NACK:      // Previously addressed with general call; data has been received; NOT ACK has been returned
    case TWI_STX_DATA_ACK_LAST_BYTE: // Last data byte in TWDR has been transmitted (TWEA = 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩一区二区三区不卡| 欧美性大战久久久久久久蜜臀| 午夜在线成人av| 亚洲一区免费观看| 婷婷久久综合九色国产成人 | 蜜桃视频在线观看一区二区| 亚洲电影第三页| 日本亚洲免费观看| 久久99精品国产麻豆婷婷洗澡| 美腿丝袜在线亚洲一区| 久久se精品一区二区| 国产美女一区二区| caoporen国产精品视频| 一本一道久久a久久精品综合蜜臀| 91免费国产在线观看| 欧美调教femdomvk| 日韩精品在线一区二区| 久久久久久麻豆| 亚洲精品成a人| 久久国产精品色| 99久久精品国产一区二区三区 | 91网站黄www| 欧美色欧美亚洲另类二区| 日韩三级av在线播放| 国产日韩欧美一区二区三区综合| 亚洲天堂av一区| 麻豆专区一区二区三区四区五区| 国产福利一区二区| 欧美日韩久久久久久| 久久精品亚洲一区二区三区浴池| 亚洲免费在线观看视频| 日av在线不卡| 一本大道久久a久久综合婷婷| 欧美理论电影在线| 欧美韩日一区二区三区四区| 亚洲成av人在线观看| 成人一区二区视频| 91精品国产欧美一区二区| 国产精品福利在线播放| 日本伊人色综合网| 色婷婷久久久亚洲一区二区三区| 日韩免费高清视频| 亚洲综合无码一区二区| 成人精品鲁一区一区二区| 欧美日韩国产精品成人| 亚洲久本草在线中文字幕| 国产麻豆成人传媒免费观看| 欧美日韩精品欧美日韩精品一 | 欧美亚洲动漫制服丝袜| 国产性做久久久久久| 舔着乳尖日韩一区| 91亚洲精品一区二区乱码| 26uuu亚洲| 喷水一区二区三区| 色就色 综合激情| 国产精品久久三区| 国产成人精品亚洲午夜麻豆| 日韩女优av电影在线观看| 亚洲国产日日夜夜| 91美女片黄在线观看91美女| 欧美激情在线看| 精品无人码麻豆乱码1区2区 | 亚洲精品日产精品乱码不卡| 国产成人免费9x9x人网站视频| 日韩欧美亚洲国产另类| 无吗不卡中文字幕| 欧美日韩在线播放| 亚洲影视资源网| 欧美视频一区二区三区在线观看| 亚洲欧美日韩国产一区二区三区| 99综合电影在线视频| 国产精品护士白丝一区av| 成人福利在线看| 国产精品成人免费在线| 99精品久久久久久| 亚洲人成小说网站色在线| 色悠悠久久综合| 亚洲午夜在线视频| 欧美一区二视频| 免费久久99精品国产| 精品乱码亚洲一区二区不卡| 精品亚洲免费视频| 中文字幕不卡在线| 日本大香伊一区二区三区| 亚洲日本va午夜在线电影| 色婷婷av一区二区三区大白胸| 亚洲一区二区三区爽爽爽爽爽| 欧美高清视频www夜色资源网| 日本美女一区二区| 久久久久久久久蜜桃| 成人精品小蝌蚪| 亚洲资源中文字幕| 欧美一级黄色大片| 成人午夜视频在线| 亚洲图片欧美视频| 欧美成人午夜电影| 懂色中文一区二区在线播放| 亚洲欧美日韩国产另类专区| 精品视频1区2区| 九色综合狠狠综合久久| 国产精品家庭影院| 在线不卡免费av| 粉嫩一区二区三区在线看| 亚洲激情综合网| 久久综合给合久久狠狠狠97色69| 成人激情午夜影院| 日韩高清不卡在线| 欧美国产日产图区| 欧美一区日韩一区| aaa欧美大片| 美美哒免费高清在线观看视频一区二区 | 日韩精品中文字幕一区二区三区| 国产精品一区二区91| 亚洲主播在线播放| 国产日产精品1区| 宅男在线国产精品| 成人国产电影网| 日韩成人免费电影| 最新国产成人在线观看| 日韩欧美电影一区| 在线日韩国产精品| 国产精品主播直播| 日韩不卡一二三区| 一区二区三区中文字幕在线观看| 久久影视一区二区| 欧美高清一级片在线| 色爱区综合激月婷婷| 国产精品白丝jk黑袜喷水| 日韩精品亚洲一区| 亚洲一线二线三线久久久| 国产精品免费看片| 久久久久久麻豆| 日韩欧美高清在线| 欧美一区二区日韩| 欧美日韩一区二区三区不卡| 成人动漫在线一区| 国产酒店精品激情| 麻豆精品视频在线观看免费| 亚洲高清久久久| 亚洲制服欧美中文字幕中文字幕| 国产日韩欧美综合一区| 国产亚洲欧美一级| 久久在线免费观看| 久久久久久久综合日本| 欧美va亚洲va| 欧美大片一区二区三区| 欧美日韩精品一二三区| 99国产精品国产精品久久| 国产aⅴ综合色| 大陆成人av片| 成人中文字幕合集| 成人精品视频.| 97久久精品人人澡人人爽| 91在线观看地址| 91国偷自产一区二区三区成为亚洲经典 | 91一区一区三区| 91网页版在线| 精品视频免费在线| 在线播放欧美女士性生活| 欧美日韩免费电影| 在线播放91灌醉迷j高跟美女 | 亚洲成年人网站在线观看| 亚洲一区在线观看网站| 亚洲第一福利一区| 蜜臀精品一区二区三区在线观看 | 一区二区欧美在线观看| 亚洲一区在线看| 日本大胆欧美人术艺术动态| 麻豆精品国产91久久久久久| 韩国欧美国产一区| 不卡一区二区三区四区| 色综合夜色一区| 欧美日韩不卡一区| 久久久激情视频| 艳妇臀荡乳欲伦亚洲一区| 午夜a成v人精品| 国产成人亚洲精品青草天美| 一本久道中文字幕精品亚洲嫩| 欧美视频日韩视频在线观看| 日韩精品一区二区三区视频| 日本一区二区三区高清不卡 | 精品国产乱码久久久久久夜甘婷婷| 337p粉嫩大胆噜噜噜噜噜91av| 国产精品美女久久福利网站| 亚洲精品综合在线| 捆绑变态av一区二区三区| 国产iv一区二区三区| 91官网在线免费观看| 久久夜色精品国产噜噜av| 亚洲色图欧美在线| 奇米色777欧美一区二区| 国产成都精品91一区二区三| 在线影院国内精品| 国产三级精品三级| 视频一区二区国产| 99国产精品国产精品毛片| 日韩欧美卡一卡二| 一区二区三区电影在线播| 精品一区二区免费| 在线观看视频一区二区|