If you already know how to program when you start learning about microcontrollers, that’s great. It means you only have to familiarize yourself with the nuances of microcontroller operation. But even if you don’t have any programming skills, don’t give up – just take a step and try to acquire them! In our article, you will find some simple recommendations on how to do it quickly and easily.

What is the best way to start programming?:

This article is dedicated to those who have no prior programming experience and haven’t worked with microcontrollers but are eager to learn. The main factor here is the desire. If you have the desire, the next step is to properly organize your self-education process.

And so, we’re getting to the heart of the matter! First of all, before diving into microcontroller firmware, you need to write and debug a program for its operation. At this stage, many people start copying others’ programs and desperately try to understand what’s written there. This is an entirely wrong approach—don’t do that. In reality, it’s easier to write a program yourself than to decipher someone else’s. However, a program doesn’t begin with a multitude of commands, extensive lines of code, or terabytes of text. Every program starts with an algorithm!

Recommendations for beginners on writing an algorithm:

The algorithm of a program (just like anything else) is its graphical representation in the form of a sequence of special blocks connected by a logical chain, which defines ‘what’ and ‘in what sequence’ is executed. Each block has its own specific purpose and performs a particular function. Before even writing the simplest program for a microcontroller, such as blinking an LED, you need to create an algorithm for the program, at least for yourself.

To create an algorithm for a program, you need to know the functions and rules for representing each individual block of the algorithm. However, there’s no need to memorize all of this; you just need to refer to any programming guide or tutorial to review it.

An example of creating an algorithm:

Once you have finally grasped how the blocks are properly arranged in the algorithm diagram, you can begin creating it. If you are writing a program for yourself, it is important to follow a few simple rules:

Clarity – don’t hesitate to describe your algorithm in detail, add necessary comments, but avoid unnecessary information (be as clear and concise as possible).

Systematic approach – try to develop a habit of organizing everything systematically. A good algorithm is not just a collection of different blocks; it has a well-thought-out structure with a strict system.

Optimization – ‘simplicity is the mark of genius.’ The same task can be solved in multiple ways, so choose approaches that are first and foremost understandable and straightforward (with the fewest operations required to achieve the final result), at least until you learn how to optimize programs.

Of course, it will be challenging for you at the beginning. Be prepared that your initial algorithms may not be concise, simple, or optimal. The key is not to get discouraged and keep exploring and experimenting.

An example of developing a simple algorithm:

Before starting the development, it’s important to clearly define your objective! I recommend specifically writing down what you want to do or what result from the program execution will satisfy you. For example:

“When power is supplied to the circuit, light up the LED connected to the PD6 port of the Attiny2313 microcontroller (refer to Figure 1), wait for 5 seconds, and start blinking it.

Figure 1: LED connected to the PD6 port of the Attiny2313 microcontroller.

And, as you may have already guessed, your first step after defining and describing the task is not assembling the circuit or writing the program. It is to intelligently construct an algorithm that implements your task (see Figure 2).

Figure 2: My version of implementing the task.

Perhaps the algorithm depicted in Figure 2 is not perfect and was drawn without strict adherence to standards and rules for creating flowcharts or algorithms. However, it is understandable and clear to me, which is crucial for me to be able to create a program for its implementation. This is my vision of solving the task, but of course, you may have a different approach. So, try to come up with your own ideas and create an algorithm for implementing your device on the microcontroller. As for how to translate it into a program, we will describe that in our upcoming articles on our website at https://bip-mip.com/.

Leave a Reply

Your email address will not be published. Required fields are marked *