How to upload the program to atmega8 proteus. Simulation of microcontrollers. This tutorial will explain and demonstrate with simple examples how to

'arrow" ( F 12) - start simulation

"double arrow" ( F 11) – step by step (by commands) simulation

"two sticks" ( pause ) - pause

'rectangle" ( Esc ) - stop

Or a letter "R"

Let's choose the components:

And let's put together this diagram:

But the scheme turned out to be “cluttered”, and we will remake it into:

And in the Program File section, specify the firmware file for it ( hex)

We close. Turn on the simulation ( F12 )

The clock has started.

It is worth recalling that in the diagram:

" Red" - logical " 1 "
" Blue"- boolean " 0 "
" Gray" – indefinite-high-impedance "Z- condition"
" Yellow" - conflict on the line.

Let's stop the project. Let's press right click mouse on the processor.Opens:

In the menu that opens, in the item AVR available to us:

CPU registers - Ul - general-purpose registers of the controller.

EPROM Memory- Ul - eeprom memory

Program Memory-ul- program memory (flash)

Data Memory - Ul - contents of RAM

I / O registers - Ul - the contents of the I / O registers (in microcontrollers AVR I / O registers - control registers of the microcontroller periphery)

Source Code – Ul- program text

CPURegisters:

EPROM Memory :

Program Memory :

Data Memory :

Controller RAM, at the top (at address) you can see the contents of the stack

I/O Registers:

source code :

Above in this menu, the item Configure Diagnostics ...(beetle)

Check it out for details.

When you click on it, a panel will open:

From it we select ATMEGA 32 (Ul ).The panel will look like this:

In the "menu" that opens, the peripheral modules of the selected microcontroller will appear. When selected, they can be given a "debug level":

Disabled – disabled, the program will not respond to events in the module

Warnings Onl at– only warnings, in case of this event a message will be written in the module (in SIMULATION LOG).

Full Trace - at some event, a warning will be written in the module (in the SIMULATION LOG), but the program will go further.

Debug – at any event in the specified module, the program will stop.

Example: we will monitor interrupts in the MK. Choose " Interrupt Events ", set the level" debug":

Suspend the program execution. We open SIMULATION LOG. Events are shown there - interrupt calls. Such things are extremely necessary when debugging complex projects. There are also "links" to "points" in the program where these events were called. For example, all interrupts were called from the address 0x0086. By clicking on the “link” value, you can get to the section of the program from where the call originated.

But these windows will be open if the project is stopped. To display information about the status of I / O registers, the Watch Window is designed. Opening: menu= > Debug=> watch window. A window will appear:

When you press the right button, a menu will appear:

For example, let's put inWatch Window the contents of the second counter of our watch ( r 17) and the content of the port that displays the seconds counter.

Surely, many of the readers of this site would like to independently develop and assemble some kind of device on the AVR MK. But there can be a lot of reasons why it is difficult to do this in hardware. For example, living in a rural area where there are no radio shops with a large selection of radio components. Although in this case, as always, the Ali Express website comes to the rescue. Or limited budget. This is especially true for schoolchildren and students who do not yet have a permanent source of income.

So what to do in this case? Here, special simulator programs specially created for debugging circuits come to our aid.

One of them, Proteus version 7.7, we will analyze in this article in relation to our project. You can download it on Rutracker.

What does this program give us? Beginners will think that it is too difficult to master. No, it's not. We simply will not use all the functions of the program when emulating our first projects. It is really possible to master its basics in one or two evenings. What does it give us in terms of learning how to work with microcontrollers? There, for example, there is a visual representation of the operation of LEDs, real-time displays. You can choose to emulate many types of AVR MK, including those on which our lessons will be based: Tiny2313 and Mega8. What does this mean and how is it done? We write our firmware code, compile it, get the HEX file we need and virtually flash our MK in the Proteus program. Moreover, we can also change the fuse bits of our virtual MK.

Let's take a look at what actions we need to take in order to assemble this circuit on the working field on our own and emulate it.

This is the window that opens immediately after starting the program (click to enlarge):

Then we need to select from the library those radio parts that we need for the project and place them in the parts list. We can then select and install them on the working field. In our project, we will use an Attiny2313 MCU, a yellow LED-YELLOW (it glows well in Proteus) and a RES resistor to limit the current flowing through the LED. Otherwise, we, no matter how ridiculous it may sound, will “burn” the virtual LED :-).

In order to select these radio elements, we must click on the letter "P":

After clicking, the following window will appear:

In the "Mask" field, we drive in what we want to find, namely, our MK, LED and resistor

We type “Tiny2313” in the Mask field and click on the MC we found in the “Results (1)” column:

Then we repeat the same with the resistor. We drive "res":

and in the same way we are looking for an LED:

