Flowcode DecisionsBitahwa Bindu
Watch The Video Tutorial
Let us design a binary counter to count from 0 to 15 in binary using four LEDs connected to PORTB as in figure above for this tutorial.
NOTE: The power supply is not shown here, the PIC should be connected to +5V(VDD) and Ground (VSS).
As the internal oscillator is not used here, connect an external crystal oscillator on pin 13 and 14 as shown in Reading Switches article.
Decisions are vital in any programming languages, in most of the cases, we need to know IF a certain CONDITION has been met so that we can do certain things or select an OPTION (CASE OPTION) from a number of options.
In our binary counter example above, we need to increment the value of variable by 1 until we reach the maximum value (15) so that we can start counting again.
—> Start a new project, select the PIC 16F877A. Go to the component toolbar and select 4 LEDs.
—> Insert a While (1) loop icon.
—> Insert a decision icon.
—> Double click the Decision icon to open its properties.
—> Create a new byte variable named “Counter” and initialise its value to “0” as learned in the Flowcode Variables article
—> Click OK to close the variable dialog.
—> Insert the rest of the icons to complete the project.
—> As long as the condition evaluates to FALSE (Counter is less or equals to 15), the branch of the decision under the NO will continue to evaluate. Outputting the value of Counter to PORTB, delay of 500ms and then increment the value of Counter until it becomes greater than 15.
—> Once the value of Counter in greater than 15, the IF Statement will evaluate to TRUE and then branch of the decision under the YES will evaluate which here will reset the counter (counter=0).
—> As the Counter becomes less than 15 again, the decision evaluates to FALSE again and the cycle begins again.
Download Decision Flowcode Project