⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeprom使用详解—avr使用范例.htm

📁 avr硬件软件开发的一些总结 用AVR单片机模拟的串口程序 AVR基本硬件线路设计与分析 等等
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0045)http://www.avrvi.com/avr_examples/eeprom.html -->
<HTML 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>EEPROM使用详解—AVR使用范例</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="AVR 新手入门 单片机 AVR与虚拟仪器网站提供" name=description>
<META content="古欣 guxin[at]mail.sdu.edu.cn" name=author>
<META content="AVR 单片机 新手入门 手把手教程 avr程序 avr范例" name=keywords>
<STYLE title=css_design_by_guxin type=text/css media=all>@import url( ../inc/article.css );
</STYLE>
<LINK media=all href="EEPROM使用详解—AVR使用范例.files/article.css" type=text/css 
rel=stylesheet>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY>
<DIV class=m>
<H1 class=c>AVR与虚拟仪器 www.avrvi.com</H1></DIV>
<DIV class=m>
<DIV id=head>
<P class=c>AVR与虚拟仪器致力于提供最优质的AVR和labview技术服务,最全的技术资料,最好的开发板方案。</P>
<P class=c>我们将以AVR DB-CORE Ver2.3 Atmega16开发板为平台,一步一步,教会大家AVR单片机编程。</P>
<P class=c>本站所有范例都采用ICC编写,ICC编译器加AVR Studio下载调试,下载器为JTAG&amp;ISP下载编程器。 
</P></DIV></DIV>
<DIV class=m>
<DIV id=now>你现在的位置:<A href="http://www.avrvi.com/">AVR与虚拟仪器</A>&gt;&gt;<A 
href="http://www.avrvi.com/index_avr_examples.html">AVR使用范例</A>&gt;&gt;EEPROM使用详解<SPAN><A 
title=AVR与虚拟仪器论坛 href="http://bbs.avrvi.com/">论坛</A></SPAN></DIV></DIV>
<DIV class=m>
<H3>AVR使用范例--EEPROM使用详解</H3>
<DIV class=pad10>
<P>本页关键词:什么是eeprom spi eeprom eeprom程序 eeprom资料 eeprom结构 eeprom 读写 eeprom的读写</P>
<P>本页详细介绍ICC自带EEPROM操作函数的操作方法,包括<SPAN class=red>单字符</SPAN>读写,<SPAN 
class=red>数组</SPAN>读写,<SPAN class=red>结构体</SPAN>读写。</P>
<P>程序代码:<A title=下载eeprom相关文件 
href="http://www.avrvi.com/down.php?file=examples/eeprom_examples.rar">下载相关文件</A></P>
<UL>
  <LI><PRE>void main(void)
{
 unsigned char temp1,temp2;<SPAN class=gray>                                  /*定义变量*/</SPAN>
 unsigned char buffer[10];                                   <SPAN class=gray>/*定义数组*/</SPAN>
 unsigned char buf[]="AVR与虚拟仪器";                        <SPAN class=gray>/*定义字符串*/</SPAN>
 
 EEPROMwrite(0x10,'a');                                      <SPAN class=gray>/*单字符写入到0x10,</SPAN><SPAN class=red>注意是单引号</SPAN><SPAN class=gray>*/</SPAN>
 temp1 = EEPROMread(0x10);                                   <SPAN class=gray>/*读一个字符到temp1*/</SPAN>
 
 
 EEPROM_WRITE(0x20,"abcdefg");                               <SPAN class=gray>/*写字符串到0x20*/</SPAN>
 EEPROM_READ(0x20,temp2);                                    <SPAN class=gray>/*读</SPAN><SPAN class=red>字符</SPAN><SPAN class=gray>到temp2,temp2=a*/</SPAN> 
 EEPROM_READ(0x20,buffer);                                   <SPAN class=gray>/*读</SPAN><SPAN class=red>字符串</SPAN><SPAN class=gray>到数组中 buffer[10]=abcdefg */</SPAN>
 
 EEPROM_WRITE(0x30,buf);                                     <SPAN class=gray>/*</SPAN><SPAN class=gray>数组中的值写到EEPROM中:0X30开始为"AVR与虚拟仪器"*/</SPAN>
 
 while(1)
 ;
} 
</PRE></LI></UL>
<P class=title>调试后的效果:</P>
<P>调试eeprom的时候,记住设置Avr studio<SPAN 
class=red>保护eeprom数据</SPAN>,否则每次都会将eeprom中的数据改为0xFF。如下图:</P>
<P>打开调试选项:</P>
<P><IMG height=364 alt=打开调试选项的方法 src="EEPROM使用详解—AVR使用范例.files/eeprom_1.gif" 
width=300></P>
<P>钩选保护eeprom数据选项:</P>
<P><IMG height=360 alt=钩选保护eeprom选项 src="EEPROM使用详解—AVR使用范例.files/eeprom_2.gif" 
width=427></P>
<P class=title>打开相关观测窗口:</P>
<P><IMG height=582 alt=打开调试窗查看程序运行情况 src="EEPROM使用详解—AVR使用范例.files/eeprom_3.gif" 
width=611></P>
<P class=title>按F10逐条语句运行,查看运行结果。</P>
<OL>
  <LI>地址10上的值被改写为“a”<BR><IMG height=212 alt=地址10上的值被改写 
  src="EEPROM使用详解—AVR使用范例.files/eeprom_4.gif" width=320> 
  <LI>temp1的值变为a,及读取了地址0x10的值a:<BR><IMG height=200 alt=temp1的值变为a 
  src="EEPROM使用详解—AVR使用范例.files/eeprom_5.gif" width=300> 
  <LI>abcdefg写入20开始的地址:<BR><IMG height=212 alt=abcdefg写入20开始的地址 
  src="EEPROM使用详解—AVR使用范例.files/eeprom_6.gif" width=320> 
  <LI>temp2的变为地址20的值a:<BR><IMG height=200 alt="" 
  src="EEPROM使用详解—AVR使用范例.files/eeprom_7.gif" width=300> 
  <LI>以0x20开始的值都读入buffer数组中:<BR><IMG height=334 alt=" " 
  src="EEPROM使用详解—AVR使用范例.files/eeprom_8.gif" width=300> 
  <LI>预定义的数组中的值写到EEPROM中:<BR><IMG height=138 alt=预定义的数组中的值写到EEPROM中 
  src="EEPROM使用详解—AVR使用范例.files/eeprom_9.gif" width=555> 
  <LI>设置不保护EEPROM的值之后,停止调试再开始调试,EEPROM中的值改为0XFF:<BR><IMG height=138 
  alt=数据恢复成0XFF src="EEPROM使用详解—AVR使用范例.files/eeprom_10.gif" width=555> </LI></OL>
