Need a little help with program, nearly there.

Thread Starter


Joined Apr 23, 2009
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:


Joined Jan 6, 2004
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?

Rich (BB code):
  LOADREG PWMCON1,B'00000000'
  ;                 0.......
  ;                 .0......
  ;                 ..0.....
  ;                 ...0....  ;0000 =1:1 postscale
  ;                 ....0...  ;SEVTDIR =0 trigger when counting upwards
  ;                 .....0..  ;not implemented
  ;                 ......0.  ;=0 DC & period buffer updates enabled.
  ;                 .......0  ;=0 output override is asynchronous
Buena suerte.

Thread Starter


Joined Apr 23, 2009
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?