📄 spieeprom_8c-source.html
字号:
<!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: spieeprom.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>spieeprom.c</h1><a href="spieeprom_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file spieeprom.c \brief Interface for standard SPI EEPROM memories. */</span>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'spieeprom.c'</span>00005 <span class="comment">// Title : Interface for standard SPI EEPROM memories</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span>00007 <span class="comment">// Created : 2004.10.07</span>00008 <span class="comment">// Revised : 2004.10.07</span>00009 <span class="comment">// Version : 0.1</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">// This code is distributed under the GNU Public License</span>00014 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>00015 <span class="comment">//</span>00016 <span class="comment">//*****************************************************************************</span>00017 00018 <span class="preprocessor">#include <avr/io.h></span>00019 <span class="preprocessor">#include <avr/interrupt.h></span>00020 00021 <span class="preprocessor">#include "<a class="code" href="spi_8h.html">spi.h</a>"</span>00022 <span class="preprocessor">#include "<a class="code" href="spieeprom_8h.html">spieeprom.h</a>"</span>00023 00024 <span class="comment">// functions</span><a name="l00025"></a><a class="code" href="spieeprom_8h.html#a11">00025</a> <span class="keywordtype">void</span> <a class="code" href="spieeprom_8c.html#a0">spieepromInit</a>(<span class="keywordtype">void</span>)00026 {00027 <span class="comment">// although there is no code here</span>00028 <span class="comment">// don't forget to initialize the SPI interface itself</span>00029 <span class="comment">// sbi(DDRB, 0);</span>00030 }00031 <a name="l00032"></a><a class="code" href="spieeprom_8h.html#a12">00032</a> u08 <a class="code" href="spieeprom_8c.html#a1">spieepromReadByte</a>(u32 memAddr)00033 {00034 u08 data;00035 <span class="comment">// cbi(PORTB,0);</span>00036 <span class="comment">// send command</span>00037 spiTransferByte(<a class="code" href="spieeprom_8h.html#a0">SPIEEPROM_CMD_READ</a>);00038 <span class="comment">// send address</span>00039 spiTransferByte(memAddr>>8);00040 spiTransferByte(memAddr&0x00FF);00041 <span class="comment">// read contents of memory address</span>00042 data = spiTransferByte(0xFF);00043 <span class="comment">// return data</span>00044 <span class="keywordflow">return</span> data;00045 <span class="comment">// sbi(PORTB,0);</span>00046 }00047 <a name="l00048"></a><a class="code" href="spieeprom_8h.html#a13">00048</a> <span class="keywordtype">void</span> <a class="code" href="spieeprom_8c.html#a2">spieepromWriteByte</a>(u32 memAddr, u08 data)00049 {00050 <span class="comment">// wait for any previous write to complete</span>00051 <span class="keywordflow">while</span>(spieepromReadStatus() & <a class="code" href="spieeprom_8h.html#a6">SPIEEPROM_STATUS_WIP</a>);00052 00053 <span class="comment">// cbi(PORTB,0);</span>00054 <span class="comment">// send command</span>00055 spiTransferByte(<a class="code" href="spieeprom_8h.html#a1">SPIEEPROM_CMD_WRITE</a>);00056 <span class="comment">// send address</span>00057 spiTransferByte(memAddr>>8);00058 spiTransferByte(memAddr&0x00FF);00059 <span class="comment">// send data to be written</span>00060 spiTransferByte(data);00061 <span class="comment">// sbi(PORTB,0);</span>00062 }00063 00064 <span class="keywordtype">void</span> spieepromWriteEnable(<span class="keywordtype">void</span>)00065 {00066 <span class="comment">// cbi(PORTB,0);</span>00067 <span class="comment">// send command</span>00068 spiTransferByte(<a class="code" href="spieeprom_8h.html#a2">SPIEEPROM_CMD_WREN</a>);00069 <span class="comment">// sbi(PORTB,0);</span>00070 }00071 00072 <span class="keywordtype">void</span> spieepromWriteDisable(<span class="keywordtype">void</span>)00073 {00074 <span class="comment">// cbi(PORTB,0);</span>00075 <span class="comment">// send command</span>00076 spiTransferByte(<a class="code" href="spieeprom_8h.html#a3">SPIEEPROM_CMD_WRDI</a>);00077 <span class="comment">// sbi(PORTB,0);</span>00078 }00079 00080 u08 spieepromReadStatus(<span class="keywordtype">void</span>)00081 {00082 u08 status;00083 <span class="comment">// cbi(PORTB,0);</span>00084 <span class="comment">// send command</span>00085 spiTransferByte(<a class="code" href="spieeprom_8h.html#a4">SPIEEPROM_CMD_RDSR</a>);00086 <span class="comment">// get status register value</span>00087 status = spiTransferByte(0xFF);00088 <span class="comment">// sbi(PORTB,0);</span>00089 <span class="keywordflow">return</span> status;00090 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -