Need a little help with program, nearly there.

Discussion in 'Programmer's Corner' started by David5093, Jun 12, 2009.

  1. David5093

    Thread Starter Member

    Apr 23, 2009
    19
    0
    I have been writing a program that will goto the Pass routine if the sequence of buttons 4-2-3-1 is pressed, any deviation from this and the program will goto the Fail routine.

    The program works for the correct sequence, when i press 4-2-3-1 it goes to the Pass routine but there is a slight problem.

    The program starts and waits for 4 to be pressed, if 2, 3 or 1 are pressed at this point it goes to the Fail routine like i want. The only problem is that the program then waits for button 2 to be pressed and it doesn't matter what other buttons are pressed at this stage the program will not deviate to the fail routine as I would like, it waits and waits for button 2 to be pressed and then waits and waits for button 3 etc.

    Basically I think there is a small problem with subroutine SEQ_1, SEQ_2 and SEQ_3. I want the program to branch off to the Fail routine if the wrong button is pressed within these sub routines.

    Enclosed is the program, i'd appreciate any in-sight as to where the error lies.
     
    Last edited: Jun 12, 2009
  2. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,652
    768
    I would write a flow diagram. This kind of problem deserves it and allows you to solve the sequence and the decisions well before writing a single line of code.

    By the way, what is this good for?:

    MOVLW B'11010111' ;Set PIC options (See datasheet)

    Kind of funny. Have you read the datasheet?

    If so, write what is there for when revisiting the code...or for anyone like those here, trying to understand what you did.

    Doesn't this look better?

    Code ( (Unknown Language)):
    1.  
    2.   LOADREG PWMCON1,B'00000000'
    3.   ;                 0.......
    4.   ;                 .0......
    5.   ;                 ..0.....
    6.   ;                 ...0....  ;0000 =1:1 postscale
    7.   ;                 ....0...  ;SEVTDIR =0 trigger when counting upwards
    8.   ;                 .....0..  ;not implemented
    9.   ;                 ......0.  ;=0 DC & period buffer updates enabled.
    10.   ;                 .......0  ;=0 output override is asynchronous
    11.  
    Buena suerte.
     
  3. David5093

    Thread Starter Member

    Apr 23, 2009
    19
    0
    Yes I have and its nothing to worry about, just sets the watchdog timer off and sets up pre-scaling, nothing that will not make the program work. This program has been modified from an example that was given with an experiment board.

    Any ideas on how to branch off from the aforementioned sub-routines?
     
Loading...