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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? i2c_8c-source.html

?? ATMEL的AVR單片機庫文件
?? HTML
?? 第 1 頁 / 共 3 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: i2c.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.6 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div><h1>i2c.c</h1><a href="i2c_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*! \file i2c.c \brief I2C interface using AVR Two-Wire Interface (TWI) hardware. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'i2c.c'</span>00005 <span class="comment">// Title        : I2C interface using AVR Two-Wire Interface (TWI) hardware</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2002-2003</span>00007 <span class="comment">// Created      : 2002.06.25</span>00008 <span class="comment">// Revised      : 2003.03.02</span>00009 <span class="comment">// Version      : 0.9</span>00010 <span class="comment">// Target MCU   : Atmel AVR series</span>00011 <span class="comment">// Editor Tabs  : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// Description : I2C (pronounced "eye-squared-see") is a two-wire bidirectional</span>00014 <span class="comment">//      network designed for easy transfer of information between a wide variety</span>00015 <span class="comment">//      of intelligent devices.  Many of the Atmel AVR series processors have</span>00016 <span class="comment">//      hardware support for transmitting and receiving using an I2C-type bus.</span>00017 <span class="comment">//      In addition to the AVRs, there are thousands of other parts made by</span>00018 <span class="comment">//      manufacturers like Philips, Maxim, National, TI, etc that use I2C as</span>00019 <span class="comment">//      their primary means of communication and control.  Common device types</span>00020 <span class="comment">//      are A/D &amp; D/A converters, temp sensors, intelligent battery monitors,</span>00021 <span class="comment">//      MP3 decoder chips, EEPROM chips, multiplexing switches, etc.</span>00022 <span class="comment">//</span>00023 <span class="comment">//      I2C uses only two wires (SDA and SCL) to communicate bidirectionally</span>00024 <span class="comment">//      between devices.  I2C is a multidrop network, meaning that you can have</span>00025 <span class="comment">//      several devices on a single bus.  Because I2C uses a 7-bit number to</span>00026 <span class="comment">//      identify which device it wants to talk to, you cannot have more than</span>00027 <span class="comment">//      127 devices on a single bus.</span>00028 <span class="comment">//</span>00029 <span class="comment">//      I2C ordinarily requires two 4.7K pull-up resistors to power (one each on</span>00030 <span class="comment">//      SDA and SCL), but for small numbers of devices (maybe 1-4), it is enough</span>00031 <span class="comment">//      to activate the internal pull-up resistors in the AVR processor.  To do</span>00032 <span class="comment">//      this, set the port pins, which correspond to the I2C pins SDA/SCL, high.</span>00033 <span class="comment">//      For example, on the mega163, sbi(PORTC, 0); sbi(PORTC, 1);.</span>00034 <span class="comment">//</span>00035 <span class="comment">//      For complete information about I2C, see the Philips Semiconductor</span>00036 <span class="comment">//      website.  They created I2C and have the largest family of devices that</span>00037 <span class="comment">//      work with I2C.</span>00038 <span class="comment">//</span>00039 <span class="comment">// Note: Many manufacturers market I2C bus devices under a different or generic</span>00040 <span class="comment">//      bus name like "Two-Wire Interface".  This is because Philips still holds</span>00041 <span class="comment">//      "I2C" as a trademark.  For example, SMBus and SMBus devices are hardware</span>00042 <span class="comment">//      compatible and closely related to I2C.  They can be directly connected</span>00043 <span class="comment">//      to an I2C bus along with other I2C devices are are generally accessed in</span>00044 <span class="comment">//      the same way as I2C devices.  SMBus is often found on modern motherboards</span>00045 <span class="comment">//      for temp sensing and other low-level control tasks.</span>00046 <span class="comment">//</span>00047 <span class="comment">// This code is distributed under the GNU Public License</span>00048 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00049 <span class="comment">//</span>00050 <span class="comment">//*****************************************************************************</span>00051 00052 <span class="preprocessor">#include &lt;avr/io.h&gt;</span>00053 <span class="preprocessor">#include &lt;avr/signal.h&gt;</span>00054 <span class="preprocessor">#include &lt;avr/interrupt.h&gt;</span>00055 <span class="preprocessor">#include &lt;avr/twi.h&gt;</span>00056 00057 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span>00058 00059 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>    <span class="comment">// include printf function library</span>00060 <span class="preprocessor">#include "<a class="code" href="uart2_8h.html">uart2.h</a>"</span>00061 00062 <span class="comment">// Standard I2C bit rates are:</span>00063 <span class="comment">// 100KHz for slow speed</span>00064 <span class="comment">// 400KHz for high speed</span>00065 00066 <span class="comment">//#define I2C_DEBUG</span>00067 00068 <span class="comment">// I2C state and address variables</span>00069 <span class="keyword">static</span> <span class="keyword">volatile</span> eI2cStateType I2cState;00070 <span class="keyword">static</span> u08 I2cDeviceAddrRW;00071 <span class="comment">// send/transmit buffer (outgoing data)</span>00072 <span class="keyword">static</span> u08 I2cSendData[I2C_SEND_DATA_BUFFER_SIZE];00073 <span class="keyword">static</span> u08 I2cSendDataIndex;00074 <span class="keyword">static</span> u08 I2cSendDataLength;00075 <span class="comment">// receive buffer (incoming data)</span>00076 <span class="keyword">static</span> u08 I2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE];00077 <span class="keyword">static</span> u08 I2cReceiveDataIndex;00078 <span class="keyword">static</span> u08 I2cReceiveDataLength;00079 00080 <span class="comment">// function pointer to i2c receive routine</span><span class="comment"></span>00081 <span class="comment">//! I2cSlaveReceive is called when this processor</span>00082 <span class="comment"></span><span class="comment">// is addressed as a slave for writing</span>00083 <span class="keyword">static</span> void (*i2cSlaveReceive)(u08 receiveDataLength, u08* recieveData);<span class="comment"></span>00084 <span class="comment">//! I2cSlaveTransmit is called when this processor</span>00085 <span class="comment"></span><span class="comment">// is addressed as a slave for reading</span>00086 <span class="keyword">static</span> u08 (*i2cSlaveTransmit)(u08 transmitDataLengthMax, u08* transmitData);00087 00088 <span class="comment">// functions</span><a name="l00089"></a><a class="code" href="i2csw_8h.html#a1">00089</a> <span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a10">i2cInit</a>(<span class="keywordtype">void</span>)00090 {00091     <span class="comment">// set pull-up resistors on I2C bus pins</span>00092     <span class="comment">// TODO: should #ifdef these</span>00093     sbi(PORTC, 0);  <span class="comment">// i2c SCL on ATmega163,323,16,32,etc</span>00094     sbi(PORTC, 1);  <span class="comment">// i2c SDA on ATmega163,323,16,32,etc</span>00095     sbi(PORTD, 0);  <span class="comment">// i2c SCL on ATmega128,64</span>00096     sbi(PORTD, 1);  <span class="comment">// i2c SDA on ATmega128,64</span>00097 00098     <span class="comment">// clear SlaveReceive and SlaveTransmit handler to null</span>00099     i2cSlaveReceive = 0;00100     i2cSlaveTransmit = 0;00101     <span class="comment">// set i2c bit rate to 100KHz</span>00102     <a class="code" href="i2c_8h.html#a11">i2cSetBitrate</a>(100);00103     <span class="comment">// enable TWI (two-wire interface)</span>00104     sbi(TWCR, TWEN);00105     <span class="comment">// set state</span>00106     I2cState = I2C_IDLE;00107     <span class="comment">// enable TWI interrupt and slave address ACK</span>00108     sbi(TWCR, TWIE);00109     sbi(TWCR, TWEA);00110     <span class="comment">//outb(TWCR, (inb(TWCR)&amp;TWCR_CMD_MASK)|BV(TWINT)|BV(TWEA));</span>00111     <span class="comment">// enable interrupts</span>00112     sei();00113 }00114 <a name="l00115"></a><a class="code" href="i2c_8h.html#a11">00115</a> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a11">i2cSetBitrate</a>(u16 bitrateKHz)00116 {00117     u08 bitrate_div;00118     <span class="comment">// set i2c bitrate</span>00119     <span class="comment">// SCL freq = F_CPU/(16+2*TWBR))</span>00120 <span class="preprocessor">    #ifdef TWPS0</span>00121 <span class="preprocessor"></span>        <span class="comment">// for processors with additional bitrate division (mega128)</span>00122         <span class="comment">// SCL freq = F_CPU/(16+2*TWBR*4^TWPS)</span>00123         <span class="comment">// set TWPS to zero</span>00124         cbi(TWSR, TWPS0);00125         cbi(TWSR, TWPS1);00126 <span class="preprocessor">    #endif</span>00127 <span class="preprocessor"></span>    <span class="comment">// calculate bitrate division   </span>00128     bitrate_div = ((F_CPU/1000l)/bitrateKHz);00129     <span class="keywordflow">if</span>(bitrate_div &gt;= 16)00130         bitrate_div = (bitrate_div-16)/2;00131     outb(TWBR, bitrate_div);00132 }00133 <a name="l00134"></a><a class="code" href="i2c_8h.html#a12">00134</a> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a12">i2cSetLocalDeviceAddr</a>(u08 deviceAddr, u08 genCallEn)00135 {00136     <span class="comment">// set local device address (used in slave mode only)</span>00137     outb(TWAR, ((deviceAddr&amp;0xFE) | (genCallEn?1:0)) );00138 }00139 <a name="l00140"></a><a class="code" href="i2c_8h.html#a13">00140</a> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a13">i2cSetSlaveReceiveHandler</a>(<span class="keywordtype">void</span> (*i2cSlaveRx_func)(u08 receiveDataLength, u08* recieveData))00141 {00142     i2cSlaveReceive = i2cSlaveRx_func;00143 }00144 <a name="l00145"></a><a class="code" href="i2c_8h.html#a14">00145</a> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a14">i2cSetSlaveTransmitHandler</a>(u08 (*i2cSlaveTx_func)(u08 transmitDataLengthMax, u08* transmitData))00146 {00147     i2cSlaveTransmit = i2cSlaveTx_func;00148 }00149 <a name="l00150"></a><a class="code" href="i2c_8h.html#a15">00150</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a15">i2cSendStart</a>(<span class="keywordtype">void</span>)00151 {00152     <span class="comment">// send start condition</span>00153     outb(TWCR, (inb(TWCR)&amp;TWCR_CMD_MASK)|BV(TWINT)|BV(TWSTA));00154 }00155 <a name="l00156"></a><a class="code" href="i2c_8h.html#a16">00156</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a16">i2cSendStop</a>(<span class="keywordtype">void</span>)00157 {00158     <span class="comment">// transmit stop condition</span>00159     <span class="comment">// leave with TWEA on for slave receiving</span>00160     outb(TWCR, (inb(TWCR)&amp;TWCR_CMD_MASK)|BV(TWINT)|BV(TWEA)|BV(TWSTO));00161 }00162 <a name="l00163"></a><a class="code" href="i2c_8h.html#a17">00163</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="i2c_8c.html#a17">i2cWaitForComplete</a>(<span class="keywordtype">void</span>)00164 {00165     <span class="comment">// wait for i2c interface to complete operation</span>00166     <span class="keywordflow">while</span>( !(inb(TWCR) &amp; BV(TWINT)) );00167 }00168 <a name="l00169"></a><a class="code" href="i2c_8h.html#a18">00169</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a18">i2cSendByte</a>(u08 data)00170 {00171     <span class="comment">// save data to the TWDR</span>00172     outb(TWDR, data);00173     <span class="comment">// begin send</span>00174     outb(TWCR, (inb(TWCR)&amp;TWCR_CMD_MASK)|BV(TWINT));00175 }00176 <a name="l00177"></a><a class="code" href="i2c_8h.html#a19">00177</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a19">i2cReceiveByte</a>(u08 ackFlag)00178 {00179     <span class="comment">// begin receive over i2c</span>00180     <span class="keywordflow">if</span>( ackFlag )00181     {00182         <span class="comment">// ackFlag = TRUE: ACK the recevied data</span>00183         outb(TWCR, (inb(TWCR)&amp;TWCR_CMD_MASK)|BV(TWINT)|BV(TWEA));00184     }00185     <span class="keywordflow">else</span>00186     {00187         <span class="comment">// ackFlag = FALSE: NACK the recevied data</span>00188         outb(TWCR, (inb(TWCR)&amp;TWCR_CMD_MASK)|BV(TWINT));00189     }00190 }00191 <a name="l00192"></a><a class="code" href="i2c_8h.html#a20">00192</a> <span class="keyword">inline</span> u08 <a class="code" href="i2c_8c.html#a20">i2cGetReceivedByte</a>(<span class="keywordtype">void</span>)00193 {00194     <span class="comment">// retieve received data byte from i2c TWDR</span>00195     <span class="keywordflow">return</span>( inb(TWDR) );00196 }00197 <a name="l00198"></a><a class="code" href="i2c_8h.html#a21">00198</a> <span class="keyword">inline</span> u08 <a class="code" href="i2c_8c.html#a21">i2cGetStatus</a>(<span class="keywordtype">void</span>)00199 {00200     <span class="comment">// retieve current i2c status from i2c TWSR</span>00201     <span class="keywordflow">return</span>( inb(TWSR) );00202 }00203 <a name="l00204"></a><a class="code" href="i2c_8h.html#a22">00204</a> <span class="keywordtype">void</span> <a class="code" href="i2c_8h.html#a22">i2cMasterSend</a>(u08 deviceAddr, u08 length, u08* data)00205 {00206     u08 i;00207     <span class="comment">// wait for interface to be ready</span>00208     <span class="keywordflow">while</span>(I2cState);00209     <span class="comment">// set state</span>00210     I2cState = I2C_MASTER_TX;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
麻豆一区二区在线| 亚洲一区二区三区四区中文字幕| 尤物av一区二区| 九色|91porny| 在线视频一区二区免费| 久久中文娱乐网| 亚洲一二三四在线观看| 国产麻豆视频精品| 717成人午夜免费福利电影| 国产精品天美传媒沈樵| 久久成人综合网| 欧美视频一区在线| 亚洲色图在线视频| 国产精品影视在线观看| 7777女厕盗摄久久久| 国产精品国模大尺度视频| 免费亚洲电影在线| 欧美亚洲综合在线| 成人免费小视频| 国产精品18久久久久久久久| 日韩一区二区免费电影| 亚洲国产欧美在线人成| 91免费看视频| 国产欧美精品在线观看| 精品一区二区三区久久| 欧美一区二区在线视频| 性做久久久久久久免费看| 欧美曰成人黄网| 一区二区三区高清不卡| av中文字幕亚洲| 亚洲国产高清aⅴ视频| 国产精品一区二区无线| 欧美成人bangbros| 蜜乳av一区二区| 欧美精品一二三区| 午夜一区二区三区在线观看| 欧洲av一区二区嗯嗯嗯啊| ㊣最新国产の精品bt伙计久久| 国产激情一区二区三区四区| 久久九九久久九九| 国产寡妇亲子伦一区二区| 国产亚洲一区二区三区四区| 精品亚洲国产成人av制服丝袜| 欧美一二三在线| 琪琪一区二区三区| 日韩精品在线网站| 麻豆精品国产91久久久久久| 欧美xxxxx牲另类人与| 美女一区二区久久| 日韩欧美国产wwwww| 蜜桃视频在线观看一区| 欧美一级欧美三级在线观看| 青青草原综合久久大伊人精品优势| 欧美日韩精品欧美日韩精品| 五月激情综合色| 91麻豆精品国产| 久久99精品国产.久久久久| 欧美大片一区二区| 国产高清一区日本| 中文字幕一区二区三区不卡 | 精品日韩一区二区三区| 看电影不卡的网站| 国产午夜精品一区二区三区嫩草 | 亚洲人成在线播放网站岛国| 色婷婷久久久亚洲一区二区三区| 一区二区三区国产精品| 555夜色666亚洲国产免| 捆绑变态av一区二区三区| 2024国产精品视频| 成人精品免费视频| 亚洲综合激情另类小说区| 5566中文字幕一区二区电影| 老司机精品视频一区二区三区| 久久久久国产免费免费| 91丨九色丨蝌蚪丨老版| 亚洲18女电影在线观看| 2020国产成人综合网| 不卡大黄网站免费看| 亚洲一级片在线观看| 欧美va亚洲va| av中文字幕在线不卡| 亚洲国产一区二区视频| 日韩一区二区三区高清免费看看| 国产成人在线视频播放| 亚洲男帅同性gay1069| 91精品国产色综合久久ai换脸| 狠狠色综合播放一区二区| 国产精品久久久久影视| 欧美吞精做爰啪啪高潮| 国产在线日韩欧美| 亚洲最新在线观看| 精品国产三级电影在线观看| av激情综合网| 日本女优在线视频一区二区| 欧美国产视频在线| 欧美日韩精品免费观看视频| 国产乱子伦视频一区二区三区| 亚洲激情在线播放| 精品播放一区二区| 91福利国产精品| 捆绑调教一区二区三区| 亚洲精品免费一二三区| 精品久久久网站| 色妹子一区二区| 国产综合色视频| 亚洲国产精品视频| 国产日本欧美一区二区| 欧美色男人天堂| 国产成人自拍网| 天天操天天综合网| 中文字幕不卡的av| 欧美一区二区在线不卡| 97精品久久久午夜一区二区三区 | 久久九九99视频| 欧美日韩成人激情| 国产ts人妖一区二区| 午夜欧美2019年伦理| 国产精品区一区二区三区| 欧美一区二区三区思思人| 91麻豆6部合集magnet| 久久99精品视频| 丝袜美腿一区二区三区| 中文字幕中文乱码欧美一区二区| 日韩女优毛片在线| 欧美三区在线观看| av在线不卡电影| 国产精品自拍在线| 日本欧美肥老太交大片| 亚洲国产美女搞黄色| 国产精品第五页| 国产亚洲欧美一级| 欧美一级久久久久久久大片| 欧美影片第一页| 色综合中文综合网| 欧美日韩亚洲综合| 极品美女销魂一区二区三区 | 精品免费国产一区二区三区四区| 欧亚洲嫩模精品一区三区| 国产91精品欧美| 精彩视频一区二区| 日韩 欧美一区二区三区| 亚洲图片欧美一区| 亚洲在线中文字幕| 亚洲你懂的在线视频| 综合分类小说区另类春色亚洲小说欧美| 久久久久久久久一| 精品国产凹凸成av人导航| 欧美疯狂性受xxxxx喷水图片| 一道本成人在线| 色综合久久天天综合网| 本田岬高潮一区二区三区| 国产盗摄视频一区二区三区| 九九精品一区二区| 亚洲高清免费观看| 亚洲综合久久久| 夜色激情一区二区| 亚洲午夜一区二区| 亚洲国产日韩精品| 午夜不卡av在线| 亚洲国产另类av| 亚洲国产欧美日韩另类综合| 一区二区成人在线视频| 一区二区国产视频| 亚洲成a人在线观看| 亚洲国产精品视频| 日韩精品一区第一页| 日韩av电影天堂| 日韩影院免费视频| 青青青伊人色综合久久| 毛片不卡一区二区| 精品系列免费在线观看| 国产综合色精品一区二区三区| 国内精品写真在线观看| 国产精品123区| 国产成人免费视频| 成人福利视频在线看| 99精品视频在线播放观看| 色综合视频一区二区三区高清| 在线一区二区三区四区| 6080亚洲精品一区二区| 欧美mv日韩mv亚洲| 日本一区二区三区在线观看| 国产精品久久久久久久午夜片 | 欧美一级久久久| 久久综合久久综合九色| 国产欧美va欧美不卡在线| 国产精品美女www爽爽爽| 亚洲一区免费视频| 日本成人在线看| 国产成人在线观看| 99精品一区二区三区| 欧美久久久久久久久中文字幕| 欧美xxxxx牲另类人与| 国产精品麻豆欧美日韩ww| 亚洲你懂的在线视频| 七七婷婷婷婷精品国产| 国产·精品毛片| 日本韩国一区二区三区视频| 欧美美女直播网站| 国产午夜精品一区二区三区四区|