Arduino EEPROM 的操作
2016-03-16 11:24
861 查看
#include <EEPROM.h> struct MyObject{ float field1; byte field2; char name[10]; }; void setup(){ Serial.begin(9600); while (!Serial) { ; } float f = 123.456f; unsigned int eeAddress = 0; EEPROM.write( eeAddress, f ); Serial.println("Written float data type!"); MyObject customVar = { 3.14f, 65, "Working" }; eeAddress += sizeof(float); //EEPROM.write( eeAddress, customVar ); EEPROM_write_block ((unsigned char*)&customVar,eeAddress,sizeof(MyObject)); Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" ); MyObject xixi ; EEPROM_read_block((unsigned char*)&xixi,eeAddress,sizeof(MyObject)); Serial.print(xixi.field1); Serial.print(xixi.field2); Serial.print(xixi.name); } void loop(){ //int address = 0; //float f ; // EEPROM.read(address,f); // address += sizeof(MyObject); } void EEPROM_write_block(unsigned char *memory_block, unsigned int start_address, unsigned int block_size) { unsigned char Count = 0; for (Count=0; Count < block_size; Count++) { EEPROM.write(start_address + Count, memory_block[Count]); } } void EEPROM_read_block(unsigned char *memory_block, unsigned int start_address, unsigned int block_size) { unsigned char Count = 0; for (Count=0; Count < block_size; Count++) { memory_block[Count]= EEPROM.read(start_address + Count); } }
相关文章推荐
- 使用AsyncDisplayKit提升UICollectionView和UITableView的滚动性能
- String,StringBuffer,StringBuild区别
- UIViewController的生命周期及iOS程序执行顺序
- Android studio b Error: No resource found that matches the given name (at 'src' with value '@dra...
- iOS UIlabel一些常用属性方法总结
- SystemUI之Airplane mode之分析
- 日志搜集、过滤及推送处理框架logstash及fluentd总结
- request和response中文乱码
- UIPageControl-页面控件
- String与CharSequence的区别与联系
- Unknown class ViewController in Interface Builder file问题解决
- Android Volley入门到精通:定制自己的Request
- iOS UI自动化测试与代码覆盖率
- UICollectionView不能拖拽或者刷新抖动
- ContentValues
- UILable 的字体加宽,倾斜
- UIBezierPath精讲
- Android:一个高效的UI才是一个拉风的UI(一)
- 62. Unique Paths && 63 Unique Paths II
- 仿MIUI的Toast动画效果实现