|
M4里面的EEPROM并不是编址在内存空间中的,而是直接通过操作寄存器(Register)进行读写的。所以EEPROM中间的某个地址就是只属于EEPROM的地址,并不和内存地址有冲突。
要想方便的使用EEPROM,最好的办法就是使用TI的StellarisWare驱动库程序:
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_memmap.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_types.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_timer.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_ints.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "inc/hw_gpio.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "driverlib/sysctl.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">#include "driverlib/eeprom.h"</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">unsigned long pulRead[2];</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">void main()</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">{</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> unsigned long pulData[2];</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> // 系统工作在50MHZ</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> // 使能EEPROM</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0); </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> // 初始化EEPROM</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> EEPROMInit(); </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> pulData[0] = 0x12345678;</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> pulData[1] = 0x56789abc; </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> // 向EEPROM里面0x400地址写入数据</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> EEPROMProgram(pulData, 0x400, sizeof(pulData)); </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"="">
- </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> // 读回来</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> EEPROMRead(pulRead, 0x400, sizeof(pulRead)); </font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> while(1)</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> {</font>
- <font size="4" style="color: rgb(51, 51, 51); font-family: " microsoft="" yahei";"=""> }</font>
复制代码
|
|