Add:
while(1);
Just before the last bracket in the program (at line 51). The way it is written, after the 4 flashes, your code exits ‘main’ and will restart (XC8 adds that code). Embedded programs like this always need some sort of loop to stay in main. Without it, the code ‘exits’ but there is no operating system to return to so the C startup code provides a jump back to the beginning. Note that this just hangs your code there but it will stop the flashing.
You should be using LATBbits, not PORTBbits for outputs - especially single bit outputs.
Also try our handy code tags to post your code. I added them your post 19 so you can see how it's done. Use the ‘INSERT’ button on the edit toolbar.
Good luck!
while(1);
Just before the last bracket in the program (at line 51). The way it is written, after the 4 flashes, your code exits ‘main’ and will restart (XC8 adds that code). Embedded programs like this always need some sort of loop to stay in main. Without it, the code ‘exits’ but there is no operating system to return to so the C startup code provides a jump back to the beginning. Note that this just hangs your code there but it will stop the flashing.
You should be using LATBbits, not PORTBbits for outputs - especially single bit outputs.
Also try our handy code tags to post your code. I added them your post 19 so you can see how it's done. Use the ‘INSERT’ button on the edit toolbar.
Good luck!
Last edited: