Thứ Ba, 4 tháng 12, 2018

Cách lưu biến float vào EEPROM

Ví dụ sau đây chỉ cách đọc hoặc viết số kiểu float lưu trong EEPROM

  • n is an offset into the eeprom.
  • For example if the first float is at 0 the second
  • For floats you must increment it by 4.
  • one should be at 4 and the third at 8.
WRITE_FLOAT_EXT_EEPROM(long int n, float data) { 
   int i;

   for (i = 0; i < 4; i++) 
      write_ext_eeprom(i + n, *((int8*)&data + i) ) ; 
}

float READ_FLOAT_EXT_EEPROM(long int n) { 
   int i; 
   float data;

   for (i = 0; i < 4; i++) 
      *((int8*)&data + i) = read_ext_eeprom(i + n);

   return(data); 
}

Không có nhận xét nào:

Đăng nhận xét

Bài đăng mới nhất

Valdes Fernando - Microcontrollers Applications With Pic

Bài đăng phổ biến