You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
261 lines
15 KiB
HTML
261 lines
15 KiB
HTML
<!-- HTML header for doxygen 1.8.7-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.6.3"/>
|
|
<!--BEGIN PROJECT_NAME--><title>avr-libc: avr-libc: <avr/sfr_defs.h>: Special function registers</title><!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME--><title>avr-libc: <avr/sfr_defs.h>: Special function registers</title><!--END !PROJECT_NAME-->
|
|
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
|
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
|
$treeview
|
|
$search
|
|
$mathjax
|
|
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
|
$extrastylesheet
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
|
|
<!--BEGIN TITLEAREA-->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<!--BEGIN PROJECT_LOGO-->
|
|
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
|
<!--END PROJECT_LOGO-->
|
|
<!--BEGIN PROJECT_NAME-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectname">avr-libc
|
|
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">2.0.0</span><!--END PROJECT_NUMBER-->
|
|
</div>
|
|
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
|
</td>
|
|
<!--END PROJECT_NAME-->
|
|
<!--BEGIN !PROJECT_NAME-->
|
|
<!--BEGIN PROJECT_BRIEF-->
|
|
<td style="padding-left: 0.5em;">
|
|
<div id="projectbrief">$projectbrief</div>
|
|
</td>
|
|
<!--END PROJECT_BRIEF-->
|
|
<!--END !PROJECT_NAME-->
|
|
<!--BEGIN DISABLE_INDEX-->
|
|
<!--BEGIN SEARCHENGINE-->
|
|
<td>$searchbox</td>
|
|
<!--END SEARCHENGINE-->
|
|
<!--END DISABLE_INDEX-->
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table>
|
|
<tr>
|
|
<td align="left"><a href="http://www.nongnu.org/avr-libc/"><h2>AVR Libc Home Page</h2></a></td>
|
|
<td align="center" colspan=4><img src="avrs.png" alt="AVRs" align="middle" border="0"></td>
|
|
<td align="right"><a href="https://savannah.nongnu.org/projects/avr-libc/"><h2>AVR Libc Development Pages</h2></a></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" width="20%"><a href="index.html"><h2>Main Page</h2></a></td>
|
|
<td align="center" width="20%"><a href="pages.html"><h2>User Manual</h2></a></td>
|
|
<td align="center" width="20%"><a href="modules.html"><h2>Library Reference</h2></a></td>
|
|
<td align="center" width="20%"><a href="FAQ.html"><h2>FAQ</h2></a></td>
|
|
<td align="center" width="20%"><a href="group__demos.html"><h2>Example Projects</h2></a></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<!--END TITLEAREA-->
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.6.3 -->
|
|
<script type="text/javascript"><!--
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
--></script>
|
|
<div class="contents">
|
|
<h1><avr/sfr_defs.h>: Special function registers</h1><table border="0" cellpadding="0" cellspacing="0">
|
|
<tr><td colspan="2"><h2>Modules</h2></td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__avr__sfr__notes.html">Additional notes from <avr/sfr_defs.h></a></td></tr>
|
|
<tr><td colspan="2"><h2>Bit manipulation</h2></td></tr>
|
|
<tr><td colspan="2"><p><a class="anchor" id="amgrpf30dbbede0898fee36ed270cd84b8f29"></a> </p>
|
|
<br/><br/></td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__avr__sfr.html#ga11643f271076024c395a93800b3d9546">_BV</a>(bit) (1 << (bit))</td></tr>
|
|
<tr><td colspan="2"><h2>IO register bit manipulation</h2></td></tr>
|
|
<tr><td colspan="2"><p><a class="anchor" id="amgrp1781a0b42846497d95d8c317ac5216e5"></a> </p>
|
|
<br/><br/></td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__avr__sfr.html#ga3b034cb1d74b9addc7599bd6ea6bd0d9">bit_is_set</a>(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))</td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__avr__sfr.html#gad188fb0fbfd923bdb01294072367d024">bit_is_clear</a>(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit)))</td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__avr__sfr.html#gaaf6857fa882da35f8685e2001e5c3bbe">loop_until_bit_is_set</a>(sfr, bit) do { } while (bit_is_clear(sfr, bit))</td></tr>
|
|
<tr><td class="memItemLeft" align="right" valign="top">#define </td><td class="memItemRight" valign="bottom"><a class="el" href="group__avr__sfr.html#gabf06c3d703cf5adc691c0be5d72e7839">loop_until_bit_is_clear</a>(sfr, bit) do { } while (bit_is_set(sfr, bit))</td></tr>
|
|
</table>
|
|
<hr/><a name="_details"></a><h2>Detailed Description</h2>
|
|
<p>When working with microcontrollers, many tasks usually consist of controlling internal peripherals, or external peripherals that are connected to the device. The entire IO address space is made available as <em>memory-mapped IO</em>, i.e. it can be accessed using all the MCU instructions that are applicable to normal data memory. For most AVR devices, the IO register space is mapped into the data memory address space with an offset of 0x20 since the bottom of this space is reserved for direct access to the MCU registers. (Actual SRAM is available only behind the IO register area, starting at some specific address depending on the device.)</p>
|
|
<p>For example the user can access memory-mapped IO registers as if they were globally defined variables like this:</p>
|
|
<div class="fragment"><pre class="fragment"> PORTA = 0x33;
|
|
<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> foo = PINA;
|
|
</pre></div><p>The compiler will choose the correct instruction sequence to generate based on the address of the register being accessed.</p>
|
|
<p>The advantage of using the memory-mapped registers in C programs is that it makes the programs more portable to other C compilers for the AVR platform.</p>
|
|
<p>Note that special care must be taken when accessing some of the 16-bit timer IO registers where access from both the main program and within an interrupt context can happen. See <a class="el" href="FAQ.html#faq_16bitio">Why do some 16-bit timer registers sometimes get trashed?</a>.</p>
|
|
<dl class="user"><dt><b>Porting programs that use the deprecated sbi/cbi macros</b></dt><dd></dd></dl>
|
|
<p>Access to the AVR single bit set and clear instructions are provided via the standard C bit manipulation commands. The sbi and cbi macros are no longer directly supported. sbi (sfr,bit) can be replaced by sfr |= <a class="el" href="group__avr__sfr.html#ga11643f271076024c395a93800b3d9546">_BV(bit)</a> .</p>
|
|
<p>i.e.: <a class="el" href="group__deprecated__items.html#ga014ef751e83f97569c06f3cdd888f3f7">sbi(PORTB, PB1)</a>; is now PORTB |= <a class="el" href="group__avr__sfr.html#ga11643f271076024c395a93800b3d9546">_BV(PB1)</a>;</p>
|
|
<p>This actually is more flexible than having sbi directly, as the optimizer will use a hardware sbi if appropriate, or a read/or/write operation if not appropriate. You do not need to keep track of which registers sbi/cbi will operate on.</p>
|
|
<p>Likewise, cbi (sfr,bit) is now sfr &= ~(<a class="el" href="group__avr__sfr.html#ga11643f271076024c395a93800b3d9546">_BV(bit)</a>); </p>
|
|
<hr/><h2>Define Documentation</h2>
|
|
<a class="anchor" id="ga11643f271076024c395a93800b3d9546"></a><!-- doxytag: member="sfr_defs.h::_BV" ref="ga11643f271076024c395a93800b3d9546" args="(bit)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">#define _BV</td>
|
|
<td>(</td>
|
|
<td class="paramtype">bit </td>
|
|
<td class="paramname"></td>
|
|
<td> ) </td>
|
|
<td> (1 << (bit))</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
</pre></div><p>Converts a bit number into a byte value.</p>
|
|
<dl class="note"><dt><b>Note:</b></dt><dd>The bit shift is performed by the compiler which then inserts the result into the code. Thus, there is no run-time overhead when using <a class="el" href="group__avr__sfr.html#ga11643f271076024c395a93800b3d9546">_BV()</a>. </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a class="anchor" id="gad188fb0fbfd923bdb01294072367d024"></a><!-- doxytag: member="sfr_defs.h::bit_is_clear" ref="gad188fb0fbfd923bdb01294072367d024" args="(sfr, bit)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">#define bit_is_clear</td>
|
|
<td>(</td>
|
|
<td class="paramtype">sfr, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">bit </td>
|
|
<td class="paramname"></td>
|
|
<td> ) </td>
|
|
<td> (!(_SFR_BYTE(sfr) & _BV(bit)))</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
</pre></div><p>Test whether bit <code>bit</code> in IO register <code>sfr</code> is clear. This will return non-zero if the bit is clear, and a 0 if the bit is set. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a class="anchor" id="ga3b034cb1d74b9addc7599bd6ea6bd0d9"></a><!-- doxytag: member="sfr_defs.h::bit_is_set" ref="ga3b034cb1d74b9addc7599bd6ea6bd0d9" args="(sfr, bit)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">#define bit_is_set</td>
|
|
<td>(</td>
|
|
<td class="paramtype">sfr, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">bit </td>
|
|
<td class="paramname"></td>
|
|
<td> ) </td>
|
|
<td> (_SFR_BYTE(sfr) & _BV(bit))</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
</pre></div><p>Test whether bit <code>bit</code> in IO register <code>sfr</code> is set. This will return a 0 if the bit is clear, and non-zero if the bit is set. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a class="anchor" id="gabf06c3d703cf5adc691c0be5d72e7839"></a><!-- doxytag: member="sfr_defs.h::loop_until_bit_is_clear" ref="gabf06c3d703cf5adc691c0be5d72e7839" args="(sfr, bit)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">#define loop_until_bit_is_clear</td>
|
|
<td>(</td>
|
|
<td class="paramtype">sfr, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">bit </td>
|
|
<td class="paramname"></td>
|
|
<td> ) </td>
|
|
<td> do { } while (bit_is_set(sfr, bit))</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
</pre></div><p>Wait until bit <code>bit</code> in IO register <code>sfr</code> is clear. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a class="anchor" id="gaaf6857fa882da35f8685e2001e5c3bbe"></a><!-- doxytag: member="sfr_defs.h::loop_until_bit_is_set" ref="gaaf6857fa882da35f8685e2001e5c3bbe" args="(sfr, bit)" -->
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">#define loop_until_bit_is_set</td>
|
|
<td>(</td>
|
|
<td class="paramtype">sfr, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">bit </td>
|
|
<td class="paramname"></td>
|
|
<td> ) </td>
|
|
<td> do { } while (bit_is_clear(sfr, bit))</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="memdoc">
|
|
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <<a class="code" href="io_8h.html">avr/io.h</a>></span>
|
|
</pre></div><p>Wait until bit <code>bit</code> in IO register <code>sfr</code> is set. </p>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Defines</a></div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<!-- HTML footer for doxygen 1.8.7-->
|
|
<!-- start footer part -->
|
|
<!--BEGIN GENERATE_TREEVIEW-->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
$navpath
|
|
<li class="footer">$generatedby
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/></a> 1.6.3 </li>
|
|
</ul>
|
|
</div>
|
|
<!--END GENERATE_TREEVIEW-->
|
|
<!--BEGIN !GENERATE_TREEVIEW-->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
$generatedby  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="$relpath^doxygen.png" alt="doxygen"/>
|
|
</a> 1.6.3
|
|
</small></address>
|
|
<!--END !GENERATE_TREEVIEW-->
|
|
</body>
|
|
</html>
|