# Need a little help with program, nearly there.

#### David5093

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

#### Attachments

• 9.1 KB Views: 23
Last edited:

#### atferrari

Joined Jan 6, 2004
3,381
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.