<P>通过以上的观察,我想你已经对EEPROM的操作有了一定的认识,同时,你可以打开eeprom.h查看内部内容,是如何定义函数的。</P>
<P><SPAN class=title>结构体的操作方法与数组类似</SPAN>:(一般简单应用中,你用不到下面的知识,看不懂没有关系,不要被吓倒了)</P>
<UL>
  <LI>EEPROMWriteBytes(0x10,&amp;red_flag,sizeof(red_flag)); //将结构写入EEPROM 
  <LI>EEPROMReadBytes(0x10,&amp;red_flag,sizeof(red_flag)); //从EEPROM中将结构全部读出来 
  <LI>旗帜的结构为 <PRE>/*
typedef struct
{
uint8 position;  //0   底   1~180: 中间   180:顶
uint8 fangxiang; //0   静止中 'u' : 向上   'd':向下 
uint8 T;         //0   总时间
uint8 t;         //0   已经耗去的时间
uint8 S;         //0   目标路程
uint8 s;         //0   已经走过的路程
uint8 move_flag; //0   是否运动中
uint8 half_mode; //0   非半旗  1:半旗
uint8 purse;     //0   没有暂停 1:暂停状态
uint8 half_short_or_long;//0    1:半旗长路程中 2:半旗短路程中
uint16 maichong; //0            脉冲数目
}QIZHI;
<SPAN class=red>QIZHI red_flag;</SPAN>                 //旗帜结构
*/</PRE></LI></UL></DIV></DIV>
<DIV class=m>
<H4 id=link><A href="http://www.avrvi.com/">AVR 与虚拟仪器</A>欢迎交换链接,请与小古联系 
avrvi【at】163.com </H4>
<SCRIPT src="EEPROM使用详解—AVR使用范例.files/links.js" type=text/javascript></SCRIPT>

<SCRIPT src="EEPROM使用详解—AVR使用范例.files/footer.js" type=text/javascript></SCRIPT>
</DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -