help in programming needed.

klz

New Member
Hi,

I'm using a 28X picaxe board. I need to design a program to control the motors through relays.

PROGRAM:
Inputs: pin0 is for ON/OFF purpose
pin1 is for sequence purpose
Outputs: high/low 0 and high/low1 (temporary use on LEDs on the board to see the different sequence)
label_1E: 1st sequence
label_25: 2nd sequence
label_9B: 3rd sequence
label_CF: return to 1st sequence

When input pin0 is pressed then 1st sequence is executed. Then, when the sequence1 is interrupted by the pin1 button. It will jump to the interrupt program and return back to the point it was interrupted after the interrpt program is executed. So everytime the pin1 is pressed, it will change sequence.

PROBLEM: I do not how to program the program such that when the pin0 (ON/OFF) is pressed then the currently whole program will stop until the pin0 is pressed again the next time. Can use another interrupt for the ON/OFF?

HELP!!!


Code:
'BASIC converted from flowchart: 
'C:\DOCUMENTS AND SETTINGS\STUDENT\DESKTOP\MM.CAD
'Converted on 9/20/2007 at 13:59:23


setint %00000000,%00000010

main:
label_6: if pin0=1 then label_6

label_1E:            high 0                      
                        wait 5
                        low 0
                        wait 5
                        if b1=0 then label_1E

label_25:            high 1
                        wait 1
                        low 1
                        wait 1
                        if b1=1 then label_25

label_9B:            high 0
                        wait 1
                        low 0
                        wait 1
                        if b1=2 then label_9B

label_CF:            let b1=0
                        goto label_1E

interrupt:            b1 = b1 + 1       
                        pause 2000
                        setint %00000000,%00000010
                        return

Thank you.
 
Last edited by a moderator:

Technical

Technical Support
Staff member
Something like this may help. Note the switch will only be read once per loop.

Code:
setint %00000000,%00000010

main:
label_6: if pin0=1 then label_6

label_1E:            high 0                      
                        wait 5
                        low 0
                        wait 5
                        if pin0=0 then reset_it
                        if b1=0 then label_1E

label_25:            high 1
                        wait 1
                        low 1
                        wait 1
                        if pin0=0 then reset_it
                        if b1=1 then label_25

label_9B:            high 0
                        wait 1
                        low 0
                        wait 1
                        if pin0=0 then reset_it
                        if b1=2 then label_9B

label_CF:            let b1=0
                        goto label_1E

interrupt:            b1 = b1 + 1       
                        pause 2000
                        setint %00000000,%00000010
                        return

reset_it:            ; wait until switch released again
                        pause 10
                        if pin0=0 then reset_it
                       ; switch has now been released
                       ; wait 10ms to debounce switch
                       ; then loop back to start
                        pause 10
                        goto main
 

klz

New Member
Something like this may help. Note the switch will only be read once per loop.

Code:
setint %00000000,%00000010

main:
label_6: if pin0=1 then label_6

label_1E:            high 0                      
                        wait 5
                        low 0
                        wait 5
                        if pin0=0 then reset_it
                        if b1=0 then label_1E

label_25:            high 1
                        wait 1
                        low 1
                        wait 1
                        if pin0=0 then reset_it
                        if b1=1 then label_25

label_9B:            high 0
                        wait 1
                        low 0
                        wait 1
                        if pin0=0 then reset_it
                        if b1=2 then label_9B

label_CF:            let b1=0
                        goto label_1E

interrupt:            b1 = b1 + 1       
                        pause 2000
                        setint %00000000,%00000010
                        return

reset_it:            ; wait until switch released again
                        pause 10
                        if pin0=0 then reset_it
                       ; switch has now been released
                       ; wait 10ms to debounce switch
                       ; then loop back to start
                        pause 10
                        goto main
Hi.

Is there another faster way to check whether the ON/OFF switch is pressed? Because if the period of 1 loop is 10 secs then I have to catch the exact time the loop finishes and pressed the switch at the same moment for the program to work.

label_1E: high 0
wait 5
low 0
wait 5
if pin0=0 then reset_it
if b1=0 then label_1E
 
Last edited:

Technical

Technical Support
Staff member
The waits can be broken down into smaller delays e.g 'wait 5' can become

Code:
for w5 = 1 to 500 
if pin0=0 then reset_it
pause 10
next w5
This will check the switch every 10ms. Remember to use a word variable if the number of for...next loops > 255
 
Top