Shop OBEX P1 Docs P2 Docs Learn Events
Stalled... Program will not enter Sub Routine — Parallax Forums

Stalled... Program will not enter Sub Routine

ZeusZeus Posts: 79
edited 2011-12-15 12:32 in BASIC Stamp
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

[/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

  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-11 15:26
    You really need to provide the whole program. It's not at all obvious what's wrong from the parts you've provided. You also need to define what you mean by "not recognizing the Alarm subroutine". What does work in your program and what doesn't work (what do you do in terms of switches and what do you see on a display?).
  • ZeusZeus Posts: 79
    edited 2011-12-11 17:00
    I really hate to post the whole thing and overwhelm everyone... but here it is.

    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

    [/B] 
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    ' 8 Active-Low Inputs Available On P9 - P15
    
    DataIO           PIN     0               ' DS1302.6/DS1620.1/MAX7219.1
    Clock             PIN     1               ' DS1302.7/DS1620.2/MAX7219.13
    DS1302          PIN     2               ' DS1302.5
    DS1620          PIN     3               ' DS1620.3
    MAX7219        PIN     4               ' MAX7219.12
    
    LCD                 PIN     6               ' LCD Display Output
    Speaker           PIN     7               ' Speaker Output
    AlarmSwitch     PIN     8               ' Alarm On/Off Switch
    
    
    ' -----[ Constants - DS1302 ]----------------------------------------------
    
    WrSecs          CON     $80             ' Write Seconds
    RdSecs          CON     $81             ' Read Seconds
    WrMins          CON     $82             ' Write Minutes
    RdMins          CON     $83             ' Read Minutes
    WrHrs            CON     $84             ' Write Hours
    RdHrs            CON     $85             ' Read Hours
    CWPr            CON     $8E             ' Write Protect Register
    WPr1             CON     $80             ' Set Write Protect
    WPr0             CON     $00             ' Clear Write Protect
    WrBurst         CON     $BE             ' Write Burst Of Data
    RdBurst         CON     $BF             ' Read Burst Of Data
    WrRam          CON     $C0             ' Write RAM Data
    RdRam          CON     $C1             ' Read RAM Data
    Hr24              CON     0               ' 24 Hour Mode
    Hr12              CON     1               ' 12 Hour Mode
    
    
    ' -----[ Constants - MAX7219 ]---------------------------------------------
    
    Decode          CON     $09             ' BCD Decode Register
    Brite           CON     $0A             ' Intensity Register
    Scan            CON     $0B             ' Scan Limit Register
    ShutDn          CON     $0C             ' Shutdown Register (1 = On)
    Test            CON     $0F             ' Display Test Mode
    DecPnt          CON     000000       ' Decimal Point
    Blank           CON     11           ' Blank A Digit
    
    ' -----[ Constants - DS1804 ]----------------------------------------------
    
    'Duration        CON     5               ' PULSOUT Duration For DS1804
    
    
    ' -----[ Constants - Other ]-----------------------------------------------
    
    Yes             CON     1               ' Yes Constant
    No              CON     0               ' No Constant
    
    IsOn            CON     1               ' On Constant
    IsOff            CON     0               ' Off Constant
    
    True             CON     1               ' True Constant
    False           CON     0               ' False Constant
    
    
    ' -----[ Variables - DS1302 ]----------------------------------------------
    
    oldSecs         VAR     Byte            ' Old Seconds
    secs              VAR     Byte            ' Seconds
    mins              VAR     Byte            ' Minutes
    hrs                VAR     Byte            ' Hours
    date              VAR     Byte            ' Date
    month            VAR     Byte            ' Month
    day               VAR     Nib             ' Day
    year              VAR     Byte            ' Year
    clockMode       VAR     hrs.BIT7        ' 12/24 Hour Mode Bit
    
    AlmMins         VAR     Byte            ' Defines "AlmMins" as a "Byte" sized variable.
    AlmHrs           VAR     Nib             ' Defines "AlmHrs" as a "Nib" sized variable.
    
    flags              VAR     Byte            ' Alarm Flags
    a1Status        VAR     flags.BIT0      ' Alarm 1 Status Flag
    TimeAmPm     VAR     flags.BIT2      ' Time Am/Pm Flag: 0 = AM, 1 = PM
    tripFlag2         VAR     flags.BIT3      ' Unassigned
    dimAct           VAR     flags.BIT4      ' Unassigned
    dimFlag          VAR     flags.BIT5      ' Dimmer Flag 1 = Dim, 0 = Bright
    dimming         VAR     flags.BIT6      ' Dimming Enabled? 1 = Yes, 0 = No
    valid               VAR     flags.BIT7      ' RTC RAM Valid? 1 = Yes, 0 = No
    
      'My Variables
    
    MenuNum         VAR     Nib             ' Defines "MenuNum" as a "Nib" sized variable.
    MenuText          VAR     Byte            ' Defines "MenuText" as a "Byte" sized variable.
    Text                  VAR     Byte            ' Defines "Text" as a "Byte" sized variable.
    AlarmAmPm      VAR     Bit             ' Defines "AlarmAmPm" as a "Bit" sized variable, Alarm Am/Pm Flag: 0 = AM, 1 = PM
    Snooze             VAR     Byte            ' Defines "Snooze" as a "Byte" sized variable.
    LCDOut            VAR     Byte            ' Defines "LCDOut" as a "Byte" sized variable, used for backlight timer.
    AlarmOnOff        VAR     Bit             ' Defines "AlarmOnOff" as a "Bit" sized variable.
    
    ' -----[ Variables - MAX7219 ]---------------------------------------------
    
    d7219           VAR     Byte            ' Data For MAX7219
    dSet             VAR     Nib             ' Dimmer Level Setting
    
    
    ' -----[ Variables - Other ]-----------------------------------------------
    
    index           VAR     Byte            ' Loop Counter
    idxOdd         VAR     index.BIT0      ' Is Index Odd? (1 = Yes)
    ioByte          VAR     Byte            ' Data To/From Devices
    work            VAR     Byte            ' Work Data (Temp Variable)
    
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    Defaults:       DATA    $30, $06, $30, $07, $00, $21, $55, $05, $02, $C3
    
      'My EEPROM DATA
    
    AlarmHr                 DATA "Set ALARM Hours", 0
    AlarmMin               DATA "Set ALARM Minutes", 0
    AmPmAlarm          DATA "Set ALARM AM/PM", 0
    Snooze5                DATA "Set Snooze", 0
    empty                   DATA "Empty", 0
    
    
    ' -----[ Initialization - DS1302 ]-----------------------------------------
    
      GOSUB Get_RAM                         ' Initialize DS1302
    
    ' -----[ Initialization of Variables ]-------------------------------------
    
      MenuNum = 0
      AlmHrs = 6
      AlmMins = 30
      Snooze = 15
    
    ' -----[ Initialization - MAX7219 ]----------------------------------------
    
      GOSUB Display_Test                    ' For Debugging Purposes
    
      FOR index = 0 TO 7                    ' 4 Registers & 4 Values
        LOOKUP index, [Scan, 5, Brite, 1, Decode, $FF, ShutDn, 1], ioByte
        SHIFTOUT DataIO, Clock, MSBFIRST, [ioByte]
        IF (idxOdd = No) THEN No_Load       ' Wait For Value To Be Shifted
        PULSOUT MAX7219, 5
    
    No_Load:
      NEXT
    
    ' -----[ Initialization - LCD ]----------------------------------------
    
      SEROUT LCD, 84, [22, 12]         'Assigns Pin 6 as LCD output, 84 establishes BAUD rate, 22 turns on LCD, 12 clears LCD.
      PAUSE 5                          '"Pause 5" required for "12" command above.
    
    ' -----[ Initialization - DS1804 ]-----------------------------------------
    
    '  GOSUB Reset_Volume                    ' Make Sure Volume Is Down
    
    
    ' -----[ Initialization - Other ]------------------------------------------
    
      'GOSUB Dimmer                          ' Restore Dimming State
    
    
    ' -----[ Program Code - Main Loop ]----------------------------------------
    
    Start:
      DO
    
        IF (IN12 = 0) OR (IN13 = 0) OR (IN14 = 0) OR (IN15 = 0) THEN 'If any BUTTON INPUT is detected the program enters the "Buttons_Sub" sub routine,
        GOSUB Buttons_Sub
        ENDIF
    
        GOSUB Get_Time                      ' Get Date/Time Data From DS1302
    
        DEBUG HOME, "Time: ", HEX hrs, ":", HEX2 mins, 9, HEX2 secs, 9, ? TimeAmPm
        DEBUG "Alarm: ", DEC2 AlmHrs, ":", DEC2 AlmMins, 9, ? AlarmAmPm
        DEBUG ? a1Status
        'DEBUG CR, HEX2 d1Hrs, ":", HEX2 d1Mins, CR, DEC dSet, CR, BIN flags, CR, BIN8 INL
    
        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
    
        ENDIF
    
        DEBUG CR, DEC2 ?  LCDOut
        LCDOut = LCDOut + 1             'Adds one to LCDOut counter.
          IF LCDOut > 30 THEN           'End of nested "Do Loop", scanning for button inputs (Backlight Timer).
          LCDOut = 0
          SEROUT LCD, 84, [18]           'Assigns Pin 6 as LCD output, 84 establishes BAUD rate, 18 turns LCD Backlight Off.
          'PAUSE 600                          'Pauses for 6 sec. before shutting off LCD.
          SEROUT LCD, 84, [21]           'Command to Shut Off LCD.
    
        ENDIF
    
      LOOP                                  'End of Loop. Sends program back to "Do" statement.
    
    
    ' -----[ Subroutines - DS1302 ]--------------------------------------------
    
    Set_RAM:
      index = CWPr                          ' Write Protect Register
      ioByte = WPr0                         ' Clear Write Protect
      GOSUB RTC_Out                     ' Send Command
    
      ioByte = 0                                       ' Address Of Alarm 1 Minutes
      index = WrRam | (ioByte << 1)         ' Write RAM Mode + Address
      ioByte = AlmMins                            ' Set Alarm 1 Minutes
      GOSUB RTC_Out                            ' Write Value
    
      ioByte = 1                                       ' Address Of Alarm 1 Hours
      index = WrRam | (ioByte << 1)         ' Write RAM Mode + Address
      ioByte = AlmHrs                              ' Set Alarm 1 Hours
      GOSUB RTC_Out                            ' Write Value
    
      ioByte = 9                                        ' Address Of Flags
      index = WrRam | (ioByte << 1)         ' Write RAM Mode + Address
      ioByte = flags                                  ' Set Flags
      GOSUB RTC_Out                            ' Write Value
    
      index = CWPr                                 ' Write Protect Register
      ioByte = WPr1                                ' Set Write Protect
      GOSUB RTC_Out                           ' Send Command
      RETURN
    
    Get_RAM:
      index = CWPr                              ' Write Protect Register
      ioByte = WPr1                              ' Set Write Protect
      GOSUB RTC_Out                         ' Send Command
    
      ioByte = 0                                       ' Address Of Alarm 1 Minutes
      index = RdRam | (ioByte << 1)         ' Read RAM Mode + Address
      GOSUB RTC_In                               ' Get Value
      AlmMins = ioByte                             ' Restore Alarm 1 Minutes
    
      ioByte = 1                                       ' Address Of Alarm 1 Hours
      index = RdRam | (ioByte << 1)         ' Read RAM Mode + Address
      GOSUB RTC_In                               ' Get Value
      AlmHrs = ioByte                               ' Restore Alarm 1 Hours
    
      ioByte = 9                                      ' Address Of Flags
      index = RdRam | (ioByte << 1)         ' Read RAM Mode + Address
      GOSUB RTC_In                               ' Get Value
      flags = ioByte                                 ' Restore Flags
      RETURN
    
    RTC_Out:
      HIGH DS1302                           ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [index, ioByte]
      LOW DS1302                            ' Deselect DS1302
      RETURN
    
    RTC_In:
      HIGH DS1302                                            ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [index]
      SHIFTIN DataIO, Clock, LSBPRE, [ioByte]
      LOW DS1302                                             ' Deselect DS1302
      RETURN
    
    Set_Time:                                                ' DS1302 Burst Write
      HIGH DS1302                                         ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [WrBurst]
      SHIFTOUT DataIO, Clock, LSBFIRST, [secs, mins, hrs,
        date, month, day, year, 0]                      ' Part Of Previous Line
      LOW DS1302                                          ' Deselect DS1302
      RETURN
    
    Get_Time:                                                    ' DS1302 Burst Read
      HIGH DS1302                                              ' Select DS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [RdBurst]
      SHIFTIN DataIO, Clock, LSBPRE, [secs, mins, hrs, date, month, day, year]
      LOW DS1302                                                 ' Deselect DS1302
      clockMode = 0                                                ' Clear BIT7
      IF hrs > $11 THEN                                           ' AM/PM?
        TimeAmPm = 1                                              ' PM
      ELSE
        TimeAmPm = 0                                                ' AM
      ENDIF
      RETURN
    
    
    ' -----[ Subroutines - MAX7219 ]-------------------------------------------
    
    Show_Time:
    
      index = 1                                                       ' Set First Digit (Minutes)
      ioByte = mins.LOWNIB                                   ' Minutes Lower Digit
      IF TimeAmPm = 1 THEN ioByte = ioByte | DecPnt
      GOSUB Max_Out                                          ' Send To Display
    
      index = 2                                                       ' Set Second Digit (Minutes)
      ioByte = mins.HIGHNIB                                   ' Minutes Upper Digit
      IF TimeAmPm = 0 THEN ioByte = ioByte | DecPnt
      GOSUB Max_Out                                              ' Send To Display
    
      work = hrs                                                          ' Store Hours In Temp Variable
    
      IF work > $12 THEN
        work = (work.NIB1 * 10) + work.NIB0 ' BCD To Decimal
        work = work - 12                    ' Remove 24 Hour Offset
        work = (work / 10 << 4) + (Work // 10) ' Decimal To BCD
      ELSEIF work = $00 THEN                                        ' Midnight Adjustment
        work = $12
      ENDIF
    
      index = 3                             ' Set Third Digit
      ioByte = work.LOWNIB | DecPnt         ' Hours Lower Digit/DP (Colon)
      GOSUB Max_Out                         ' Send To Display
    
      index = 4                                                           ' Set Fourth Digit
      ioByte = Blank                                                  ' Pre-Blank Digit
      IF work.HIGHNIB <> $00 THEN ioByte = work.HIGHNIB ' If Not 0 Set
      ioByte = ioByte | DecPnt                                 ' Enable Decimal Point (Colon)
      GOSUB Max_Out                                               ' Send To Display
    
      index = 6                                                         '  Set Sixth Digit (DP)
      ioByte = Blank                                                 ' Pre-Blank
      IF a1Status = 1 THEN ioByte = ioByte | DecPnt ' Enable DP If 1
      GOSUB Max_Out                                            ' Send To Display
    
      RETURN
    
    Display_Test:
      index = Test                                                ' Select Display Test Register
      ioByte = 1                                                   ' Set Display Test Mode
      GOSUB Max_Out                                        ' Send To Display
    
      PAUSE 2000                                                ' Wait For 2 Seconds
    
      index = Test                                                  ' Select Display Test Register
      ioByte = 0                                                     ' Clear Display Test Mode
      GOSUB Max_Out                                            ' Send To Display
      RETURN
    
    Max_Out:
      SHIFTOUT DataIO, Clock, MSBFIRST, [index, ioByte]
      PULSOUT MAX7219, 5                                   ' Latch Data
      RETURN
    
    ' -----[ Subroutines - Alarms ]--------------------------------------------
    
    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
      'NEXT
    
    Alarm_Exit:
      RETURN
    
    ' -----[ Subroutines - Snooze_Sub ]--------------------------------------------
    
    'Insert snooze subroutin here.
    
    '________________Sub Routines
    
    Buttons_Sub:                          ' Start of Sub Routine.
    
    'Menu Number Buttons Block
      IF (IN14 = 0) AND (IN15 = 0) THEN              ' Start of "If" statement which adresses both buttons being presses.
        MenuNum = 0                                           ' If above statement is true "MenuNum" is set equal to zero.
      ELSEIF (IN14 = 0) THEN                              ' Begining of "If" Statement which adds 1 from "MenuNum" variable.
        MenuNum = MenuNum + 1                          ' If above condition is true, adds 1 from "MenuNum" variable.
      ELSEIF (IN15 = 0) THEN                               ' Begining of "If" Statement which subtracts 1 from "MenuNum" variable.
        MenuNum = MenuNum - 1                           ' If above condition is true, subtracts 1 from "MenuNum" variable.
      ENDIF                                                           ' End of "IF" statement.
    
    'Alarm Hour Buttons Block
    IF (MenuNum = 0) THEN
    
      SELECT IND & 3                             ' Start of "Select Case" statement, possibilities are 00, 01, 10 and 11.
        CASE = 0                                      ' Case 3, both buttons pressed... Reset
          AlmHrs = 6                                    ' If both buttons are pressed alarm hours set TO 6.
          AlarmAmPm = 0
          AlmMins = 0
        CASE = 1                                           ' Case 2, one button is pressed... advance 1.
           AlmHrs = AlmHrs + 1
            IF AlmHrs = 13 THEN AlmHrs = 1   ' Starts variable counting over at "12" if value is less than "1".
        CASE = 2                                          ' Case 1, other button is pressed... subtract 1.
          AlmHrs = AlmHrs - 1
            IF AlmHrs = 0 THEN AlmHrs = 12    ' Starts variable counting over at "1" if value is greater than "12".
      ENDSELECT
    
    ENDIF
    
    
    ' Alarm Minutes Buttons Block
    IF (MenuNum = 1) THEN
    
      SELECT IND & 3                                ' Possibilities are 00, 01, 10 and 11.
        CASE = 0
          AlmMins = 0                                   ' Reset to Zero
        CASE = 1
          AlmMins = AlmMins + 1 // 60          ' Count up mod 60 using // operator
        CASE = 2
          AlmMins = AlmMins - 1 MAX 59       ' Count down mod 60, return to 59 when value becomes 255
    
      ENDSELECT
    
    ENDIF
    
    'Am/Pm Buttons Block                    
    IF (MenuNum = 2) THEN
    
      SELECT IND & 3                                    ' Possibilities are 00, 01, and 10.
        CASE = 0
          DEBUG CR, "Test"
        CASE = 1
          AlarmAmPm = AlarmAmPm + 1 MAX 1
        CASE = 2
          AlarmAmPm = AlarmAmPm - 1 MAX 0
          'AlarmAmPm = AlarmAmPm - 1 // 2
    
      ENDSELECT
    
    ENDIF
    
    ' Snooze Duration (+/- 5 Minutes) Buttons Block
    IF (MenuNum = 3) THEN
    
      SELECT IND & 3                             ' Possibilities are 00, 01, 10 and 11.
        CASE = 0                                     ' Reset
          Snooze = 15
        CASE = 1                                     ' Count up mod 60 using // operator
          Snooze = Snooze + 5
            IF Snooze = 60 THEN Snooze = 10
        CASE = 2                                      ' Count down mod 60, return to 59 when value becomes 255
          Snooze = Snooze - 5
            IF Snooze = 5 THEN Snooze = 55
      ENDSELECT
    
    ENDIF
    
    GOSUB Display_Sub
    
    RETURN
    
    
    Display_Sub:
    
      'DEBUG HOME                                                    ' Returns cursor to "Home" postion.
      SEROUT LCD, 84, [12]                                          ' Assigns Pin 6 as LCD output, 84 establishes BAUD rate, 12 clears LCD.
    
    LOOKUP MenuNum, [AlarmHr, AlarmMin, AmPmAlarm, Snooze5, empty , empty , empty , empty , empty , empty , empty , empty , empty , empty , empty , empty], MenuText
    DO                                 ' Start of MenuText Display "Do" loop
    
      READ MenuText, Text                                             ' Reads current MenuText from Lookup table and stores it to "Storage" variable.
      MenuText = MenuText + 1
      IF (Text = 0) THEN EXIT
      'DEBUG CLREOL, Text                                           ' "CLREOL" format command clears everything to right of cursor before displaying "Storage".
      SEROUT LCD, 84, [22, 17, Text]                               ' Assigns Pin 6 as LCD output, 84 establishes BAUD rate, 17 turns on Back Light.
    
    LOOP                                                                      ' End of MenuText Display "Do" loop
    
      'DEBUG CR, CLREOL, ? AlmHrs
        SEROUT LCD, 84, [CR, DEC AlmHrs]                      ' Assigns Pin 6 as LCD output, 84 establishes BAUD rate, displays AlarmHrs value on 2nd line LCD.
      'DEBUG CLREOL, ? AlarmMins
        SEROUT LCD, 84, [":", DEC2 AlmMins]                    ' Assigns Pin 6 as LCD output, 84 establishes BAUD rate, displays ":" on 2nd line of LCD.
    
        IF (AlarmAmPm = 0) THEN                                      ' Start of "If Then" statement which detrmines Am/Pm display.
        'DEBUG "AM"
          SEROUT LCD, 84, [9, "AM"]                                    ' Assigns PIN 6 as LCD OUTPUT, 84 establishes BAUD rate, displays "AM" ON 2nd line of LCD.
        ELSE
        'DEBUG "PM"
          SEROUT LCD, 84, [9, "PM"]                                    ' Assigns PIN 6 as LCD OUTPUT, 84 establishes BAUD rate, displays "PM" ON 2nd line of LCD.
        ENDIF                                                                      ' End of "If Then" statement which detrmines Am/Pm display.
    
        IF (AlarmSwitch = 0) THEN                                         ' Modify code so that this continually updates the On/Off Alarm state.
          SEROUT LCD, 84,  [9, "-Alarm On-"]
            ENDIF
    
      'DEBUG CR, ? Snooze
        SEROUT LCD, 84, [CR, DEC2 Snooze, 9, "Minute Snooze"]     ' Assigns Pin 6 as LCD output, 84 establishes BAUD rate, displays Snooze value on 3rd line of LCD.
        LCDOut = 0
    
    RETURN
    [B]
    
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-11 18:20
    You've got an IF INL <> $FF THEN Alarm_Exit in each loop. This tests I/O pins 0-7 and, if any of these are low, the Alarm routine exits. In addition to testing I/O pins set to input mode, it also checks I/O pins set to output mode. I suspect one or more output bits are set to low, so the Alarm routine always exits. I don't understand why you're doing this, but that's probably why your program is behaving the way it is.
  • ZeusZeus Posts: 79
    edited 2011-12-11 18:54
    Thanks for the replies Mike,

    I understand what you are saying to a point however shouldn't the Debug BELL at least sound twice?

    Zeus
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-11 19:29
    I thought you said that the Debug BELL sounded proving that the program reached the Alarm routine. If not, what did happen? It really helps if you're precise in describing what happened and under what circumstances.
  • ZeusZeus Posts: 79
    edited 2011-12-11 20:33
    I placed a DEBUG BELL statement before and after the point in the main body where the code decides to enter the alarm sub routine, and the speaker sounded. This tells me that the main body looping correctly as is also evident by the fact that the clock keeps updating the time.

    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?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-11 21:14
    I don't have the parts to set up something like your system, so I can't test it. The following is the only place I can see a call to Alarm and you should try it with debug messages as shown in the 2nd sample:
    IF a1Status = 1 AND mins = AlmMins AND hrs = AlmHrs AND secs = $00 THEN
          GOSUB Alarm                       ' Activate Alarm Sequence
        ENDIF
    
    '   DEBUG "Alm Test: ",a1Status," ",mins," ",AlmMins," ",hrs," ",AlmHrs," ",secs,CR
        IF a1Status = 1 AND mins = AlmMins AND hrs = AlmHrs AND secs = $00 THEN
          DEBUG "Alarm satisfied",CR
          GOSUB Alarm                       ' Activate Alarm Sequence
          DEBUG "Alarm exited",CR
        ENDIF
    

    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.
  • ZeusZeus Posts: 79
    edited 2011-12-12 15:46
    Mike,

    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...
    DEBUG "Alm Test: ",a1Status," ",mins," ",AlmMins," ",hrs," ",AlmHrs," ",secs,CR
    
    
    
    
    
    What was the intent and/or what were you expecting as the result?

    Zeus
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-12 16:18
    If your code is not calling the Alarm subroutine, the question is why. You're assuming that certain things are true. The purpose of this DEBUG statement is to show all the factors involved since one or more of them are not behaving the way you expect them to. If you can see the wrong values, you can begin to trace backwards in your program's logic to see where and why. Program bugs are not magic. Your Stamp is behaving the way Stamps are supposed to behave. Don't expect that there is some error in the Stamp interpreter or in the Stamp Editor. It's been many years since any of those have been found and corrected. There's something about your program that's wrong and you have to start with whatever observations you have and work backward and forward from that, looking at variable values, putting in DEBUG statements as you've started to do to see where the program has gotten to.
  • ZeusZeus Posts: 79
    edited 2011-12-12 16:55
    One more question for you Mike... What exactly leads you to believe that I am blaming the hardware for my coding error?

    Zeus
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-12 21:15
    I think I just wanted to cut that line of thinking off. I've provided several people with answers recently where they've taken posted sample programs, tried them, sometimes with changes, and were puzzled why they didn't work. Commonly the problem lies with the power source or the changes they've made. There have been cases of faulty Stamps or faulty boards or Stamps inserted in reverse or other such, but overwhelmingly the problem is something that step by step debugging can uncover.

    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.
  • ZeusZeus Posts: 79
    edited 2011-12-13 14:59
    Well played Mike.

    Moving on... Taking a stab at you intent I added the following line to my code...
    DEBUG HOME, HEX hrs, ":", HEX2 mins, ":", HEX2 secs, 9, ? a1Status      'This is the line of code mentioned above
        
    IF a1Status = 1 AND mins = AlmMins AND hrs = AlmHrs AND secs = $00 THEN
          GOSUB Alarm                       ' Activate Alarm Sequence
    

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-13 15:52
    If the values displayed in the DEBUG statement are correct, the IF statement should execute, thus the GOSUB will be executed. In the Alarm subroutine, the DEBUG statements will execute before anything else is done. It's possible that the PC terminal program is ignoring the BELL character. There isn't anything that can "lock out" the rest of the program. Either the DEBUG statement executes or it doesn't. Either the displayed values are correct, thus the IF statement will succeed or they're not correct which would explain why the GOSUB doesn't execute. There is no magic involved.

    How about tracing backwards from the GOSUB Alarm? ... putting in DEBUG statements to see what execution path the program is following?
  • ZeusZeus Posts: 79
    edited 2011-12-13 17:57
    I added the DEBUG BELL statement to the body of the statement (below) and the bell sounded. This proves that the statement is being processed at least partially but yet the Alarm sub routing is still not executing.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-13 18:00
    The way you've written the DEBUG statement, it sounds the BELL if the IF statement fails, not if it succeeds. The IF statement is going to fail most of the time since the alarm is disabled or the time is wrong most of the time. Look at my post #8 to see what you need to test the IF statement.
  • ZeusZeus Posts: 79
    edited 2011-12-13 19:29
    Yes, that was intentional. I wanted to verify that the program was at least entering the statement as I was starting to wonder if the statement was being bypassed all together. Since I am unable to verify the positive condition I then chose to verify the negative.

    I'll take another stab at adding your code and see what happens.
  • ZeusZeus Posts: 79
    edited 2011-12-14 17:50
    So I modified the code to look/sound for the positive case (below) and no bell. This code completely removed the sub routine from the equation.
        DEBUG HOME, HEX hrs, ":", HEX2 mins, ":", HEX2 secs, 9, ? a1Status
    
        IF a1Status = 1 AND mins = AlmMins AND hrs = AlmHrs AND secs = $00 THEN
         DEBUG BELL
    
        ENDIF
    

    Does anyone have any thoughts as to what I am missing here?

    Zeus
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-14 17:55
    Try putting parentheses around the expression terms like

    IF (a1Status = 1) AND (mins = AlmMins) AND (hrs = AlmHrs) AND (secs = $00) THEN
  • $WMc%$WMc% Posts: 1,884
    edited 2011-12-14 18:10
    Mr.Green:
    '
    You never gave me this much help back in the day, What gives!!!!!
    '
    What ever it is...
    '
    Merry Chirstmas...
  • ZeusZeus Posts: 79
    edited 2011-12-14 18:24
    Thank you Mike,

    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
  • ZeusZeus Posts: 79
    edited 2011-12-15 12:32
    I am not sure why my reply from last night did not post but here goes...
    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?
Sign In or Register to comment.