To be fair, paste up your complete code as it is and then people can see what you want to do and hopefully post a corrected version for you. To ask for help and only post up cryptic bits of code makes it hard to provide the support you are seeking
To be fair, paste up your complete code as it is and then people can see what you want to do and hopefully post a corrected version for you. To ask for help and only post up cryptic bits of code makes it hard to provide the support you are seeking
Ok,I try modification this code:
and what I need,Code:switch var byte main: if portb.2 = 1 then switch = switch +1 If switch = 1 then goto program1 If switch = 2 then goto program2 If switch = 3 then goto program3 endif goto main program1: HIGH PORTB.1 PAUSE 500 LOW PORTB.1 PAUSE 500 GOTO program1 program2: HIGH PORTB.2 PAUSE 500 LOW PORTB.2 PAUSE 500 GOTO program2 program3: HIGH PORTB.3 PAUSE 500 LOW PORTB.3 PAUSE 500 GOTO program3
when I press button,JUST ONE TIME,TO, PORTB.2,
TO GO TO PROGRAM 1,
AND STILL WORKING IN THE PROGRAM 1.
when I press button,NEXT TIME,TO, PORTB.2,
TO GO TO PROGRAM 2,
AND STILL WORKING IN THE PROGRAM 2.
when I press button,NEXT TIME,TO, PORTB.2,
TO GO TO PROGRAM 3,
AND STILL WORKING IN THE PROGRAM 3,.......
THAT I NEED!!!
Long way, but possibly a fix is to incorporate the test for switch in each program
crude code, but may work (I've not tested as I'm at work)Code:main: if portb.2 = 1 then switch = switch +1 If switch = 1 then goto program1 If switch = 2 then goto program2 If switch = 3 then goto program3 endif goto main program1: HIGH PORTB.1 PAUSE 500 LOW PORTB.1 PAUSE 500 if portb.2 = 1 then switch = switch +1 If switch = 1 then goto program1 If switch = 2 then goto program2 If switch = 3 then goto program3 endif GOTO program1 program2: HIGH PORTB.2 PAUSE 500 LOW PORTB.2 PAUSE 500 if portb.2 = 1 then switch = switch +1 If switch = 1 then goto program1 If switch = 2 then goto program2 If switch = 3 then goto program3 endif GOTO program2 program3: HIGH PORTB.3 PAUSE 500 LOW PORTB.3 PAUSE 500 if portb.2 = 1 then switch = switch +1 If switch = 1 then goto program1 If switch = 2 then goto program2 If switch = 3 then goto program3 endif GOTO program3
Hello.
Please forgive me, but I'm still not sure what are you trying to do. What puzzles me most is PAUSE 500 because when a program is executing PAUSE it can't do anything else until the specified period expire (unless abrupted by interrupt). In your case, whenever the program hits PAUSE 500 it is just sitting there for the half of a second.
In my example the program is looping in MAIN waiting a key to be pressed (with some sort of debounce routine) and counting ~500ms ON/OFF time for the appropriate LED (it counts nothing until the key is pressed for the first time). After keypress it jumps to SWITCH_LED subroutine where it adjusts index (indx variable) to grab a value from the LOOKUP table in order to toggle an appropriate LED (that way I'm addresing a port by its number instead by its name), and then returns in main loop.
To change ports with attached LEDs you need to change values in LOOKUP table. You can use numbers 0-15 instead of port names, where 0 is portb.0, and 15 would be porta.7. However on 16F628 you can go as far as 12 (porta.4) or 13 (porta.5), depending whether you use external or internal oscillator. It's not same for all PICs. For example on 16F877 you can use full range of 0-15 because it spreads over portb and portc.if I like to change, which port I like to be low,of high,I mean because I like to make some ,to combinations of led,to high,or low,to I do it myself!
Hello.
First, I want to apologize for taking liberty to correct other people's code. In post no. 31 mr. Roger (flotulopex) accidentaly made a mistake:
Those colons marked red are surplus and that PAUSE 300 doesn't do any debounce here. It is simply executed immediately after the porta.2 goes low. The most simple way to verify that is to change pause to some larger value, e.g. 1000 (1 sec.) and apply very short (less than 1 sec.) push on button. What will happen is that LED will toggle its state after the pause no matter how shortly you kept the button pressed.Code:MAIN: IF PORTA.2 = 0 THEN <font color="red">PAUSE 300 'debounce</font> GOTO Program1<font color="red">:</font> ENDIF GOTO MAIN<font color="red">:</font> ...
If it was written like this:
On button-press the program would make a 300ms debounce-pause and then check again if button is still pressed and perceived if it was real button-press or just random noise.Code:IF PORTA.2 = 0 THEN PAUSE 300 IF PORTA.2 = 0 THEN Program1 ENDIF
Hi grinder,
Thanks for your corrections but there is sometimes an explanation behind "strange looking" code.
If you didn't tested this yet, do so and you will discover that the "debounce" will prevent the code to jump from the MAIN loop directly to the Program2 label; just try...and see by yourself
You're right, the colons are not necessary but this is just because I copy/paste the code instead of retyping it. BTW, this will make absolutely no change to the compiled code.
Dragan77 seems to be looking for a simple program made of simple commands for simple functionality; I'm not sure his application needs "complexity" up to using LOOKUP and so on.
Roger
Hello.
Mr. Roger (flotulopex), I apologize once more.
No need to test it, you're absolutely right about that. I made a mistake taking piece of your code out of the content. My intention was to explain that debouncing should represent a protection against random noise, beside inadvertently key presses. I'm really sorry, I didn't eplained that adequately.If you didn't tested this yet, do so and you will discover that the "debounce" will prevent the code to jump from the MAIN loop directly to the Program2 label; just try...and see by yourself
That's why I said that you accidentaly made a mistake.You're right, the colons are not necessary but this is just because I copy/paste the code instead of retyping it...
I beleive you're right about that as well. I put my example more as a probe to see if that's what mr. Dragan77 wants to achieve.Dragan77 seems to be looking for a simple program made of simple commands for simple functionality; I'm not sure his application needs "complexity" up to using LOOKUP and so on.
Bookmarks