Well, now all these three elements should be displayed in the “Devices” column:

Now we click on the black arrow, and then select the radio element we need from the list:

On the left in the vertical column we see the "Terminal" icon. We are interested in two lines there: Power and Ground. This is respectively in our circuit +5 volts supply and ground. It is not necessary to supply power to the MK, it is supplied automatically. For the circuit, we take only the "earth" icon.

We pull out all the radio elements on the working field

Then we need to connect them with a connection line, after that we will not care that they are connected by a conductor, for example, a track on the board or wiring

I must say right away, do not try to install one output of the part close to the other or even overlap, without using connection lines. The program will not understand this as a connection and the circuit will not work.

We also need to change the value of the resistor. By default, it is not suitable for our scheme. How to do it?

Right-click on the resistor, select Edit Properties

And then change the value to 200 ohms. It is enough that our virtual LED is not dead)

Sometimes our working field tries to escape from the screen, then we need to use the scrolling mouse wheel to change the scale and click, setting the green frame in the upper left corner so that our entire project is inside it

By the way, I want to say right away that if we have committed some kind of erroneous action, we just need to click the "Cancel" button and last action will be cancelled. I think a lot of people know this third party programs, but hardly).

So we've put together a diagram. Now we need to upload the firmware to our microcontroller and see how it looks in action. To do this, we need to right-click on the MK and click the yellow folder icon in the Program Files column. By the way, here you can also set the fuse bits if necessary (click to enlarge the picture):

Then you need to select the firmware file with *.HEX extension and click "Open". Everything is ready, you can emulate the project.

(click on the picture to enlarge)

To start emulation, you need to press the "triangle" button in the lower left corner of the Proteus program:

We will begin emulation. We will see how the LED blinks. At some point in time, our LED will glow. See how brightly it burns in yellow 🙂

And then it will fade again:

This is what the saved project icon looks like on the desktop:

I hope that you, the readers, will not be difficult to assemble this project on your own and in the future, having pumped your skill, you can easily assemble any more complex project on your own. I attached the finished project for the Proteus 7.7 program and the firmware in this archive.

That's it! Below is a video of the operation of the circuit, as well as all the stages of emulation:

Surely, many of the readers of this site would like to independently develop and assemble some kind of device on the AVR MK. But there can be a lot of reasons why it is difficult to do this in hardware. For example, living in a rural area where there are no radio shops with a large selection of radio components. Although in this case, as always, the Ali Express website comes to the rescue. Or limited budget. This is especially true for schoolchildren and students who do not yet have a permanent source of income.

So what to do in this case? Here, special simulator programs specially created for debugging circuits come to our aid.

One of them, Proteus version 7.7, we will analyze in this article in relation to our project.

What does this program give us? Beginners will think that it is too difficult to master. No, it's not. We simply will not use all the functions of the program when emulating our first projects. It is really possible to master its basics in one or two evenings. What does it give us in terms of learning how to work with microcontrollers? There, for example, there is a visual representation of the operation of LEDs, real-time displays. You can choose to emulate many types of AVR MK, including those on which our lessons will be based: Tiny2313 and Mega8. What does this mean and how is it done? We write our firmware code, compile it, get the HEX file we need and virtually flash our MK in the Proteus program. Moreover, we can also change the fuse bits of our virtual MK.

Let's take a look at what actions we need to take in order to assemble this circuit on the working field on our own and emulate it.

This is the window that opens immediately after starting the program (click to enlarge):


Then we need to select from the library those radio parts that we need for the project and place them in the parts list. We can then select and install them on the working field. In our project, we will use an Attiny2313 MCU, a yellow LED-YELLOW (it glows well in Proteus) and a RES resistor to limit the current flowing through the LED. Otherwise, we, no matter how ridiculous it may sound, will “burn” the virtual LED :-).

In order to select these radio elements, we must click on the letter “R”:

After clicking, the following window will appear:


In the “Mask” field, we drive in what we want to find, namely, our MK, LED and resistor


We type “Tiny2313” in the Mask field and click on the MC we found in the “Results (1)” column:


Then we repeat the same with the resistor. We drive in "res":


and in the same way we are looking for an LED:


Well, now all these three elements should be displayed in the “Devices” column:

Now we click on the black arrow, and then select the radio element we need from the list:

On the left in the vertical column we see the “Terminal” icon. We are interested in two lines there: Power and Ground. This is respectively in our circuit +5 volts supply and ground. It is not necessary to supply power to the MK, it is supplied automatically. For the circuit, we take only the “earth” icon.

We pull out all the radio elements on the working field


Then we need to connect them with a connection line, after that we will not care that they are connected by a conductor, for example, a track on the board or wiring


I must say right away, do not try to install one output of the part close to the other or even overlap, without using connection lines. The program will not understand this as a connection and the circuit will not work.

We also need to change the value of the resistor. By default, it is not suitable for our scheme. How to do it?

Right-click on the resistor, select Edit Properties


And then change the value to 200 ohms. It is enough that our virtual LED is not dead)


Sometimes our working field tries to escape from the screen, then we need to use the scrolling mouse wheel to change the scale and click, setting the green frame in the upper left corner so that our entire project is inside it

By the way, I want to say right away that if we have committed some kind of erroneous action, we just need to click the “Cancel” button and the last action will be canceled. I think many people know this from third-party programs, but you never know).

So we've put together a diagram. Now we need to upload the firmware to our microcontroller and see how it looks in action. To do this, we need to click right click on MK and click the icon with the image of a yellow folder in the Program Files column. By the way, here you can also set the fuse bits if necessary (click to enlarge the picture):


Then you need to select the firmware file with *.HEX extension and click “Open”. Everything is ready, you can emulate the project.

(click on the picture to enlarge)


To start emulation, you need to press the “triangle” button in the lower left corner of the “Proteus” program:


We will begin emulation. We will see how the LED blinks. At some point in time, our LED will glow. See how brightly it burns yellow :-)


And then it will fade again:


Now we can optionally save our project under any name by selecting “Save project as”, and also if we need to open a finished file of another project by selecting “Open project”

This is what the saved project icon looks like on the desktop:

I hope that you, the readers, will not be difficult to assemble this project on your own and in the future, having pumped your skill, you can easily assemble any more complex project on your own. I attached the finished project for the Proteus 7.7 program and the firmware in the archive.

That's it! Below is a video of the operation of the circuit, as well as all the stages of emulation:

Design of electrical circuit diagrams using microcontrollers in a software environmentProteus 8.1. Part 2

Proteus has a large number of features for professional design of microelectronic devices, focused on the most modern facilities modeling. One of these functions is the simulation of microcontrollers.

In this article, the process of modeling circuits using microcontrollers is considered using the 80C51 microcontroller as an example.

Modeling a circuit including a microcontroller and translation program code.

To visually demonstrate the operation of the microcontroller initialization program, we will use colored probes of logic levels 0 and 1. select Logic Probes in the Sub-category field, and LOGICPROBE in the Results field, then click OK.

Rice. 1. Selecting a logic level probe in the Pick Devices window.

As a result, the Pick Devices window will be closed, and the probe symbol will be attached to the mouse cursor, with which you need to place the symbol in the right place on the diagram - click in the right place on the diagram with the left mouse button as many times as you need to place the probes.

Let's add an 80C51 microcontroller to the project's working field (the process of creating a new project using a microcontroller in Proteus was discussed in detail in the first part of the article) and connect the probes to the investigated microcontroller port lines. As a result, when a logical unit value appears at the output of the port line, the probe will be highlighted in red, and when a logical zero value appears, the probe will be highlighted in blue. Also on the probes, the values ​​\u200b\u200bof 0 and 1 are visually displayed.

After the scheme is assembled in the project workspace (Fig. 2), and the program code is entered on the Source Code tab (Fig. 3), you can start the simulation.

Rice. 2. Demonstration circuit using a microcontroller and colored logic level probes.

Rice. 3. Microcontroller initialization program.

The simulation process is launched using the Run the simulation button, which is located in the lower left corner of the program window. In order to temporarily pause the simulation process, use the Pause the simulation, or start up at time 0 if stopped button (the button is located in the lower left corner of the program window). You can stop the simulation using the Stop the simulation button.

As a result, in the event that the compiler does not find errors in the program listing, on the disk of your computer in working folder project, the following files will be created:

  • *.hex – machine code file (Fig. 4);
  • *.asm - file with the assembler code of the program (Fig. 5);
  • *.sdi - debug file of the initialization program, the contents of which can also be viewed on the 8051 CPU Source Code tab (Fig. 6).

Rice. 4. Hex machine code file.

Rice. 5. File with the assembler code of the program.

Rice. 6. Tab 8051 CPU Source Code.

The microcontroller initialization program is written in the asm51 programming language. This is an assembly language that is designed specifically for writing programs for microcontrollers of the x51 family. In the event that errors were found during the compilation of the microcontroller initialization program code, they will be marked by the compiler in the *.lst file. In this case, the hex file will not be generated until the errors are fixed. In the listing file, for each error it encounters, the compiler lists the cause of the error and the line number where it was found. Figure 7 shows a fragment of the *.lst file, in which the debugger reports error number 2 (Undefined identifier), which consists in the fact that the name of the data input / output port is incorrectly specified in the program code (the microcontroller used does not have a port with the name P6).

Rice. 7. Fragment of the listing file *.lst.

