To Mr.MGP and Mr.Jonathan W. (by spy)
how to make a counter,that when i turn off and then turn ON again the previous data is still count
(no subject) (by MGP)
You also can supervise the supply voltage and when it becomes lower then 4V (the pic will still run at this voltage) do as Boris wrote.
You can use an adc input or optocoupler, relay, TL431, transistor, zenerdiode...etc.
If the countingspeed is low then use "persistent" without contact or adc.
You can count >>> 100000 before the cpu eeprom fails.