PIC12F508 saving last count of compressor
In XC8 you can set a global or static variable to be persistent. These variables are not automatically cleared at startup like others are, so they retain their value across reboots (not across power-off though of course). 


  5.4.8.1 PERSISTENT TYPE QUALIFIER
  
  By default, any C variables that are not explicitly initialized are cleared on startup. This is consistent with the definition of the C language. However, there are occasions where it is desired for some data to be preserved across a Reset. The persistent type qualifier (or __persistent) is used to qualify variables that should not be cleared by the runtime startup code.
  
  In addition, any persistent variables will be stored in a different area of memory to other variables. Different psects are used to hold these objects. See 5.15.2 Compiler-Generated Psects for more information.
  
  This type qualifier cannot be used on variables of class auto; however, statically defined local variables can be qualified persistent. For example, you should write:
  
  void test(void)
  {
   static persistent int intvar; /* must be static */
   // ...
  }
  
  If the xc8 option, --STRICT is used, you cannot use the persistent qualifier, but you can continue to use __persistent.


Of course one "issue" with this is you don't get a power-on default of 0 for your counter - the actual power-on value may be completely random. So you can try examining the STATUS register to try and work out in what way the chip has started up, or give a manual reset option to the user in some way.