Debugging the initialization program is performed on the 8051 CPU Source Code tab, which is displayed after the simulation process is paused. In order to temporarily pause the circuit simulation, use the Pause the simulation, or start up at time 0 if stopped button (the button is located in the lower left corner of the program window). A report on errors received as a result of translation of the program code is displayed at the bottom of the Source Code tab in the VSM Studio Output panel (Fig. 8).

Rice. 8. Report on errors received as a result of the translation of the program code.

The state of the memory and registers of the microcontroller can be viewed using the following commands of the main menu of the program:

  • Debug/8051 CPU Registers (Fig. 9a);
  • Debug/8051 CPU SFR Memory (Fig. 9b);
  • Debug/8051 CPU Internal (IDATA) Memory (Fig. 9c).

Rice. 9. Status: (a) registers, (b) SFR memory, (c) internal memory microcontroller.

The Debug menu (Figure 10) is available to call while the circuit simulation is paused.

Rice. 10. Debug menu.

Let's analyze the operation of the demo circuit shown in Figure 2. On the main.asm tab (Figure 3), using the mov command, instructions were given to the microcontroller initialization program to write to the P2 port the following values ​​of the P2.7-P2.0 port lines - "00001111", and to port P1 - the values ​​of the lines of the port P1.7-P1.0 - "01010101". After running the simulation with color probes, we can check the correct operation of the program. As can be seen from Figure 2, the pins of the ports of the microcontroller P1 and P2 are indeed the combination that we indicated in the program code.

Pairing the microcontroller x51 with chips of 7-segment indicators in Proteus.

A system that uses a microcontroller can not only control something, but also display something. Most often, sign-synthesizing indicators are used as a display node in the scheme. There are no standard rules for pairing a microcontroller with indicators, and in each case, pairing can be done in different ways.

Figure 11 shows an example of connecting a 7-segment indicator microcircuit to a microcontroller. The principle of connecting the microcontroller to the circuit elements is the same as for other circuit components.

Rice. 11. Pairing a 7-segment indicator chip with a microcontroller.

In order to display the figure, you need to "light" certain segments of the indicator. When used in a microcontroller circuit, this can be done programmatically. Various combinations of luminous indicator elements, provided by external switching, allow displaying numbers from 0 to 9 and a decimal point. In the presented example, the elements of the indicator have a common cathode.

To control a 7-segment indicator, the circuit uses a binary-decimal decoder 74HC4511 (domestic analogue 1564ID23). The decoder chip converts the binary code received from the microcontroller into a digit code for further display on the 7-segment indicator chip. The 74HC4511 chip is a special decoder designed to convert a binary code to a seven-segment code and control seven-segment and liquid crystal indicators. Inputs А, B, C, D – information inputs. Outputs QA-QG - outputs to a seven-segment indicator. Binary codes and their corresponding decimal digits are presented in Table 1.

Table 1. Binary codes and their corresponding decimal digits.

binary code

Decimal digit

In order to add a decoder chip to the project workspace, you need to open the Pick Devices window (Fig. 12a) and select the TTL 74HC series library from the list in the Category field in its upper left part. Below the Category field is the Sub-category field, in which you must select the Decoders item. In the Results field, select the 74HC4511 chip and click the OK button. To add a chip seven-segment indicator with a common cathode, select the Optoelectronics library in the Pick Devices window (Fig. 12b) in the Category field, 7-Segment Displays in the Sub-category field, and 7SEG-MPX1-CC in the Results field.

Rice. 12. Selection of circuit components in the Pick Devices window: (a) decoder, (b) seven-segment indicator.

In the example shown in Figure 11, the indicator displays the number 3. To do this, on the main.asm tab (Fig. 13), using the mov command, instructions were given to the microcontroller initialization program to write the following values ​​​​of the P2.7-P2.0 port lines to port P2 - “ 00000011".

Rice. 13. Writing the binary code of the number 3 to the port P2 of the microcontroller.

After running the simulation, we can check that the program is working correctly. As can be seen from Figure 11, the pins of the P2 microcontroller port are indeed the combination that we indicated in the program code, and the indicator displays the number 3.

Microcontroller programming x51.

When writing program code for the x51 microcontroller, you must know the syntax of the asm51 programming language. The most commonly used asm51 commands are shown in Table 2.

Table 2. The command system of the x51 microcontroller.

Team name

Mnemocode

Transfer to accumulator from register

Transfer to register from accumulator

Battery swap with register

Accumulator addition with register

Accumulator addition with a constant

accumulator increment

register increment

Accumulator decrement

Register decrement

Boolean AND accumulator and register

Logical OR of accumulator and register

Battery reset

Battery inversion

Jump if the accumulator is zero (mt is a label in the program code)

Branch if the accumulator is not equal to zero (mt is a label in the program code)

An empty operation that can be used as a 1µs delay

Subroutine exit