Microcontroller Basics - Making a Simple Programming Code for an MCU - LEKULE

Breaking

22 Aug 2016

Microcontroller Basics - Making a Simple Programming Code for an MCU

By now you might have installed the required software and built the SPI interface.


The next step will call for a few components such as a breadboard, an LED and a calculated resistor for the intended application.

In this section we’ll learn the testing method of the programmer and confirm the installation of the relevant drivers and the software.

In order to verify if the drivers and the software were installed correctly we’ll implement a simple program known as avrdude.

The AVRdude is program associated with the latest WinAVR installation without which the actual transfer of the file into the MCU cannot be possible.

This program is a .hex file format which essentially becomes understandable to the MCU for the required executions.

In case the verification does not succeed, the programmer will be incapable of doing the transfer of the file.

Let’s quickly see how we can implement the testing procedure with the help of the following instructions:

Open the DOS (Disk operating system) prompt by clicking “start menu” and typing cmd.exe in the given search box.

Now the carrying out the AVRdude may be done by simply typing avrdude –c usbtiny –p m32 over the DOS prompt. As soon as this is implemented, the DOS will instantly acknowledge whether the connection was a success.

In the above command, the “-c” is a notifying flag which includes the “usbtiny” programmer parameter specification, while the “-p” tag identifies the microcontroller device (“m32 indicating Atmega32).

In case you have used a different MCU, you would need to include the relevant prefixes for the implementation.

Once the above procedure is finished, you may type “exit” over the DOS prompt, and that will move you out of the window.

If you are seriously wondering regarding the actual programming details, well for that we would first need to solder and construct the external analogue LED circuit over which the program could be implemented, because unless there’s a system to acknowledge the response from the MCU, the programming and running of the microcontroller would be quite meaningless.

Making the LED board is very simple, it’s all about soldering the two leads of the LED over a piece of veroboard and connect the resistor with one of the lead of the LED. The role of this LED is only to limit the current to the LED so that it doesn't burn of due to the excess voltage ad current from the MCU output.




The value of the resistor may be calculated by using the following simple formula:

R = (Ub – LEDfwd)/I

Where Ub is the supply voltage, LEDfwd is the optimal operating voltage of the LED used, and I is its optimal amps.

Suppose we use a RED LED which has a LED forward voltage = 2.5V and current I = 20mA, the above equation can be solved as follows:

Since the voltage from MCU would be 5V, it may be expressed as:

R = (5 – 2.5)/.02 = 125 ohms, ¼ watt, the nearest value being 120 ohms will do.

Now we have the LED, a 120 ohm resistor and a veroboard, simply interconnect the above components as given in the diagram with the microcontroller.

Once this is done, the MCU could be programmed for the intended response on the above LED set up.


Next up, the programming of the MCU.

No comments: