Flowcode Decisions

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 CONDITIONhas been met so that we can do certain things or select anOPTION(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.

—> 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.

Stay Update:

Search Here

Translate Website into your Language

Please support our work with a Donation

Writing tutorials and recording tutorials videos requires a lot of resources and time. If you found these tutorials helpful, please show your support and donate any amount you wish so that we can do even more.
Thanks