![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hi again guys, due to all the previous help I now have a somewhat working program but it is doing something I can't figure out and am only a beginner with Pics. When I turn on I expected the program to wait until a button (up or down) was sent high ( I have internal pullups off and the pins pulled low on my dev board - EasyPic5) but the prog just runs through past the button command to the pulses and never stops. What am I doing wrong? I am using a 12F629 Pic btw, here is the code. program stepper992 main: DIM t as byte WPU = %00000000 'turn off weak pullups TRISIO =%00101000 'set GPIO 0,1,2,4 as out and 3,5 as inputs GPIO = %00000000 'turn off all outputs CMCON =0x07 'set comparator to off IF BUTTON(GPIO,5,1,0)then GOTO up 'check for button press for up END IF IF BUTTON(GPIO,3,1,0)then GOTO down 'check for button press for down END IF GOTO main 'if no presses then restart up: FOR t = 1 to 5 GPIO = %00010001 'Set on bits for this pulse delay_ms (110) GPIO = %00000011 'Set on bits for this pulse DELAY_MS (110) GPIO = %00000110 'Set on bits for this pulse delay_ms (110) GPIO = %00010100 'Set on bits for this pulse DELAY_MS (110) NEXT t GOTO main 'After completing pulses return to start down: FOR t = 1 to 5 GPIO = %00010100 'Set on bits for this pulse delay_ms (110) GPIO = %00000110 'Set on bits for this pulse DELAY_MS (110) GPIO = %00000011 'Set on bits for this pulse delay_ms (110) GPIO = %00010001 'Set on bits for this pulse DELAY_MS (110) NEXT t GOTO main 'After completing pulses return to start end. Thanks for looking........Al
__________________ Founder member of the Campaign to do Something about the nonexistent word "Somethink" | |
| |
| | #2 |
|
I don't know what the button function does and so can't comment. However, you could try something like if(GPIO&%00100000) instead of IF BUTTON(GPIO,5,1,0). I'm assuming that IF BUTTON(GPIO,5,1,0) reads a button on GPIO 5. As both your functions have delays there is no need for any debounce. Mike. | |
| |
| | #3 | |
| Quote:
I think the OP would want Code: main: DIM t as byte WPU = %00000000 'turn off weak pullups TRISIO =%00101000 'set GPIO 0,1,2,4 as out and 3,5 as inputs GPIO = %00000000 'turn off all outputs CMCON =0x07 'set comparator to off IF BUTTON(GPIO,5,0,1)then GOTO up 'check for button press for up END IF IF BUTTON(GPIO,3,0,1)then GOTO down 'check for button press for down END IF GOTO main 'if no presses then restart up: FOR t = 1 to 5 GPIO = %00010001 'Set on bits for this pulse delay_ms (110) GPIO = %00000011 'Set on bits for this pulse DELAY_MS (110) GPIO = %00000110 'Set on bits for this pulse delay_ms (110) GPIO = %00010100 'Set on bits for this pulse DELAY_MS (110) NEXT t GOTO main 'After completing pulses return to start down: FOR t = 1 to 5 GPIO = %00010100 'Set on bits for this pulse delay_ms (110) GPIO = %00000110 'Set on bits for this pulse DELAY_MS (110) GPIO = %00000011 'Set on bits for this pulse delay_ms (110) GPIO = %00010001 'Set on bits for this pulse DELAY_MS (110) NEXT t GOTO main 'After completing pulses return to start end. Last edited by be80be; 3rd October 2009 at 04:56 PM. | ||
| |
| | #4 |
|
He states that he has the pins pulled low. Mike. | |
| |
| | #5 |
|
If he has the pin pulled low and is looking for a low then of course it will run right through and not wait...
__________________ Mike2545 | |
| |
| | #6 |
|
If the button function checks for a transition then it should always stop. One of the reasons I don't use canned functions, normally quicker to write my own and that way, I know exactly what they do. Mike. | |
| |
| | #7 |
|
mike2524 that's what it was doing I think this is what the OP needs Code: IF BUTTON(GPIO,5,0,1)then GOTO up 'check for button press for up END IF IF BUTTON(GPIO,3,0,1)then GOTO down 'check for button press for down END IF Code: IF GPIO.B5 =1 then goto up
elseif GPIO.B3 =1 then goto down
endif
Last edited by be80be; 3rd October 2009 at 04:47 PM. Reason: Not thinking LOL | |
| |
| | #8 |
|
The Op is just testing for low state he needed to test for High state
| |
| |
| | #9 |
|
Hi again guys, I have tried ALL the suggestions but still no joy. Burt's code didn't compile as MB does not like the "GPIO.B3 = 1" until I removed the .B so there must be a difference in the software he is using. Even then with Burt's code modified it then ignored either button altogether. I have taken on board what was pointed out about the state bit and realised it should be BUTTON GPIO, 5,1,1 and not 5,1,0 as I had it, but still fails! I have noticed that if I remove the button reference to pin 3 then the program works fine, so I am beginning to wonder if its something to do with the MasterClear pin that I have missed? Should I have set that to anything particular? Thanks............Al
__________________ Founder member of the Campaign to do Something about the nonexistent word "Somethink" | |
| |
| | #10 |
|
Are you using MikroBasic or MikroBasic pro there not the same the pro you have more to set up + Last edited by be80be; 3rd October 2009 at 06:15 PM. | |
| |
| | #11 |
|
this is with microbasic pro Code: program steppertest ' Declarations section dim temp as word WPU = %00000000 'turn off weak pullups TRISIO =%00101000 'set GPIO 0,1,2,4 as out and 3,5 as inputs GPIO = %00000000 'turn off all outputs CMCON =0x07 'set comparator to off main: while true IF GPIO.5 =1 then GOTO up 'check for button press for up END IF IF GPIO.3 =1 then GOTO down 'check for button press for down END IF GOTO main 'if no presses then restart up: FOR temp = 1 to 5 GPIO = %00010001 'Set on bits for this pulse delay_ms (110) GPIO = %00000011 'Set on bits for this pulse DELAY_MS (110) GPIO = %00000110 'Set on bits for this pulse delay_ms (110) GPIO = %00010100 'Set on bits for this pulse DELAY_MS (110) NEXT temp GOTO main 'After completing pulses return to start down: FOR temp = 1 to 5 GPIO = %00010100 'Set on bits for this pulse delay_ms (110) GPIO = %00000110 'Set on bits for this pulse DELAY_MS (110) GPIO = %00000011 'Set on bits for this pulse delay_ms (110) GPIO = %00010001 'Set on bits for this pulse DELAY_MS (110) NEXT temp GOTO main 'After completing pulses return to start wend end Last edited by be80be; 3rd October 2009 at 06:57 PM. | |
| |
| | #12 | |
| Quote:
Its Mikrobasic mate, not pro, I didn't even know about the pro. Is it any better? Also I may have solved the problem! If I pull UP GPIO3 and pull DOWN GPIO5, then check for the opposite on button it seems to work! But if I pull BOTH UP or DOWN then the problem is back! Weird? So I am now baffled about something else then, but at least I can make up the circuit now eh. ![]() Al
__________________ Founder member of the Campaign to do Something about the nonexistent word "Somethink" | ||
| |
| | #13 |
|
Hang on folks! The switches seemed ok, in the fact that it didn't just run at first putting a high on 5 worked when it was tied to gnd and the button command was looking for a high. Problem is that putting a gnd on 3 even though it is pulled high does not start the pulses, even though I have 3 pulled high and I can see the relevant led on 3 going out and the button command is looking for a low. Even more baffled............Al
__________________ Founder member of the Campaign to do Something about the nonexistent word "Somethink" Last edited by bigal_scorpio; 3rd October 2009 at 07:59 PM. | |
| |
| | #14 |
|
Hi guys, Thanks for all the help, I've sorted it now! Migrated to a 16F630 and not a hitch! ![]() Shame though as Ithought the 12F629 had allI needed = 4 outputs and 2 inputs. Still wondering why it didn't work but never mind. Though if anyone does has a definitve answer I would still be interested. Thanks again........Al
__________________ Founder member of the Campaign to do Something about the nonexistent word "Somethink" | |
| |
| | #15 |
|
Did you turn mclr off you set it here
| |
| |
|
| Tags |
| mikrobasic, misbehaving, program |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Whats wrong with my program? MikroBasic | bigal_scorpio | Micro Controllers | 18 | 3rd October 2009 03:35 AM |
| Mikrobasic help.. | mramos1 | Micro Controllers | 11 | 12th November 2008 10:46 AM |
| mikroBasic compiler... | simrantogether | Micro Controllers | 3 | 27th October 2007 10:19 AM |
| mikroBasic and Proton | gramo | Micro Controllers | 0 | 17th March 2007 02:47 PM |