Project with a counter that needs count saved when powered down

wvmarle:
That's load balancing. The problem here is: how will you store which page you were currently using?

Go through the pages one at a time until you find a page that is not all zeros. That is the page I am using.

Actually, using my "count to 1,600,000" scheme, you only need to use one page. Of the 32 bits on that page, use 15 bits to count from 0 to 15 in unary. (Inverse unary, actually: you start with all bits set to 1s and then one at a time set each of the bits to 0.) To count higher than 15, reset the page and then write the number of "sixteens" into the other 17 bits.

  Count        The bits in the page               Remarks
=======  ====================================  ====================================================
      0  00000000 00000000 0 1111111 11111111  The 1st reset to all 1's is just before this write
      1  00000000 00000000 0 1111111 11111110  Set one bit to 0
      2  00000000 00000000 0 1111111 11111100  Set the next bit to 0
      3  00000000 00000000 0 1111111 11111000  And so forth
      4  00000000 00000000 0 1111111 11110000  Each time setting only one bit to 0
      5  00000000 00000000 0 1111111 11100000
      6  00000000 00000000 0 1111111 11000000
      7  00000000 00000000 0 1111111 10000000
      8  00000000 00000000 0 1111111 00000000
      9  00000000 00000000 0 1111110 00000000
     10  00000000 00000000 0 1111100 00000000
     11  00000000 00000000 0 1111000 00000000
     12  00000000 00000000 0 1110000 00000000
     13  00000000 00000000 0 1100000 00000000
     14  00000000 00000000 0 1000000 00000000
     15  00000000 00000000 0 0000000 00000000  We cannot proceed further without a page reset
     16  00000000 00000000 1 1111111 11111111  The 2nd reset to all 1's is just before this write
     17  00000000 00000000 1 1111111 11111110  From there, we proceed as before
     18  00000000 00000000 1 1111111 11111100
     19  00000000 00000000 1 1111111 11111000
     20  00000000 00000000 1 1111111 11110000
     21  00000000 00000000 1 1111111 11100000
     22  00000000 00000000 1 1111111 11000000
     23  00000000 00000000 1 1111111 10000000
     24  00000000 00000000 1 1111111 00000000
     25  00000000 00000000 1 1111110 00000000
     26  00000000 00000000 1 1111100 00000000
     27  00000000 00000000 1 1111000 00000000
     28  00000000 00000000 1 1110000 00000000
     29  00000000 00000000 1 1100000 00000000
     30  00000000 00000000 1 1000000 00000000
     31  00000000 00000000 1 0000000 00000000  We cannot proceed further without a page reset
     32  00000000 00000001 0 1111111 11111111  The 3rd reset to all 1's is just before this write
     33  00000000 00000001 0 1111111 11111110
     34  00000000 00000001 0 1111111 11111100
     35  00000000 00000001 0 1111111 11111000
     36  00000000 00000001 0 1111111 11110000
     37  00000000 00000001 0 1111111 11100000
     38  00000000 00000001 0 1111111 11000000
     39  00000000 00000001 0 1111111 10000000
     40  00000000 00000001 0 1111111 00000000
     41  00000000 00000001 0 1111110 00000000
     42  00000000 00000001 0 1111100 00000000
     43  00000000 00000001 0 1111000 00000000
     44  00000000 00000001 0 1110000 00000000
     45  00000000 00000001 0 1100000 00000000
     46  00000000 00000001 0 1000000 00000000
     47  00000000 00000001 0 0000000 00000000  We cannot proceed further without a page reset
     48  00000000 00000001 1 1111111 11111111  The 4th reset to all 1's is just before this write
     49  00000000 00000001 1 1111111 11111110
     50  00000000 00000001 1 1111111 11111100
    ...  ........ ........ . ....... ........
  .....  ........ ........ . ....... ........
.......  ........ ........ . ....... ........   
1048574  01111111 11111111 1 1000000 00000000  So, why this weird storage format?
1048575  01111111 11111111 1 0000000 00000000  Because we're gonna need it right... about...
1048576  10000000 00000000 0 1111111 11111111  NOW!  (this is our 65537th reset)
.......  ........ ........ . ....... ........
.......  ........ ........ . ....... ........     
1599997  11000011 01001111 1 1100000 00000000
1599998  11000011 01001111 1 1000000 00000000
1599999  11000011 01001111 1 0000000 00000000  Technically, we should stop right here. (Why?)
1600000  11000011 01010000 0 1111111 11111111  This is the 100001st reset: our EEPROM craps out!