PIC16F627 code issue, need some help

Thread Starter

David5093

Joined Apr 23, 2009
19
Thanks, i had a look at that code but can't see where it will help me, sorry. The problem is as follows:


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

gryskop

Joined Mar 1, 2008
26
Thanks, i had a look at that code but can't see where it will help me, sorry. The problem is as follows:


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.
This is what you've programmed

Rich (BB code):
		BTFSC	PORTA,SW4  ; Test if SW4 is pressed
		GOTO	SEQ_1      ; YES, now goto SEQ_1
		GOTO	MENU

SEQ_1		INCF 	PORTA,F		; Add 1 to PORT A
		MOVLW	D'10'		; Wait about 10mS
		CALL	NMSEC		; Call subroutine (NMSEC) 
		BTFSS	PORTA,SW2	; NOW YOUR LOOKING FOR SW2??? You should
wait for SW4 to be released!!
Remember, the SW4 button will still be pressed at this stage. There is no way
that a human can press and release a button in less than 10us
		GOTO	$-1		; Still low
		MOVLW	D'10'		; Wait about 10mS
		CALL	NMSEC		; Call subroutine (NMSEC)
		BTFSS	PORTA,SW2	; If set, still released
		GOTO	$-5		; Still low start release wait all over
You are waiting for SW2 to be pressed after SW4 was pressed. You should first finish the debounce of SW4 is SEQ_1/

Make SEQ_2 to debounce SW2,
SEQ_3 to debounce SW3 and ADD a SEQ_4 for SW1.

A computer is a funny thing. It does not know what you are thinking, it only does what you tell it to do (i.e. by means of a program), and that's exactly what you told this computer to do.
 

Thread Starter

David5093

Joined Apr 23, 2009
19
Yeah, i know I have programed it wrong but i don't know what changes to make and so need a little help, I take your point about the debouncing. At the moment, where I stand is that the program works as long as you put in the right sequence but it waits for this sequence only and will not goto the Failure routine should a button be pressed out of sequence.

It appears that the debouncing section is working but i don't know how to incorporate this for other buttons within the same sub routine
 
Last edited:

Thread Starter

David5093

Joined Apr 23, 2009
19
This is the latest code, i removed that MENU section but effectivley it works as before. It waits for a 4-2-3-1 then goes to the Pass routine. So far I can't seem to get it to goto the Fail routine if a button is pressed out of sequence.
 

Attachments

Top