It got figured out on another forum. A better way actually, without writing to the on-chip EEPROM at all.
Code:
'***********************************************************************************
'* *
'* Microchip Pic 16F628 @ 8,16 or 24MHz *
'* Art 2015 *
'* *
'* [email protected] *
'* *
'***********************************************************************************
'
'
DEFINE OSC 20 '
DEFINE NO_CLRWDT 'watchdog is cleared manually
'
INCLUDE "Elapsed.bas" ‘modified to take a variable
'
' execution time!
'
'
percount var byte '
wrtcount var byte '
clkvalue var byte '
xdata var byte '
'oscfreq var word ‘this is declared in Elapsed Timer file
notreset var bit '
'
CMCON = 7 'set ports digital
trisb.4 = 0 'set led output
portb.4 = 0 '
'
percount = 0 '
clkvalue = 0 '
'
'
notreset = status.bit4 'check wdt reset occured - 0 is did reset
'
'
if notreset = 1 then 'was not reset by watchdog
portb.4 = 1 'turn led on
for percount = 0 to 255 'do eeprom writes until wdt reset
pause 100 '
write percount,$00 '
next percount '
makereset: 'failsafe to make reset occur
@ nop ;
goto makereset '
else 'was reset by watchdog
@ clrwdt ;clear the watchdog from now on
wrtcount = 0 'reset write counter
countwrites: 'count eeprom writes
read wrtcount,xdata 'read byte
@ clrwdt ;
pause 10 '
if xdata != $00 then '
goto donecount 'exit counting loop
endif '
wrtcount = wrtcount + 1 'increment count
goto countwrites '
donecount: '
for percount = 0 to 255 'erase the eeprom for next time
pause 10 '
@ clrwdt ;
write percount,$FF '
next percount '
endif '
'
'gosub flashout 'for testing only
'
oscfreq = 0 'reset oscillator frequency
'
if wrtcount > 8 then '11
oscfreq = $B1E7 'set oscillator frequency
endif '
if wrtcount > 18 then '21
oscfreq = $63C7 'set oscillator frequency
endif '
if wrtcount > 27 then '30
oscfreq = $15A7 'set oscillator frequency
endif '
'
'
gosub ResetTime 'reset time 00:00:00
gosub StartTimer 'start clock timer
'
'
'
cycle:
@ clrwdt
if Ticks > 49 then
portb.4 = 1
else
portb.4 = 0
endif
goto cycle
'
'
'
flashout: 'flash out the count of eeprom writes before wdt reset
for percount = 0 to wrtcount 'with the red led
portb.4 = 1 'flash rate will still depend on oscillator frequency
pause 250 'at this stage
@ clrwdt '
pause 350 '
@ clrwdt '
portb.4 = 0 '
pause 250 '
@ clrwdt '
pause 350 '
@ clrwdt '
next percount '
pause 500 '
@ clrwdt '
pause 500 '
@ clrwdt '
pause 500 '
@ clrwdt '
return ‘
'
Bookmarks