Stalled... Program will not enter Sub Routine
Zeus
Posts: 79
Hello All,
I am having with my program not recognizing the Alarm sub routine of my alarm clock program. I am sure that I am missing something obvious but I am too close to this to see my error. If anyone can point out where I am going wrong I would appreciate the help.
I have included the portions of the code that I thought applied. If I left anything out let me know. Also it is base on Chris Savages Digital Alarm Clock code.
Zeus
I am having with my program not recognizing the Alarm sub routine of my alarm clock program. I am sure that I am missing something obvious but I am too close to this to see my error. If anyone can point out where I am going wrong I would appreciate the help.
I have included the portions of the code that I thought applied. If I left anything out let me know. Also it is base on Chris Savages Digital Alarm Clock code.
Zeus
[/B] IF secs <> oldSecs THEN ' Next Second? oldSecs = secs ' Update Old Seconds GOSUB Show_Time ' Display Current Time/Status ENDIF IF AlarmSwitch = 0 THEN a1Status = 1 ELSE a1Status = 0 ENDIF IF (AlarmSwitch = 0) THEN DEBUG CR, "Alarm On" ELSE DEBUG CR, CLREOL ENDIF IF a1Status = 1 AND mins = AlmMins AND hrs = AlmHrs AND secs = $00 THEN GOSUB Alarm ' Activate Alarm Sequence Alarm: DEBUG BELL PAUSE 1000 DEBUG BELL oldSecs = secs DO GOSUB Get_Time IF INL <> $FF THEN Alarm_Exit LOOP UNTIL secs <> oldSecs oldSecs = secs DO GOSUB Get_Time IF INL <> $FF THEN Alarm_Exit LOOP UNTIL secs <> oldSecs Alarm_Exit: RETURN [B]
Comments
I have put a Debug BELL before and after the code where the alarm is supposed to trip and from that I confirmed that the program is indeed reaching that point in the program and then moving beyond and then finally looping. In short the clock works fine however the alarm portion is not functioning on any level.
Zeus
I understand what you are saying to a point however shouldn't the Debug BELL at least sound twice?
Zeus
In order to figure out the alarm function I simply have the alarm represented as a simple DEBUG BELL command for now, (see code above). I set the alarm time to a time in the very near future and the alarm time comes as goes yet no DEBUG BELL command sounds.
Does this help?
If you don't get the Alarm satisfied message when you expect it, uncomment the 1st DEBUG statement and see what's not what you expect.
I added you bit of code into my code and there was no change. The Debug window was constantly updating with data and as such did not provide any useful insight as to what the problem might ultimately be. I am unfamiliar with your code, specifically...
What was the intent and/or what were you expecting as the result?
Zeus
Zeus
There's an art to debugging that mostly has to do with forgetting that you wrote the program and looking at it as if you were new to the program and the task it's to accomplish. You insert DEBUG statements to trace through it, totest the various paths through the program that it takes and under what circumstances. You display the variables to ensure that their values are what you expect, assuming nothing. You may come up with test cases that will exercise the various functions of the program and reveal boundary cases.
Moving on... Taking a stab at you intent I added the following line to my code...
This confirmed that the four parameters are present right before the block of code is run which determines whether or not to enter the Alarm sub routine. Unfortunately no alarm sounded.
My immediate thought is that there is something early in the code which somehow locks out the remainder of the program from acting/seeing on the data?
I am at a loss here.
Zeus
How about tracing backwards from the GOSUB Alarm? ... putting in DEBUG statements to see what execution path the program is following?
IF a1Status = 1 AND mins = AlmMins AND hrs = AlmHrs AND secs = $00 THEN
GOSUB Alarm' Activate Alarm Sequence
ELSE
DEBUG BELL - sounded
ENDIF
There must be something simple that I am missing.
I'll take another stab at adding your code and see what happens.
Does anyone have any thoughts as to what I am missing here?
Zeus
IF (a1Status = 1) AND (mins = AlmMins) AND (hrs = AlmHrs) AND (secs = $00) THEN
'
You never gave me this much help back in the day, What gives!!!!!
'
What ever it is...
'
Merry Chirstmas...
Bell sounded, (multiple times oddly enough) but this is progress even though it is less than perfect. Also, it worked twice in a row and now it no longer sounds?! I have reloaded the code and currently it is not working, but regardless this is encouraging.
Funny thing is I tried containing each statements before and had no luck with the sub routine functioning.
Next I will try and move the alarm function to a dedicated sub routine function and work out the quirks.
Thanks again,
Zeus
I had a taste if success. I place brackets around each statement and the alarm actually sounded on two separate occasions. However after the second test I could not get it to work again. I made no changes to the code between trials.
Two things do not make sense to me. One I have placed the statements in brackets before and had no luck, so why this time and why intermittent performance? Also I noticed that my LCD was flickering prior to the first run. I am thinging that there may possibly be a power problem?