Menu

Help With Loops

Ben Omlor
2025-03-04
2025-03-05
  • Ben Omlor

    Ben Omlor - 2025-03-04

    Hello,

    With the following test program, I have a switch hooked to C.4 the "sub ten" subroutine activates a ISD1416 voice chip to say 10.
    I expect that when I push the button it will get stuck in a loop saying 10 10 10 10 . but it does not, it seems to start the program over and I have to push the button again.
    I'm certain I'm missing something, but I can't seem to figure out what it is.

    thanks for any thoughts!

    chip 16f18345, 16

    option explicit

    dir portc.4 in
    wpuc4 = 1

    main:
    do

    if portc.4 = 0 then
    goto start
    end if

    loop

    start:
    do
    gosub ten
    loop

    sub ten
    wait 10 ms
    set porta.2 on
    set portc.0 on
    set portb.4 on
    set portb.5 on
    wait 3 ms
    set portc.7 off
    wait 600 ms
    set portc.7 on

    gosub reset

    end sub

    sub reset
    set porta.2 off
    set portc.0 off
    set portc.1 off
    set portc.2 off
    set portb.4 off
    set portb.5 off
    set portb.6 off
    set portb.7 off
    end sub

     
  • Anobium

    Anobium - 2025-03-05

    From a code perspective the loop ten (then reset) should be repeating.

    I suspect your reset routine to be incorrect. Examine that, does it need a/some wait()?

     
  • Ben Omlor

    Ben Omlor - 2025-03-05

    Once again you were spot on. It did not like the reset subroutine. I tried adding waits and pauses with no change. Turned out it did not like the name "reset" for the sub. I renamed the sub RST and now she works fine.

    So tip of the day, don't name a sub reset .

    As always thanks for your input!

    Ben

     
    • Anobium

      Anobium - 2025-03-05

      Of course reset is a reset on that chip.

      Well spotted.

      :-)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.