I have a problem with using HiTec PIC C. I programmed a Pic16F84 with some simple codes such as turning on (scrolling) LEDs on portb0 to portb7 and stop. but somehow the code seems looping itself even I didn't ask it to. Please can any one help?
I am not familiar with HiTech C but I am guessing, something is not right with ur while loop. Check your while statements.. Unless you "break" it, the code inside a "while (1)" loop will repeat itself.
Why don't you post your code so that we can have a look.
In ALL C compilers, if the code even reaches the end of the main(){}, the part will reset and the code will run again.
If you want to do a job once upon power-up and then never do anything again (rare outside of the testbench), then you must have:
main(){
... do stuff...
while(1); //loop forever
}
if you have the WDT enabled, you must account for that:
main(){
... do stuff...
while(1){
CLRWDT;
} //loop forever
}
I am not familiar with HiTech C but I am guessing, something is not right with ur while loop. Check your while statements.. Unless you "break" it, the code inside a "while (1)" loop will repeat itself.
Why don't you post your code so that we can have a look.
I think you might have missed the question. I think the guy said he didn't ask for looping. So in his code, probably there's no while(1){ } in it but it loops anyway.
In ALL C compilers, if the code even reaches the end of the main(){}, the part will reset and the code will run again.
If you want to do a job once upon power-up and then never do anything again (rare outside of the testbench), then you must have:
main(){
... do stuff...
while(1); //loop forever
}
Thanks, I think I nearly got it, but still little confused.
that's the problem I'm having, the code runs to the end and reset and run again. That's what I don't want. All I want is the program will stop in what ever it told to do last and Not going back to the beginning and start again.
How do I do that?
Thanks, I think I nearly got it, but still little confused.
that's the problem I'm having, the code runs to the end and reset and run again. That's what I don't want. All I want is the program will stop in what ever it told to do last and Not going back to the beginning and start again.
How do I do that?
Read again. That's exactly what I told you to do.
while(1); //means to keep doing this loop forever- but there's NO instructions in the loop; it does not mean to repeat code lines elsewhere. All it does is the instruction is a GOTO to itself. Since the code is unconditionally stuck on this line forever then it will never get to the end of the main(){}
The second example is a single instruction in the loop- clear the WDT over and over and over.
This is an acceptable use of "while", although the original purpose was more like:
which will loop and make a clock pulse until port B is 0b00001111 then exit and run the next line of code outside the loop. But if you say while(1); "1" is inherently true so no false condition will ever occur and it is an endless, empty loop.