![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| I need a litte help with picbasic. For the life of me I can not figure out break out of the first delay in my code until it has finished. Can someone take a look at my code and give me some suggestions? Thanks ahead. Steve DEVICE 12F629 CONFIG INTRC_OSC_NOCLKOUT,WDT_OFF,MCLRE_OFF,CP_OFF,BODEN_ ON XTAL 4 ALL_DIGITAL = TRUE TRISIO = %00001000 SYMBOL PIR = GPIO.3 SYMBOL BUZ = GPIO.2 CHECKIT: WHILE PIR <> 0 DELAYMS 60000 BUZ = 1 DELAYMS 500 BUZ = 0 WEND DELAYMS 3000 BUZ = 1 DELAYMS 1000 BUZ = 0 DELAYMS 3000 GOTO CHECKIT END | |
| |
| | (permalink) |
| I'm not don't know basic very well but it seems like you can add an IF statement with a GOTO to jump out of the loop. If you want to get out of the loop durring the DELAY I don't think there's a way to do that without rewriting the delay function. You might want to look into interrupts to solve this problem. Instead of delat you set up a timer interrupt to generate the appropreate delays. This lets your processor do something useful durring this time. Another technique that I use goes as follows (in pseudo code): while PIR <> 0 if done delaying buz = buz xor 1 //simple way to toggle BUZ do something useful here WEND each time through the loop it checks the timer to see if its done delaying. If its not done delaying then it does something else then goes back through the loop. Brent | |
| |
| | (permalink) |
| I am not sure what PICBASIC you are using... I don't think is the one from melabs But here is what I see.... the Delayms function will probably make the PIC sit there and wate time... and DO NOTHING! not even checking its inputs. So you are delaying for 600000ms that is 10 minutes, while the PIC sits there for 10 minutes, it will do nothing, nor respond to anything. IT wil jus SIT there. Then you will have some micoseconds after the BUZ = 1 to make sure that PIR is not 0. If it is a switch with the bouncing and all will miss your "window" and it then will go back to the 10 minutes waiting period of doing what?..... NOTHING Instead of delaying for 60000 with DELAYMS you should delay and check your inputs something like this: Code: WHILE PIR <> 0
For X = 0 to 60000
DELAYMS 1
If PIR <> 0 then EXITWEND
Next X
BUZ = 1
DELAYMS 500
BUZ = 0
WEND
EXITWEND: Ivancho | |
| |