📄 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/signal.h></span>00020 <span class="preprocessor">#include <avr/interrupt.h></span>00021 00022 <span class="preprocessor">#include "<a class="code" href="spi_8h.html">spi.h</a>"</span>00023 <span class="preprocessor">#include "<a class="code" href="spieeprom_8h.html">spieeprom.h</a>"</span>00024 00025 <span class="comment">// functions</span><a name="l00026"></a><a class="code" href="spieeprom_8h.html#a11">00026</a> <span class="keywordtype">void</span> <a class="code" href="spieeprom_8c.html#a0">spieepromInit</a>(<span class="keywordtype">void</span>)00027 {00028 <span class="comment">// although there is no code here</span>00029 <span class="comment">// don't forget to initialize the SPI interface itself</span>00030 <span class="comment">// sbi(DDRB, 0);</span>00031 }00032 <a name="l00033"></a><a class="code" href="spieeprom_8h.html#a12">00033</a> u08 <a class="code" href="spieeprom_8c.html#a1">spieepromReadByte</a>(u32 memAddr)00034 {00035 u08 data;00036 <span class="comment">// cbi(PORTB,0);</span>00037 <span class="comment">// send command</span>00038 spiTransferByte(<a class="code" href="spieeprom_8h.html#a0">SPIEEPROM_CMD_READ</a>);00039 <span class="comment">// send address</span>00040 spiTransferByte(memAddr>>8);00041 spiTransferByte(memAddr&0x00FF);00042 <span class="comment">// read contents of memory address</span>00043 data = spiTransferByte(0xFF);00044 <span class="comment">// return data</span>00045 <span class="keywordflow">return</span> data;00046 <span class="comment">// sbi(PORTB,0);</span>00047 }00048 <a name="l00049"></a><a class="code" href="spieeprom_8h.html#a13">00049</a> <span class="keywordtype">void</span> <a class="code" href="spieeprom_8c.html#a2">spieepromWriteByte</a>(u32 memAddr, u08 data)00050 {00051 <span class="comment">// wait for any previous write to complete</span>00052 <span class="keywordflow">while</span>(spieepromReadStatus() & <a class="code" href="spieeprom_8h.html#a6">SPIEEPROM_STATUS_WIP</a>);00053 00054 <span class="comment">// cbi(PORTB,0);</span>00055 <span class="comment">// send command</span>00056 spiTransferByte(<a class="code" href="spieeprom_8h.html#a1">SPIEEPROM_CMD_WRITE</a>);00057 <span class="comment">// send address</span>00058 spiTransferByte(memAddr>>8);00059 spiTransferByte(memAddr&0x00FF);00060 <span class="comment">// send data to be written</span>00061 spiTransferByte(data);00062 <span class="comment">// sbi(PORTB,0);</span>00063 }00064 00065 <span class="keywordtype">void</span> spieepromWriteEnable(<span class="keywordtype">void</span>)00066 {00067 <span class="comment">// cbi(PORTB,0);</span>00068 <span class="comment">// send command</span>00069 spiTransferByte(<a class="code" href="spieeprom_8h.html#a2">SPIEEPROM_CMD_WREN</a>);00070 <span class="comment">// sbi(PORTB,0);</span>00071 }00072 00073 <span class="keywordtype">void</span> spieepromWriteDisable(<span class="keywordtype">void</span>)00074 {00075 <span class="comment">// cbi(PORTB,0);</span>00076 <span class="comment">// send command</span>00077 spiTransferByte(<a class="code" href="spieeprom_8h.html#a3">SPIEEPROM_CMD_WRDI</a>);00078 <span class="comment">// sbi(PORTB,0);</span>00079 }00080 00081 u08 spieepromReadStatus(<span class="keywordtype">void</span>)00082 {00083 u08 status;00084 <span class="comment">// cbi(PORTB,0);</span>00085 <span class="comment">// send command</span>00086 spiTransferByte(<a class="code" href="spieeprom_8h.html#a4">SPIEEPROM_CMD_RDSR</a>);00087 <span class="comment">// get status register value</span>00088 status = spiTransferByte(0xFF);00089 <span class="comment">// sbi(PORTB,0);</span>00090 <span class="keywordflow">return</span> status;00091 }</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 24 16:03:55 2005 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 + -