![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Help I am trying to write some basic code for a 12f629. What im trying to do is have the micro check for a input on a pin. If there is no input for 15 min are so then trigger a short output on another pin. My problum is that while it is in the 15 min. delay it will not check for a input untill it finishes the loop. Any suggestions? I tried the "WHILE" and "Else" commands Im using Proton Plus Thanks Steve | |
| |
| | #2 |
|
I dunno BASIC but you might need to change the logic of your program... What do you mean with "input on a pin"? A change in level or a short pulse like from a button? If your uC supports interrupts you should set one up to be triggered when there is "input on a pin", then add a global var input = 0 and when the interrupt is triggered you set input = 1 Then you change your loop to periodically check for input = 1,... like this: Code: BYTE input = 0
sub input_interrupt
input = 1
endsub
sub main
SHORT counter = 0
while true do
if input = 1 then
...
counter = input = 0 ; reset counter
endif
counter = counter + 1
if counter = 15*60
.. there was no input for about 15 * 60 seconds...
counter = 0 ; reset counter
endif
delay_1s
done
endsub
blight | |
| |
| | #3 |
|
Thanks for the fast reply. You poeple are great. I guess that code is in "C". Does anyone know how I would do it in Basic? As I need to keep my day job, and tring to learn another Programming lang. when I'm still thing to figure out Basic. "C" Is not an option. ( I have only a few years left to live (30 are so)). They will have a voice programable "Megamicrochip" before I figure out all the Basic commands. Thanks Steveo | |
| |
| | #4 |
|
this is not C but pseudo-code - you can translate it into any programming language you like to | |
| |
| | #5 |
|
15 minutes? that is long set up timer, can choose any timer u like, the best is timer1, because it has 16 bit register choose the largest pre scaler make some calculation on the time the overflow occur, and goes into interrupt subroutine However, the interrupt frequency is definitely far less than 15 minutes so, u assign an long integer, say i. You increment i everytime interrupt occur. I guess the time is still not long enough You declare another long integer j, j increment everytime i overflow, that is, back to 0. If the time still not enough, then declare another long int, keep doing it until u get 15 minutes However, if you microcontroller's function is just checking the input, and has nothing else to do, then u can just put a delay, lets say 1 second. make a while loop that check the pin after every second, and do the for loop for 15*60 times. If there is input, then come out from the while loop. | |
| |
|
| Tags |
| break, loop |
| Thread Tools | |
| Display Modes | |
| |