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

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

?? 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;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产日产av| 91视频.com| 精品剧情v国产在线观看在线| 综合电影一区二区三区| 国产一区二区三区观看| 日韩欧美综合在线| 免费欧美在线视频| 欧美一区二区免费| 免费av网站大全久久| 欧美精品三级在线观看| 亚洲高清视频在线| 91精品国产综合久久精品性色| 亚洲国产精品视频| 日本精品一级二级| 亚洲欧美电影一区二区| 色综合咪咪久久| 国产精品丝袜黑色高跟| www.成人网.com| 中文字幕一区二区三区四区不卡| 一本久久a久久精品亚洲| 亚洲靠逼com| 欧美日韩亚洲另类| 奇米精品一区二区三区在线观看一 | 国产99久久久国产精品| 久久久精品免费网站| 成人av资源下载| 亚洲激情五月婷婷| 91网站黄www| 一区二区三区不卡视频| 欧美日韩精品专区| 美日韩一级片在线观看| 国产欧美日产一区| 91色在线porny| 午夜视频在线观看一区二区| 欧美一区二区在线观看| 极品尤物av久久免费看| 欧美国产精品一区| 在线免费不卡电影| 亚洲午夜激情网页| 久久青草国产手机看片福利盒子 | 99久久国产免费看| 香蕉成人伊视频在线观看| 69堂精品视频| 国产成人小视频| 一区二区三区毛片| 日韩欧美国产一区二区在线播放| 韩国成人精品a∨在线观看| 亚洲免费在线视频| 欧美日韩的一区二区| 粉嫩久久99精品久久久久久夜| 国产精品久久久久影院色老大| 欧美日韩在线三区| 国产乱国产乱300精品| 亚洲激情六月丁香| 久久久亚洲欧洲日产国码αv| 91免费视频大全| 国产一区三区三区| 亚洲va天堂va国产va久| 色婷婷国产精品久久包臀| 懂色av一区二区夜夜嗨| 久久国产精品第一页| 爽好久久久欧美精品| 亚洲电影你懂得| 亚洲一区影音先锋| 一区二区三区蜜桃网| 亚洲精品第1页| 亚洲欧美视频在线观看视频| 日韩毛片高清在线播放| 中文字幕亚洲成人| 亚洲欧洲99久久| 亚洲丝袜自拍清纯另类| 1024国产精品| 亚洲女与黑人做爰| 亚洲欧美日韩综合aⅴ视频| 亚洲欧洲精品天堂一级| 亚洲男人的天堂网| 一区二区三区中文字幕在线观看| 日韩一区欧美小说| 亚洲精品日产精品乱码不卡| 一区二区三区精品视频| 亚洲国产精品自拍| 日韩av电影天堂| 蜜桃视频在线观看一区二区| 精品午夜一区二区三区在线观看| 久久99精品一区二区三区 | 亚洲午夜一区二区三区| 视频在线观看91| 乱中年女人伦av一区二区| 国产一区二三区| 成人av影视在线观看| 在线精品视频免费播放| 欧美嫩在线观看| 日韩美女天天操| 国产视频亚洲色图| 亚洲色图一区二区| 日韩一区精品视频| 国产一区二区三区蝌蚪| 99国内精品久久| 欧美日韩国产一二三| 日韩精品一区二区在线| 亚洲国产精品成人综合| 亚洲一区在线看| 精品午夜久久福利影院 | 亚洲国产精品一区二区久久| 全国精品久久少妇| 国产成人av电影在线| 欧美性欧美巨大黑白大战| 日韩午夜在线观看视频| 欧美国产一区二区在线观看| 亚洲国产视频一区二区| 激情久久五月天| 色悠久久久久综合欧美99| 91精品国产黑色紧身裤美女| 国产日产欧美一区二区视频| 一级女性全黄久久生活片免费| 麻豆成人免费电影| 99国产精品视频免费观看| 91精品国产色综合久久不卡电影| 国产色产综合色产在线视频| 亚洲国产精品久久人人爱蜜臀| 国产美女视频一区| 欧美日韩国产片| 国产欧美一区二区三区网站 | 亚洲男人的天堂在线aⅴ视频| 免费人成在线不卡| 91啦中文在线观看| 欧美xxxxxxxx| 午夜精品久久久久久不卡8050| 高清av一区二区| 日韩亚洲欧美成人一区| 亚洲精品菠萝久久久久久久| 国产精品69毛片高清亚洲| 精品视频一区二区三区免费| 1区2区3区国产精品| 国产精一品亚洲二区在线视频| 欧美日韩在线播| 亚洲同性gay激情无套| 久久av资源网| 欧美日韩国产区一| 亚洲精品国产无天堂网2021| 成人免费观看男女羞羞视频| 欧美xxxxx牲另类人与| 亚洲五月六月丁香激情| 不卡一区在线观看| 久久青草欧美一区二区三区| 青青草国产精品97视觉盛宴| 99精品视频免费在线观看| 久久亚洲精华国产精华液| 日本亚洲电影天堂| 欧美系列一区二区| 亚洲伦理在线免费看| 成人伦理片在线| 欧美精品一区二区三| 三级影片在线观看欧美日韩一区二区 | 日韩精品在线一区| 日本伊人精品一区二区三区观看方式 | 亚洲成av人片一区二区梦乃| 一本到高清视频免费精品| 中文字幕亚洲视频| 99v久久综合狠狠综合久久| 国产欧美1区2区3区| 国产一区二区三区精品视频| xnxx国产精品| 久久国产精品区| 久久午夜老司机| 国产高清不卡二三区| 国产日韩欧美a| 成人h动漫精品一区二区| 国产婷婷色一区二区三区| 国产美女精品人人做人人爽| 国产偷国产偷亚洲高清人白洁 | 日韩av成人高清| 欧美成人精品二区三区99精品| 免费看黄色91| 久久亚洲捆绑美女| 成人黄色网址在线观看| 亚洲人成亚洲人成在线观看图片 | 岛国精品一区二区| 国产精品久久久久一区| 91日韩一区二区三区| 亚洲国产另类av| 日韩欧美国产不卡| 国产精品一二三在| 1024亚洲合集| 欧美日韩国产123区| 蜜臀91精品一区二区三区| 久久久久9999亚洲精品| 成人国产视频在线观看| 亚洲一区二区三区美女| 欧美一区午夜精品| 国产精品1区二区.| 亚洲欧美日韩在线| 制服丝袜一区二区三区| 国产一区二区三区四区在线观看| 国产精品久久久久久久浪潮网站| 色婷婷精品久久二区二区蜜臀av| 免费在线观看视频一区| 欧美国产综合一区二区| 欧美性受xxxx黑人xyx| 国产综合久久久久久久久久久久|