PDA

View Full Version : One works, one doesn't



RussMartin
- 17th March 2010, 04:17
This, on a 12F683 and PBP 2.47, works fine:



@ INT_ENABLE TMR1_INT ; Enable interrupt for timebase

CYCLE=0 : FLASH=16 : FLASH2=9 ' Initial values for "idle" condition

FOR INDEX=1 TO 525 ' Test for trigger status at startup
HIGH SLED ' Indicator is high during the test
IF TRIGR=0 THEN GOTO ESCAPE ' Trigger released exits the test
PAUSE 10 ' 10 ms X 525 iterations = 5 seconds
NEXT INDEX
ESCAPE: IF INDEX<2 THEN GOTO BFLAG ' Trigger not pressed, no mode change;
IF INDEX<525 THEN GOTO AFLAG ' held less than 5 seconds, change mode
MFLAG=1 ' If trigger has remained high for 5 or
GOTO NXTEST ' more seconds, set mode optional (1)

AFLAG: READ 255,MFLAG ' Get mode option flag from memory
IF MFLAG=0 THEN WRITE 255,1 ' If mode default, select optional (1)
IF MFLAG=1 THEN WRITE 255,0 ' If mode optional, restore default (0)
BFLAG: READ 255,MFLAG ' Get mode flag again in case it changed

NXTEST: READ 254,PFLAG ' Get data protect flag from memory
IF ACTIVE=0 THEN ' If held down at power-up, toggle flag
IF PFLAG=0 THEN WRITE 254,1 ' If data not protected, protect it (1)
IF PFLAG=1 THEN WRITE 254,0 ' If data is protected, unprotect it (0)
WHILE ACTIVE=0 ' Wait for the button to be released
ALED=1 ' and hold activity indicator on
WEND ' before continuing
PAUSE 105 ' Pause ~100 ms
ALED=0 ' Reset activity indicator
ENDIF
READ 254,PFLAG ' Get flag again in case it changed


This essentially identical fragment, on a 16F88 and PBP 2.60, does not:



@ INT_ENABLE TMR1_INT ; Enable the frame counter interrupt

GOSUB STARTTIMER ' Start the frame counter
' CHECK MEMORY PROTECTION
READ 254,PFLAG ' Get state of memory protection
IF PFLAG=1 THEN GOTO NXTEST ' If "on", skip mode select
' CHECK FOR "STRAPPED" INPUT
FOR INDEXW=1 TO 500 ' Test for TRIGGER status at startup
CTLIGHT=1 : ALIGHT2=1 ' Indicators are HIGH during the test
IF TRIGGER=0 THEN GOTO ESCAPE ' TRIGGER released exits the test
PAUSE 10 ' 10ms x 500 iterations = 5 seconds
NEXT INDEXW ' CHECK FOR MODE CHANGE
ESCAPE: CTLIGHT=0 : ALIGHT2=0 ' TRIGGER not on, no mode change; held
IF INDEXW<2 THEN GOTO BFLAG ' less than 5 seconds, change mode
IF INDEXW<500 THEN GOTO AFLAG ' If TRIGGER is HIGH for 5 or more
MFLAG=1 ' seconds, set mode to optional (1)
GOTO NXTEST
' TOGGLE MODE
AFLAG: READ 255,MFLAG ' Get state of mode option
IF MFLAG=0 THEN WRITE 255,1 ' If mode default, select optional (1)
IF MFLAG=1 THEN WRITE 255,0 ' If mode optional, restore default (0)
BFLAG: READ 255,MFLAG ' Get flag again in case it changed
' TOGGLE MEMORY PROTECTION
NXTEST: READ 254,PFLAG ' Get state of memory protection
IF ACTIVE1=0 THEN ' If held down at power-up, toggle flag
CTLIGHT=1
IF PFLAG=0 THEN WRITE 254,1 ' If data not protected, protect it (1)
IF PFLAG=1 THEN WRITE 254,0 ' If data protected, unprotect it (0)
WHILE ACTIVE1=0 ' Wait for CHAN1 to be released and
ALIGHT1=1 ' hold CHAN1 on before continuing
WEND
PAUSE 100
ALIGHT1=0 : CTLIGHT=0 ' Reset the indicators
ENDIF
READ 254,PFLAG ' Get flag again in case it changed


Since they are each at the head of much longer programs, I don't want to create clutter.

But it seems, no matter what, the FOR loop on the second never starts (the lights don't go on) and it continues with NXTEST--even when the preceding READ and IF are commented out! I've checked and rechecked so many times that I probably can't see the simple problem. I even used crude breakpoints (turn a LED on, pause 5 seconds, turn it off).

NXTEST works as it should. Both EEPROM locations are specified as "0" with DATA statements early in each program. I've looked at the EEPROM and the correct values are plugged in, but the value at 255 never changes; the one at 254 does. I even tried using 253 instead of 255. No change.

Am I going blind, or what?

RussMartin
- 17th March 2010, 05:59
Okay, fixed it myself.

I added a PAUSE 10 as shown.

But I surely do not know why the fix worked!



. . .
READ 254,PFLAG ' Get state of memory protection
IF PFLAG=1 THEN GOTO NXTEST ' If "on", skip mode select

PAUSE 10
' CHECK FOR "STRAPPED" INPUT
FOR INDEXW=1 TO 500 ' Test for TRIGGER status at startup
CTLIGHT=1 : ALIGHT2=1 ' Indicators are HIGH during the test
. . .

sayzer
- 17th March 2010, 08:05
Hi Russ,
For your EE location 255, I am guessing that your programmer does not read that location eventhough may be it is already there.