the Internet Windows Android

Programming MK from scratch. Programming Microcontrollers AVR.

I have not once and not two saying that the study of the MK should be started with the assembler. This was dedicated a whole course on the site (although it is not very consistent, but gradually I combed it to an adequate type). Yes, it is difficult, the result will not be on the first day, but you will learn to understand what is happening in your controller. You will know how it works, and not on the monkey copy other people's sources and try to understand why it suddenly stopped working. In addition, the SI is much easier to overtake by the middle oflood, which will come out with forks at the most inopportune moment.

Unfortunately, everyone wants the result immediately. Therefore, I decided to go on the other hand - to make training on SI, but with the show of his underwear. A good programmer-embedder always holds his piece of iron for a squall, without giving her a step to step without permission. So it will be at the beginning of the SO code, then what born the compiler and how it really works in fact :)

On the other hand, the SI is a strong side is portability of the code. If, of course, writing everything correctly. Separating the work algorithms and their iron implementations in different parts of the project. Then, to transfer the algorithm to another MK, it is enough to rewrite only the interface layer, where all appeal to the gland is written, and leave the entire working code as it is. And, of course, readability. The sash source source is easier to understand at first sight (although .. I, for example, do not care about what to flirt is at least si, at least AFM :)), but, again, if you write everything right. With this moments, I will also pay attention.

As an experimental piece of hardware on which the lion's share of all examples will be my debug board.

First program on C for AVR

Choosing a compiler and installation of the environment
For AVR, there are many different C compilers:
First of all it IAR AVR C. - Almost uniquely recognized as the best compiler for AVR, because The controller itself was created by the close cooperator of ATMEL and specialists from IAR. But for everything you have to pay. And this compiler is not enough of what is expensive commercial software, it also possesses such a breakfast settings that just take and compile it in it should be rushed. I really didn't have a friendship with him, the project was drunk on strange mistakes at the linkage stage (later found out that it was a crack curve).

The second is coming WinAvr GCC. - Powerful optimizing compiler. Full opens, cross-platform, in general, all the joys of life. He also integrates perfectly in Avr Studio allowing you to debug right there that hell is comfortable. In general, I chose it.

Also there is CodeVision AVR C.- Very popular compiler. He became popular in connection with his simplicity. Working program You can get in it in a few minutes - the master of the starting code is greatly promoted, the stamp of the initialization of all kinds of ears. Honestly, I'm sorry with suspicion to him - somehow I had to disassemble a prog written by this compiler, some kind of meant, but not the code was obtained. A terrible amount of unnecessary televitations and operations, which was poured into a slight codes and slow speed. However, perhaps there was a mistake in DNA wrote the original firmware. Plus he wants money. Not much like Iar, but noticeable. And in demozhim gives not more than 2KB code.
Crack of course there is, but if you steal, so a million, in the sense of IAR :)

There is also Image Craft AVR C and Microc from microelectronics. Neither to use any other use, but here SWG. Very plowing MicropascalMelt is a terribly convenient programming environment and library. I think Microc will not be worse, but also paid.

As I said, I choose WinAvr. in three reasons: free, integrates in AVR Studio and is written by just a buzz finished code for all occasions.

So download yourself to install WinAvr C and AVR Studio. Then the studio is first put, then, from above, WinAvr rolls over and clings to the studio in the form of a plugin. I strongly recommend installing WinAvr on a short way, something like C: \\ WinAvr Thereby, thereby you avoid piles of problems with the ways.

Creating a project
So, the studio is delivered, Si is fastened, it is time to try something to program. Let's start with a simple, simplest. Run the studio, choose a new project there, as a compiler AVR GCC and enter the name of the project.

Opens the work field with an empty * .c file.

Now it does not prevent configure the display of paths in the Studio tabs. For this, the slant at:
The Tools menu - Options - General - Filetabs and select "FileName Only" in the drop-down list. Otherwise it will be impossible to work - on the tab there will be a full path of the file and there will be no more than two tabs on the screen.

Project Setup
In general, the creation of the Make file in which all dependencies would be described. And this is probably correct. But I grew up on fully integrated IDE like uvision. or AVR Studio. This approach is deeply alien. Therefore, I will do in my own way, all the studios.

Pile into the button with a gear.


These are the settings of your project, or rather the setting of automatic generation of the Make file. On the first page you just need to enter the frequency on which your MK will work. It depends on the fuses of bits, so we believe that the frequency is 8000000Gz.
Also pay attention to the optimization string. Now there is --OS is optimization in size. While leave as it is, then you can try to play with this parameter. -O0 is removable optimization at all.

The next step is to configure paths. The first thing to add the directory of your project there is - you will put a third-party library there. The list will appear ". \\"

Make file generated, you can see it in the Default folder in your project, just run through your eyes, see what is there.


That's all. Jim everywhere OK and go to the source.

Formulation of the problem
The blank sheet is so waved to embody some tricky idea, since the banal blinking of the diode does not insert. Let's immediately take a bull for the horns and implement a connection with the computer - this is the first thing that I do.

It will work like this:
Under the arrival of the COM port, the unit (code 0x31) will light the diodion, and when the arrival of zero (code 0x30) is extinguished. Moreover, everything will be done on interrupts, and the background task will be blinking another diode. Simply and with meaning.

Collect the scheme
We need to connect the USB-USart Converter module with the microcontroller usart converters. To do this, take a jumper of two wiring and put the cross in the pins of the cross. That is, the Rx controller connects with the TX converter, and the TX converter with the RX controller.

It turns out, as a result, this is such a scheme:


Connecting other conclusions, nutrition, discharge, it is standard

We write code

Immediately make a reservation that I will not deepen specifically in the description of the SI language itself. For this, there is simply a tremendous amount of material, ranging from the classics "SI programming language" from K & R and ending with different techniques.

One such method was found in me in the honeycomb, I once studied this language on it. There everything is brief, understandable and in the case. I gradually make it up and rearranged to my site.

There's really not all chapter postponed, but I think it's not for long.

It is unlikely that I will describe better, so from the training course, instead of a detailed exposure of the blue subtleties, I will simply give direct links to certain pages of this technique.

Add libraries.
First of all, we add the necessary libraries and titles with definitions. After all, si is a universal language and he needs to explain that we work with AVR, so enter into the source line:

1 #Include.

#Include.

This file is in the folder WinAvr. And it contains a description of all registers and ports of the controller. And there all cunning, with reference to a specific controller, which is transmitted by the compiler through make File in the parameter MCU. And on the basis of this variable in your project, a header file with a description of the addresses of all ports and registers is on this controller. In how! Without it, too, it is also possible, but then you will not be able to use the symbolic names of the registers like a SREG or UDR and have to remember the address of each such as "0xc1", and this is a head.

The same team itself #Include.<имя файла> Allows you to add to your project the contents of any text file, for example, a file describing the functions or a piece of another code. And so that the directive could find this file, we indicated ways to our project (the WinAvr directory is already spelled out there).

Main function.
The program in the SI language consists of functions. They can be embedded and brought from each other in any order and different ways. Each function has three required parameters:

  • Return value, for example, sIN (X) Returns the value of the X Sinus. As in mathematics, in short.
  • Transmitted parameters, the same X.
  • Body function.

All values \u200b\u200btransmitted and returned must be any type, depending on the data.

Any program on C must contain a function main. As a point of entry to the main program, otherwise it is nifiga not si :). According to the presence of Main in someone else's source from a million files, it can be understood that this is the head of the program where everything begins. So let's ask:

1 2 3 4 5 INT MAIN (Void) (Return 0;)

iNT MAIN (Void) (Return 0;)

All, first simplest program It was written, it did not matter that she does nothing, we just started.

We will analyze what we did.
int. This type of data that the Main function returns.

Of course, in a microcontroller main. I can not return anything in principle and in theory should be void Main (Void)but the GCC is initially sharpened on the PC and there the program can return the value operating system Upon completion. Therefore GCC on void Main (Void) swearing warning.

This is not a mistake, it will work, but I do not like Varnings.

void. This type of data that we transmit to the function in this case main. Also can't take anything from the outside, the poet void. - Dummy. The plug is applied when it is not necessary to transmit anything or return.

These are { } Figure brackets are a software block, in this case the body function main., there will be the code.

return. - This is the return value that the Main function will give upon completion, since we are int, that is, the number that we must return the number. Although it still does not make sense, because On the microcontroller from Main, we except for nowhere. I return zero. For nonfig. And the compiler is usually smart and the code does not generate the code.
Although, if you pervert, then from main. You can go to the MC - for example, fall into the bootloader section and fulfill it, but there is already a low-level firmware picking, to adjust the transition addresses. Below you will see and understand how to do it. What for? This is another question, in 99.999% of cases this nafig is not necessary :)

Made, went further. Add a variable, it is not particularly necessary for us and it is not necessary to introduce variables, but we are learning. If the variables are added within the body of the function - then they are local and exist only in this function. When you leave the function, these variables are removed, and the memory of RAM is given to more important needs. .

1 2 3 4 5 6 INT MAIN (Void) (Unsigned Char i; Return 0;)

iNT MAIN (Void) (Unsigned Char i; Return 0;)

unsigned So unsaluable. The fact is that in binary representation, we have a senior bit for the sign, which means in one byte (char) the number + 127 / -128, but if the sign discardes it gets already from 0 to 255. Usually the sign is not needed. So that unsigned.
i. - This is just the name of the variable. No more.

Now you need to initialize ports and UART.. Of course, you can take and connect the library and call some kind of uartinit (9600); But then you will not know what happened in fact.

We do this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 INT MAIN (Void) (Unsigned Char i; #define Xtal 8000000l #define Baudrate 9600L #Define Bauddivider (Xtal / (16 * Baudrate) -1) #Define Hi (x) ((x) \u003e\u003e 8) #define Lo (x) ((x) & 0xFF) uBrrl \u003d Lo (Bauddivider); UBRRH \u003d HI (Bauddivider); Ucsra \u003d 0; UCSRB \u003d 1.<< RXEN| 1 << TXEN| 1 << RXCIE| 0 << TXCIE; UCSRC = 1 << URSEL| 1 << UCSZ0| 1 << UCSZ1; }

iNT MAIN (Void) (unsigned char i; #define xtal 8000000l #define Baudrate 9600L #define Bauddivider (Xtal / (16 * Baudrate) -1) #define Hi (x) ((x) \u003e\u003e 8) #define Lo ( x) ((x) & 0xFF) uBrrl \u003d Lo (Bauddivider); uBrrh \u003d Hi (Bauddivider); ucsra \u003d 0; ucsrb \u003d 1<

Scary? In fact, the real code here is only five last lines. Everything, that #Define This is a macro-language preprocessor. Almost the same tops as in the assembler, but the syntax is somewhat different.

They will facilitate your routine operations to calculate the necessary coefficients. In the first line we say that instead Xtal You can safely substitute 80,000,000, and L.- Type specification, Long Mall are a processor clock frequency. Same baudrate. - Data frequency by UART.

bauddivider. Already more complicated, the expression calculated by the formula of two previous ones will be substituted instead.
Well and LO. and HI From this result will take the younger and senior bytes, because In one byte it clearly may not fit. IN HI Icse shift is done (the input parameter of the macro) eight times in the right, as a result, only the oldest byte will remain. A B. LO. We make a batch and with a number 00FF, as a result, only the youngest byte will remain.

So all that is done as #Define You can safely throw out, and the desired numbers count on the calculator and immediately enter them into the UbBrl \u003d lines .... and ubbrh \u003d ... ..

Can. But! Do this It is categorically impossible!

It will also work to work, but you will have the so-called magic numbers - The values \u200b\u200btaken incomprehensibly from where it is not clear why and if you donate such a project in a couple of years, then it is difficult to understand that it will be damn it. Yes, and now, you want to change the speed, or change the frequency of quartz and everything will have to recalculate, and so changed a couple of tsiferok in the code and everything itself. In general, if you do not want to enjoy Bydlokoder, then do the code so that it is easy to read, it was understandable and easily modified.

Then everything is simple:
All these "UBRRL and CO" are the registers of the configuration of the transmitter with which we will communicate with the world. And now we have assigned the necessary values \u200b\u200bby configuring the desired speed and the right mode.

Recording view 1< Means the following: take 1 and put it in place RXEN. In the fly. RXEN. This is the 4th bit of the register UCSRB., so that 1< forms a binary number 00010000, TXEN. - this is a 3rd bit, and 1< Dast 00001000. Single "|" It is broken ORso 00010000 | 00001000 \u003d 00011000. The remaining necessary configuration bits are exhibited in the same way and added to the general bunch. As a result, the assembly number is written in UCSRB. Details are written in Datashet on the MC in the USArt section. So do not get distracted by technical details.

Ready, it is time to see what happened. Pips on the compilation and launch of emulation (Ctrl + F7).

Debugging
All sorts of progress bars ran, the studio changed and a yellow arrow appeared near the Main function. This is where the processor is currently current, and the simulation on the pause.

The fact is that initially, in fact, it stood on the row UBrrl \u003d Lo (Bauddivider); After all, the fact that we have in define it is not code, but simply preliminary calculations, then the simulator fastened a little. But now he realized, the first instruction is completed and if you climb into a tree I / O View, In the USArt section and win there on the UbBrl byte, you will see that there is already there already! 0x33.

Make one more step. Looking at how the contents of another register change. So fuse them all, pay attention to the fact that all the indicated bits are exhibited as I said, and it is set at a time for the entire byte. Next Return does not work, the program is over.

Opening
Now reset the simulation in zero. Click there RESET (SHIFT + F5). Open disassembly listing, now you will see what happens in the controller in fact. View -\u003e Disassembler. And not yyaaaa !!! Assembler !!! Uzhos !!! BUT YOU MUST. So that later, when something goes wrong, did not dare into the code and did not ask Lamer issues on the forums, and immediately climbed into the loss and watched where you have a stall. There is nothing terrible there.

First, it will be a top of the series:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 +00000000: 940C002A JMP 0x0000002A Jump +00000002: 940C0034 JMP 0x00000034 Jump +00000004: 940C0034 JMP 0x00000034 Jump +00000006: 940C0034 JMP 0x00000034 Jump +00000008: 940C0034 JMP 0x00000034 Jump + 0000000A: 940C0034 JMP 0x00000034 Jump + 0000000C: 940C0034 JMP 0x00000034 Jump + 0000000E: 940C0034 JMP 0x00000034 Jump +00000010: 940C0034 JMP 0x00000034 Jump +00000012: 940C0034 JMP 0x00000034 Jump +00000014: 940C0034 JMP 0x00000034 Jump +00000016: 940C0034 JMP 0x00000034 Jump +00000018: 940C0034 JMP 0x00000034 Jump + 0000001A: 940C0034 JMP 0x00000034 Jump + 0000001C : 940C0034 JMP 0x00000034 Jump + 0000001E: 940C0034 JMP 0x00000034 Jump +00000020: 940C0034 JMP 0x00000034 Jump +00000022: 940C0034 JMP 0x00000034 Jump +00000024: 940C0034 JMP 0x00000034 Jump +00000026: 940C0034 JMP 0x00000034 Jump +00000028: 940C0034 JMP 0x00000034 Jump

00000000: 940C002A JMP 0x0000002A Jump +00000002: 940C0034 JMP 0x00000034 Jump +00000004: 940C0034 JMP 0x00000034 Jump +00000006: 940C0034 JMP 0x00000034 Jump +00000008: 940C0034 JMP 0x00000034 Jump + 0000000A: 940C0034 JMP 0x00000034 Jump + 0000000C: 940C0034 JMP 0x00000034 Jump + 0000000E : 940C0034 JMP 0x00000034 Jump +00000010: 940C0034 JMP 0x00000034 Jump +00000012: 940C0034 JMP 0x00000034 Jump +00000014: 940C0034 JMP 0x00000034 Jump +00000016: 940C0034 JMP 0x00000034 Jump +00000018: 940C0034 JMP 0x00000034 Jump + 0000001A: 940C0034 JMP 0x00000034 Jump + 0000001C: 940C0034 JMP 0x00000034 Jump + 0000001E: 940C0034 JMP 0x00000034 Jump +00000020: 940C0034 JMP 0x00000034 Jump +00000022: 940C0034 JMP 0x00000034 Jump +00000024: 940C0034 JMP 0x00000034 Jump +00000026: 940C0034 JMP 0x00000034 Jump +00000028: 940C0034 JMP 0x00000034 Jump

This is the table of interrupt vectors. We will come back to it, while just see and remember that it is. The first column is the flash address of the flash in which the command is lying, the second command code of the third mnemonic team, the same assembler instruction, the third operand of the team. Well, an automatic comment.
So, if you look, then there are solid transitions. And the JMP command code is four byte, it contains the transition address recorded by the backward - the younger byte for the younger address and the code of the transition command 940C

0000002B: BE1F OUT 0X3F, R1 Out to I / O Location

Recording this zero to 0x3F address if you see the I / O View column, then you will see that 0x3f address is the address of the SREG - Flag Register Controller Register. Those. We reset the SREG to run the program at zero conditions.

1 2 3 4 + 0000002C: E5CF LDI R28.0X5F LOAD IMMEDIATE + 0000002D: E0D4 LDI R29.0x04 Load Immediate + 0000002e: BFDE OUT 0X3E, R29 OUT TO I / O Location + 0000002F: BFCD OUT 0x3D, R28 Out to I / O Location

0000002C: E5CF LDI R28.0X5F LOAD IMMEDIATE + 0000002D: E0D4 LDI R29.0x04 Load Immediate + 0000002e: BFDE OUT 0X3E, R29 OUT TO I / O Location + 0000002F: BFCD OUT 0x3D, R28 Out to I / O Location

This is the loading of the stack pointer. Directly shipping in I / O registers can not, only through the intermediate register. Therefore, first LDI in the intermediate, and then from there Out in I / O. I will also tell you more about the stack. In the meantime, it is known that this is such a dynamic memory area, hanging in the end of RAM and keeps addresses and intermediate variables. Now we pointed out where we will have a stack.

00000032: 940C0041 JMP 0x00000041 JUMP

Jump to the Saaaeaeee End of the program, and there we have a ban of interrupts and looping tightly by itself:

1 2 +00000041: 94F8 Cli Global Interrupt Disable +00000042: CFFF RJMP PC-0X0000 Relative Jump

00000041: 94F8 Cli Global Interrupt Disable +00000042: CFFF RJMP PC-0X0000 Relative Jump

This is in case of unforeseen circumstances, such as output from the Main function. From such a loop, the controller can be displayed either with a hardware reset, or that is likely, discharge from the watchdog dog - Watchdog. Well, or, as I said above, correct these places in Hex editor and routing where we have a soul. Also pay attention to the fact that there are two types of JMP and RJMP transitions The first is a direct transition to the address. It takes four bytes and can make a direct transition throughout the memory area. The second type of transition - RJMP - relative. His team takes two bytes, but the transition it does from the current position (addresses) by 1024 steps forward or backward. And in its parameters, the offset from the current point is indicated. Used more often, because It takes two times less space in flush, and long factors are rarely needed.

1 +000034: 940c0000 JMP 0x00000000 JUMP

00000034: 940C0000 JMP 0x00000000 JUMP

And this is a jump at the very beginning of the code. Restart a kind. You can check, all the vectors jump here. From this output - if you allow you to allow interrupts (they are prohibited by default) and you will be interrupted, but there is no handler, then there will be a program reset - the program will throw the program at the very beginning.

Main function. Everything is similar, you can even not describe. Looking just to the registers already calculated the number. Preprocessor compiler taxis !!! So no "magic" numbers!

1 2 3 4 5 6 7 8 9 10 11 12 <

00000036: E383 LDI R24.0X33 LOAD IMMEDIATE +000037: B989 OUT 0X09, R24 OUT TO I / O Location 15: UBRRH \u003d HI (Bauddivider); +000038: BC10 OUT 0x20, R1 OUT TO I / O Location 16: UCSRA \u003d 0; +000039: B81B Out 0x0b, R1 Out to I / O Location 17: UCSRB \u003d 1<

And here is the jamb:

1 2 3 + 0000003E: E080 LDI R24.0X00 LOAD IMMEDIATE + 0000003F: E090 LDI R25.0X00 LOAD IMMEDIATE +00000040: 9508 RET SUBROUTINE RETURN

0000003E: E080 LDI R24.0X00 LOAD IMMEDIATE + 0000003F: E090 LDI R25.0X00 LOAD IMMEDIATE +00000040: 9508 RET SUBROUTINE RETURN

It is asked why this compiler adds such a topmaster? And this is nothing but Return 0, then we have identified as int Main (Void). So I won more than four bytes do not understand what :) And if you do a Void Main (Void), it will only be RET, but varning will be. What they say we do not return anything to the Main function. In general, do it like you :)

Complicated? It seems to be no. I skip step-by-step performance in the disassembler mode and the pokery as the processor performs individual instructions, which happens with registers. How to move on commands and final looping.

Continuation follows in a couple of days ...

Offtop:
Alexei78. Gang a fixing plugger for firefox facilitating navigation in my site and forum.
Discussion and download

Ministry of Education and Science of the Russian Federation

State educational institution

higher professional education

"St. Petersburg State

Naval Technical University "

E. V. Korotitsky, Yu. E. Korotitskaya

Basics of SI Language for AVR Microcontrollers

Tutorial

St. Petersburg

1. Basics of C language for microcontrollers AVR

Universal language C was developed as a tool for writing an UNIX operating environment.

Language with supports procedural-oriented programming paradigm, i.e. Paradigm - interrelated set of procedures.

For the Si language, the laconicity is characterized by a modern set of execution flow control, data structures and an extensive set of operations.

    1. Preprocessor of the language of his team

The preprocessor (macroprocessor) is an integral part of the SI language that processes the source code of the program before it passes through the compiler. The preprocessor reads the lines of text and performs the actions defined by the command lines. If the first character in a string other than a space is #, then such a string is considered by the preprocessor as a team. Command lines are called directive preprocessor.

Preprocessor compiler CodeVisionavReakes several directives. In tab. 1 is given to their brief description.

Table. 1 CodevisionavR compiler preploitor preprocessors

Directive

Purpose

Used to include in the program

another file

Used to replace some lexical units of the SI language to others, as well as to generate macros

Used to cancel the #Define directive

Used for conditional compilation

Used to change the built-in macros _line_y_file_

Allows you to stop the compilation and display error message

Used to include in the source assembler code

Allows special compiler directives

All preprocessor directives begin with a sign #. After the preprocessor directives, the point with comma is not put.

      1. #Include directive

Example:

Directive # include.

#InClude "file name" and #include<имя_файла>

File nameconsists of the file name.

Directive # include.is widely used to enable so-called header files in the program (extension files . h.), containing the definitions of peripheral devices and interruption vectors of the microcontroller used, prototypes of library functions, prototypes of functions defined by the user, and so on.

#Include "file_name.h"

      1. #Define, #Uldef directives

Directive # define.it serves to replace frequently used alone lexical units of the SI language (constants, keywords, operators or expressions) to other, so-called identifiers. Identifiers replacing text or numerical constants call named constants. Identifiers that replace program fragments are called macro definitions and macro definitions may have arguments.

Directive # define.has two syntactic forms:

#Define text identifier

#Define identifier (parameter list) text

Before compiling a preprocessor program in accordance with the Directive # define.replace all identifiers encountered in the program to match the text.

Example:

#Define A 15 #Define in (a + 20) // These directives will be replaced in the text of the program

each identifier A to the number 15, and each identifier in the expression (15 + 20) together with its surrounding brackets.

Example:

#Define x (A, B, C) ((a) * (b) - (c)) // Preprocessor In accordance with this directive, the fragment y \u003d x (k + m, k-m, n) will be replaced; On a fragment


Modern amateur is impossible to imagine without microcontrollers, and this is obvious. In recent decades, microcontrollers of various manufacturers have become widespread in different spheres of human activity. Often they can be found in the most unexpected devices and structures. We are witnessing computerization and automation of the processes around us. The truth is that, without knowledge of the basics of programming, creating modern competitive devices has become almost impossible ...

If you read this article, you probably had a desire to understand how microcontrollers work, and most likely questions appeared:

4. What literature to study?

Let's try to answer these questions.

1. What microcontroller choose to work?

8-bit microcontrollers are very popular with radio amateurs PIC MICROCHIP TECHNOLOGY and AVR. ATMEL, 16-bit MSP430. TI, as well as 32-bit microcontrollers, architecture Arm.

In industry, somewhat differently, the first place with a big margin occupies Renesas Electronics. on the second Freescale, on the third Samsung, then go Microchip. and TIfurther all the others.
Popularity is determined by the price and accessibility, the availability of technical information and the cost of software accompaniment play a considerable role.

We will learn 8-bit AVR microcontrollers, families ATMEGA 8 and 16 series. The choice was determined, again accessibility, the presence of many amateur developments, a huge number of educational material. The presence of a variety of built-in components and the functionality of this family.

2. What is the use of the development environment for programming the selected microcontroller?

For AVR, different integrated development environments (IDE, Integrated Development Environment) have been created.
IDE - This is a software system used by programmers to develop software (software), which includes:
text editor,
compiler and / or interpreter,
assembly automation tools,
Debugger.

The most common of them AvrStudio, Atmelstudio, WinAvr, CodeVision, IAR Embedded Workbench.
In order to write programs, we will use free IDE ATMELSTUDIO version 6 and higher.
You can download Atmel Studio from the official site after registration (registration is absolutely free and does not oblige anything!)

AtmelStudio allows you to create projects, and write programs both in the assembler and on si.

Initially, there is always a question: what programming language to choose to write effective programs?

I will answer simple: you need to be able to write at least two languages \u200b\u200bassembler and si. The assembler is simply necessary when you need to write quick and compact subroutines and macros, various device drivers. But when it is required to create a bulk project built on complex algorithms, without knowing Si can be spent a lot of time, especially in the debugging process, and if there is a desire to transfer to another platform, for example PIC18, or STM, may become an intractable problem.
In addition, hardware computing platforms now appeared Arduino.Working with which requires knowledge of the SI ++ language.
Therefore, we will write programs both in the assembler and si.

To clearly see the result of your work without using a soldering iron or a bullboard enough to install the program Proteus..

3. How to flash the controller, and what additional devices and axes are needed for convenient work with them?

We use Daturian. In addition, you will need to purchase dumping cards, the power supply with output voltage is 5 volts. It is possible to use as a power supply with small ripples by applying a 5 volt stabilion.
Perhaps over time, we will offer a project to build a debug board.

4. What literature to study?

But, for example:
Practical programming AVR on assembler. Revich, 2011.
1000 and one microcontroller scheme. 1-2. Rumik, 2010-2011
10 practical devices on MK AVR Book 1-2. Kravchenko, 2008-2009
Device developer tutorial at AVR MK. Belov, 2008.
MK AVR families TINY and ATMEGA. Efstifeev, 2008.
CodeVisionavr. Handbook for beginners. Lebedev, 2008.
Microprocessor control of devices, thyristors, relays. Belov, 2008.
Analog interfaces MK. Steward, Ball, 2007
Create devices on MK AVR. Belov, 2007.
MK AVR in amateur practice. Full analysis of attiny2313. Belov, 2007.
Network and firewall data exchange with MK. Go, 2007.
MK AVR. Workshop for beginners. Hartov, 2007.
Application AVR scheme, algorithms, programs. Baranov, 2006.
AVR microcontrollers. Introductory course. Morton, 2006.
Measurement, control and regulation using AVR. Trmpet, 2006.
Programming in language C for AVR and PIC MK. Shpak, 2006.
Designing devices on MK. Belov, 2005.
Mk is simple, volume 1-3. Frunze, 2002-2003
SI programming language, 2nd edition. Kernigan, Ritchch, 2009
Programming atmel microcontrollers in S. Prokopenko, 2012

5. Where on the Internet you can ask questions and receive specific answers?

You can ask questions on our or any other forum, where some way or otherwise affected the topic of microcontrollers. The main thing on the forums correctly formulate questions to clearly receive answers. Abstract questions are not welcome, and most likely instead of an answer you will get hard criticism, or your question will be ignored!

Now consider our favorite closer, ATMEGA microcontroller 8

8-bit high-performance AVR microcontroller with low consumption
Progressive RISC architecture
130 high-performance commands, most teams are performed for one clock cycle
32 8-bit general-purpose register
Fully static work
Approaching 16 mips (with a clock frequency of 16 MHz) performance
Built-in 2-cycled multiple

Non-volatile memory and data memory
8 Kbyte intrasystem programmable Flash Memory (in-System Self-Programmable Flash)
Provides 1000 Erase / write cycles
Additional sector of boot codes with independent blocking bits
Provided simultaneous read / write mode (Read-While-Write)
512 bytes eeprom
Provides 100,000 Erase / Record Cycles
1 Kbyte Built-in Sram
Programmable Lock Protecting User's Software

Built-in periphery
Two 8-bit timer / counter with a separate preliminary divider, one with a comparison mode
One 16-bit timer / counter with a separate preliminary divider and capture and comparison modes
Real Time Counter with Separate Generator
Three channels PWM.
8-channel analog-to-digital converter (in TQFP and MLF enclosures)
6 channels with 10-bit accuracy
6-channel analog-to-digital converter (in PDIP housing)
4 channels with 10-bit accuracy
2 channels with 8-bit accuracy
Byte-oriented 2-wire serial interface
Programmable serial usart
SPI serial interface (lead / slave)
Programmable watchdog timer with separate built-in generator
Built-in analog comparator

Special microcontroller functions
Reset power supply and programmable detector short-term supply voltage
Built-in calibrated RC generator
Internal and external interrupt sources
Five low consumption modes: IDLE, POWER-SAVE, POWER-DOWN, STANDBY and ADC noise reduction

Conclusions I / O and Corps
23 Programmable I / O Lines
28-pin PDIP case, 32-pin TQFP housing and 32-pin MLF housing

Operating stress
2.7 - 5.5 V (ATMEGA8L)
4.5 - 5.5 V (ATMEGA8)

Operating frequency
0 - 8 MHz (ATMEGA8L)
0 - 16 MHz (ATMEGA8)

differences atmega16 from 8
16 Kbyte Intrasthemternally Programmable Flash Memory (in-System Self-Programmable Flash)

JTAG interface (compatible with IEEE 1149.1)
The ability to scan the periphery that meets the JTAG standard
Enhanced built-in debug support
Programming via JTAG Interface: Flash, Memory EEPROM, Jumpers and Bits Lock

Four Channel PWM / PWM

8-channel 10-bit analog-to-digital converter
8 asymmetric channels
7 differential channels (only in the TQFP case)
2 differential channels with a programmable gain in 1, 10 or 200 times (only in the TQFP case)

Six low consumption modes: IDLE, POWER-SAVE, POWER-DOWN, STANDBY, EXTENED STANDBY and ADC noise reduction

32 Programmable I / O Lines

40-pin PDIP housing and 44-pin TQFP housing

Atmelstudio.

If you are just starting, you need to download and install the ATMELSTUDIO program from the official page atmel.com
After installing the ATMELSTUDIO program, you can proceed to the creation of the project.
Project - This is your program that you will write, debug and flash, after compiling, in memory of the microcontroller.

To create a project, you need to open a program, this screensaver appears,

and the project creation page opens

To create a new project, you need to click on "NEW PROJECT ..."
In this case, a new window will open where you can select the programming language, the project name, its location, the name of the package with the project files and the ability to create a catalog for further use in other cross-projects. To create a project where we will program in the assembler, you need to choose - Assembler.After that, change the name of the project, its location, and choose OK.

The following window will appear

Choose "MEGAAVR, 8-BIT" and find the microcontroller you need, we chose ATMEGA8. On the right side of the screamer appears a list of devices running with this microcontroller, one of which we can connect. Choose OK.

The text editor page appears, which allows you to edit and debug the program. While the page is clean, specified time and date of creation and name of the project file, username. There are optional I / O devices window, program compiling reports. now we


we can program in assembler.
Similarly, a project for programming in Si language is created. Kiselev Roman, May 2007 Article Updated May 26, 2014

So, what is this microcontroller (hereinafter MK)? This, relatively speaking, a small computer located in one integral chip. It has a processor (arithmetic-logical device, or alu), flash memory, eeprom-memory, many registers, I / O ports, as well as additional "beams", such as timers, counters, comparators, USARTs, etc. . The microcontroller is loaded after powering and starts to execute the program recorded in its Flash memory. In this case, it can control the most diverse external devices through the I / O ports.

What does this mean? This means that in the MK you can implement any logical scheme that will perform certain functions. This means that the MK is a microcircuit, the internal content of which, in fact, we create themselves. What allows, having bought a few completely identical MK, collecting completely different schemes and devices on them. If you want to make any changes to the operation of the electronic device, you will not need to use a soldering iron, it will only be enough to reprogram the MK. At the same time, it is not necessary to even remove it from your Device if you use AVR, since these MK maintain intrahemable programming. Thus, microcontrollers eliminate the gap between programming and electronics.

AVR is 8-bit microcontrollers, i.e., their Alu may permanently perform the simplest operations with 8-bit numbers. Now it's time to talk about what MK we will use. I work with ATMEGA16 MK. It is very common and you can buy it almost in any radio component store somewhere for 100 rubles. If you do not find it - then you can buy any other MK of the MEGA series, but in this case you have to look for a documentation for it, since the same "legs" of different MK can perform different functions, and, by connecting, it would seem, That's right, all conclusions, you may have a working device, and maybe only the cloud of stinking smoke. When buying ATMEGA16, check that it be in a large 40-cut Dip-enclosure, and also buy a panel to it in which it can be inserted. To work with it, additional devices will also need: LEDs, buttons, connectors, etc.

ATmega16 has a very large number of a wide variety of features. Here are some of its characteristics:

  • Maximum clock frequency - 16 MHz (8 MHz for ATMEGA16L)
  • Most teams are performed for one beat
  • 32 8-bit operating registers
  • 4 full-fledged 8-bit input / output ports
  • two 8-bit timer / meter and one 16-bit
  • 10-bit analog-to-digital converter (ADC)
  • internal clock generator for 1 MHz
  • analog comparator
  • sPI, I2C, TWI, RS-232, JTAG interfaces
  • insurance programming and self-programming
  • pulse modulation module (PWM)

The complete characteristics of this device, as well as instructions for their application, can be found in the directory (Datasheet) to this MK. True, he is in English. If you know English, then definitely download this datasheet, there is a lot of useful in it.

I will finally begin to go. I recommend to make a special maquetting fee for a microcontroller, on which it will be possible to collect any electrical circuit with a microcontroller. Using such a board will greatly facilitate work with MC and speed up the process of studying its programming. It looks like this:

What will you need?

First, the fee will be required. I bought a ready-made radio component store for 115 rubles. Then all the necessary details soldered to it. It turned out an incredibly convenient thing at which you can collect any electrical circuit in a matter of minutes by overclocking the loops and installation of microcircuits and indicators.

To connect the elements of the circuit, it is very convenient to use loops, at the ends of which connectors are installed. These connectors are put on the "legs" sticking next to each port of MK. The microcontroller should be installed in the panel, and not solder to the board, otherwise it will be very difficult to remove it in case you will raise it. Below is the Cocolevka MK ATMEGA16:

Let us explain what legs are now interested.

  • VCC - Food here (4.5 - 5,5 V) from a stabilized source
  • GND - Earth
  • RESET - Reset (with low voltage)
  • Xtal1, Xtal2 - a quartz resonator connects here
  • PA, PB, PC, PD - I / O ports (A, B, C and D, respectively).

As a power source, you can use everything that issues 7-11 in DC. For stable operation, MK need stabilized meals. As a stabilizer, the 7805 series chips can be used. These are linear integral stabilizers, the input of which is supplied 7-11 in a constant non-stabilized current, and the output is obtained 5 in the stabilized. Before 7805 and after it, you need to put filtering capacitors (electrolytic for filtering of low frequency interference and ceramic for high). If it is not possible to find a stabilizer, then you can use a battery for 4.5 V as a power source from it, MK must be used directly.

Below I will give the MK connection scheme:

Let's see now what for what.

BQ1 is a quartz resonator setting the operating frequency of MK. You can put any up to 16 MHz, but since we plan to work in the future and with the COM port, I recommend using the resonators to the following frequencies: 14,7456 MHz, 11,0592 MHz, 7,3725 MHz, 3,6864 MHz or 1 , 8432 MHz (later becomes clear why). I used 11,0592 MHz. It is clear that the more frequency, the higher the speed of the device.

R1 is a tightening resistor that supports voltage 5 V at the RESET input. Low voltage level at this input means reset. After reset, the MK is loaded (10 - 15 ms) and begins to perform the program again. Since this is a high-quality entrance, it is impossible to leave it "chatting in the air" - a small tip on it will lead to an unforeseen discharge of MK. It is for this that I need R1. For reliability, I also recommend installing C6 capacitor (no more than 20 microf).

SB1 - reset button.

The quartz resonator and the filter capacitor C3 should be located as close as possible to the MC (not more than 5-7 cm), since the vendors may occur in the wires, leading to malfunctions in the operation of the MC.

The blue rectangle in the scheme arouses the proprietary programmer. It is convenient to perform in the form of a wire, one end of which is stuck in the LPT port, and the other in a certain connector next to the MK. The wire should not be excessively long. If there are problems with this cable (usually do not occur, but anything happens) then you will have to solder the Altera Byteblaster adapter. About how to do this is written in the description of the Avreal programmer.

Now, when we figured out with the gland, it's time to go to the software.

AVR programming has several developments. First, it is AVR Studio - the official programming system from ATMEL. It allows you to write on the assembler and debug programs written in assembler, C and C ++. IAR is a commercial programming system on C, C ++ and assembler. WinAvr - Compiler with open sources. AtmanAVR is a programming system for AVR with an interface, almost "one to one" is the same as Visual C ++ 6. AtmanAVR also allows you to debug programs and contains many auxiliary functions that facilitate code writing. This programming system is commercial, but, according to a license, it can be used for a month "Nakhalyava".

I suggest starting work with IAR as the most "transparent" development environment. In IAR, the project is entirely created by "handles", respectively, making several projects, you will already clearly know what it means every line of the code and what will happen if it is changed. When working with AtmanAVR, you will have to either use a pre-created template that is very bulky and difficult to understand for a person who has no experience, or have many problems with header files when assembling the project "from scratch". Having understood with IAR, we will later consider other compilers.

So, for beginnings, раздar. It is very common and his finding should not be a problem. By downloading anyone IAR 3.20, set the compiler / working environment, and run it. After that, you can start work.

Launching IAR, choose file / New / Workspace, Choose the path to our project and create a folder for it and give a name, for example, "Prog1". Now create a project: Project / Create New Project ... We also call it - "Prog1". Click right-click on the project header in the project tree and select "Options"

Here we will configure the compiler for a specific MK. First, you need to select the ATMEGA16 processor type on the Target tab, on the Library Configuration tab, install the Enable Bit Definitions In I / O-Include Files (so that you can use the names of the bits of various MK registers in the program code), select the library type / EU ++. In the ICCAVR category, you need to install the Enable MultiByte Support tick on the Optimization tab, and turn off the optimization on the Optimization tab (otherwise it will spoil our first program).

Next, choose the category XLink. Here you need to determine the format of the compiled file. Since now we specify options for debug mode (Debug), what is written in the title, then you need to receive a debug file at the output. Later we will open it in Avr Studio. To do this, select the extension.cof, and the type of file is Ubrof 7.

Now click OK, then change Debug on Release.

We go into options again, where all the parameters except Xlink are exhibiting the same. In XLink, change the extension to HEX, and the file format on Intel-Standart.

That's all. Now you can proceed to writing the first program. Create a new source / text and score the following code in it:

#Include. "iom16.h" short unsigned int i; void. Main ( void.) (DDRB \u003d 255; portb \u003d 0; while(1) { if. (Portb \u003d\u003d 255) portb \u003d 0; eLSE. Portb ++; for (i \u003d 0; i

File "iom16.h" is in the folder (C: \\ Program Files) \\ Iar Systems \\ Embedded Workbench 3.2 \\ AVR \\ INC. If you are using another MK, for example, ATMEGA64, then select the file "IOM64.h". In these header files, information about MK is stored: the names of the registers, bits in registers, the names of interrupts are determined. Each separate "leg" of the port A, B, C or D can work either as an input or as an output. This is determined by the DATA Direction Register (DDR) registers. 1 makes the "leg" output, 0 - input. Thus, exhibiting, for example, DDRA \u003d 13, we make the outputs of the "legs" PB0, PB2, PB3, the remaining - inputs, because 13 in binary code will be 00001101.

PortB is a register in which the state of the "feet" of the port is determined. Recovering there 0, we exhibit at all outputs voltage 0 V. Next is the endless cycle. When programming MK always make an infinite loop, in which the MK performs any action until it drops or until interruption occurs. In this cycle, they write as it were for the "background code", which MK performs in the latter order. This may be, for example, output information on the display. In our case, the contents of the PORTB register increase until it is filled. After that, everything starts first. Finally, the for ten thousand cycles. It is needed to form a visible delay in switching the state of the port V.



Now we save this file in the project folder as prog1.c, copy to the folder with the project file om16.h, select Project / Add Files and add "iom16.h" and "prog1.c". Select Release, click F7, the program is compiled and a message should appear:


Total Number of Errors: 0
Total Number of Warnings: 0

I will give a photo of your programmer:

Download Avreal programmer. Copy it (avreal32.exe) to the RELEASE / EXE folder, where the prog1.hex file must lie. Let's supply the MK, connect the programmer cable. We open Far Manager (it is most convenient to flash MK), go to this folder, press Ctrl + O. Since we have a brand new MK, you get stuck

avreal32.exe + mega16 -o11.0592mhz -p1 -fblev \u003d 0, jtagen \u003d 1, cksel \u003d f, SUT \u003d 1 -W

Do not forget to correctly specify the frequency if you use not 11059200 Hz! At the same time in the MK are stitched by the so-called. Fuses - registers controlling its work (using an internal generator, JTAG, etc.). After that, he is ready for receiving the first program. The programmer is transmitted as parameters used by the LPT port, frequency, file name, and others (all of them are listed in the description to Avreal). We recruit:

Avreal32.exe + mega16 -o11.0592mhz -p1 -e -w -az -% prog1.hex

In case of proper connection, the programmer will report successful programming. There is no warranty that it will work the first time (when you first call the program). I myself can be programmed from the second time. Perhaps the LPT port is buggy or appear in the cable. If you have problems, carefully check your cable. In my own experience I know that 60% of faults are associated with a lack of contact in the right place, 20% - with the presence in an unnecessary and 15% - with an erroneous soldering not to that. If nothing happens, read the description for the programmer, try to assemble byte blaster.

Suppose you all work. If you now connect eight LEDs to the port in MK (do it in the disabled state of the MK, and it is desirable consistently with the LEDs to include resistors in 300-400 Ohm) and serve me, then a small miracle will happen - "Wave" will run!

© Kiselev Roman
May 2007.

Microcontrollers are small, but at the same time very convenient devices for those who wish to create various amazing robotic or automated things at home. Within the framework of this article, AVR programming for beginners, various aspects and nuances of this process will be considered.

general information

Microcontrollers can be found everywhere. They are in refrigerators, washing machines, phones, machines in production, smart homes and in many different technical devices. Their widespread use is due to the possibility of replacing more complex and large-scale analog schemes of devices. Programming MK AVR allows you to provide autonomous control over electronic devices. These microcontrollers can be represented as the simplest computer that can interact with external equipment. So, it is under force to open / close transistors, receive data from sensors and display them on the screens. Also, microcontrollers can also carry out different input processing like a personal computer. If you master the AVR programming from scratch and reach the level of a professional, then almost limitless possibilities will open to control various devices using I / O ports, as well as changes in their code.

A little about avr.

As part of the article, a family of microcontrollers produced by ATMEL will be considered. They have pretty good performance, which allows them to use them in many amateur devices. Widely applied in industry. Can be found in this technique:

  1. Domestic. Washing machines, refrigerators, microwaves and so on.
  2. Mobile. Robots, means of communication and so on.
  3. Computing. Peripheral control systems, motherboards.
  4. Entertaining. Decorations and children's toys.
  5. Transport. Safety and engine control systems.
  6. Industrial equipment. Machine control systems.

This, of course, not all spheres. They are used where it is profitable to use not a set of control chips, but one microcontroller. This is possible due to low power consumption and programs are used languages \u200b\u200bwith and assembler, a bit changed under the microcontroller family. Such a change is necessary due to weak computing capabilities, which are calculated, as a rule, in tens of kilobytes. AVR programming without studying these languages \u200b\u200bis not possible.

How to get your first microcontroller?

AVR programming requires:

  1. Availability of the necessary development environment.
  2. Actually, microcontrollers themselves.

The second paragraph will consider in more detail. There are three possibilities to get a desired device:

  1. Buy directly the microcontroller itself.
  2. Get a device as part of a designer (for example - Arduino).
  3. Collect a microcontroller yourself.

In the first point there is nothing complicated, so we will immediately turn to the second and third.

Get a device in the designer

As an example, the famous Arduino will be selected. This is a part-time convenient platform for the rapid and high-quality development of various electronic devices. Arduino includes a specific set of components for work (there are various configurations). It is necessarily an AVR controller. This approach allows you to quickly start developing the device, does not require special skills and skills, has significant opportunities in terms of connecting additional boards, as well as on the Internet, you can find a lot of information on questions of interest. But it was not without minus. By buying Arduino, a person deprives himself a better to plunge into AVR programming, it is better to know the microcontroller, the specifics of its work. Also, negative adds a relatively narrow line of models, which is why it is often necessary to buy fees for specific tasks. A feature is also the fact that programming on the "SI" here is quite different from the standard form. Despite all its drawbacks, Arduino is suitable for studying beginners. But it is not necessary to abuse.

Independent assembly

It should be noted that AVR microcontrollers are distinguished by sufficient friendly newcomers. You can collect them yourself with affordable, simple and cheap components. If we talk about the pros, then this approach allows you to better familiarize yourself with the device, choose the necessary components yourself, customizing the final result for advanced requirements, the use of standard programming languages \u200b\u200band low cost. Of the minuses, only the complexity of self-assembly can be noted when it is carried out for the first time, and there is no necessary knowledge and skills.

How to work?

So, let's say that the question with the microcontroller decided. Next will be considered that it was purchased or bought independently. What else is needed to master the AVR programming? For this purpose, the development environment is needed (a regular notebook is suitable as a basis, but I recommend to stop at NOTEPAD ++). Although there are other programs for AVR programming, the provision provided will be able to cope with all the requirements. We also need a programmer. It can be purchased at the nearest store, order on the Internet or collect yourself. It does not hurt and the printed circuit board. It is not obligatory, but its use allows you to save your nerves and time. Also bought / created independently. And the last is a power source. For AVR, it is necessary to ensure voltage to 5V.

Where and how to learn?

Create masterpieces from scratch will not work. Knowledge, experience and practice are needed here. But where to take them? There are several ways. Initially, you can independently search for the necessary information in the global network. You can write to programming courses (remote or full-time) to obtain basic work skills. Each approach has its advantages. So, the programming courses will be cheaper, and maybe free. But if something fails, then with full-time activities, an experienced developer will be able to find the cause of the problem. It will also not be superfluous to familiarize yourself with the literature that is in free access. Of course, it will not work out on some books, but get basic knowledge about the device, programming on the "SI", "assembler" and other working moments you can.

I / O ports

This is an extremely important topic. Without an understanding of how the I / O ports work, intrahemable AVR programming is possible at all. After all, the interaction of the microcontroller with external devices is carried out precisely when they are mediated. At first glance, the novice may seem that the port is a rather tangled mechanism. To avoid such an impression, we will not consider the scheme of his work in detail, but I only get a general idea of \u200b\u200bthis. Consider the program implementation. As an example of the device, the ATMEGA8 microcontroller was selected - one of the most popular from the entire AVR family. The I / O port represents three registers that are responsible for its work. At the physical level, they are implemented like legs. Each of them corresponds to a certain bit in the control registry. Each leg can work both to enter information and for its output. For example, you can hang the LED ignition function or the pressing of the button pressing the button. By the way, the three registers, which were said, is: Portx, Pinx and DDRX. Each of them is eight-bit (do not forget that we consider ATMEGA8). That is, one bit is engaged in a certain leg.

Work registers

The most significant in terms of orientation is the DDRX managing. It is also eightic. The values \u200b\u200bfor it can be recorded 0 or 1. How does the controller work change when using zeros and units? If in a specific bit, set 0, then the feet corresponding to it will be switched to the input mode. And it will be possible to read the data that go from external devices. If you set 1, the microcontroller will be able to control something (for example, give an order to transistor to skip the voltage and light the LED). The second most important is Portx. It is engaged in the leg status control. Let's consider an example. Suppose we have an output port. If we set a logical unit in Portx, the signal from the microcontroller is sent to the control device to start work. For example, light the LED. When setting zero, it will quit. That is, working with the DDRX manager register constantly, there is no need. And finally, let's talk about PINX. This register is responsible for displaying the status of the controller's legs when it is configured to the input status. It should be noted that PINX can work exclusively in reading mode. Write nothing to write. But here to read the current status of the leg is no problem.

Work with analogs

AVR are not the only microcontrollers. This market is divided between several large manufacturers, as well as between numerous Chinese imitating devices and homemakers. In many ways, they are similar. For example, PIC / AVR programming is not very different. And if there is an understanding of something one, then it will be easy to understand everything else. But we recommend starting the way with AVR due to its competent structure, friendliness to the developer and the presence of a large number of auxiliary materials, which is why the development process can be significantly accelerated.

Safety technique

When AVR microcontrollers are programmed on "SI" or on "assembler", it is necessary to work very carefully. The fact is that by setting a definite combination of registers and changing the internal settings, you can safely block the microcontroller. This is especially true of FUUZ. If there is no confidence in the correctness of your actions, it is better to abandon their use. The same applies to programmers. If you buy factory equipment, it will flash microcontrollers without problems. When assembling with your own hands, a sad situation may occur at which the programmer blocks the device. This can occur both because of the error in the program code, and through problems in it. By the way, about another one (this time positive) moment, which was previously mentioned, but was never revealed completely. Now almost all modern microcontrollers have the function of intra-hem programming. What does it mean? Suppose that the device was collapsed on the board. And in order to change it to the firmware, now it is not necessary to get enough to get enough, because such intervention can damage the microcontroller itself. It is enough to connect to the appropriate conclusions and reprogram it when it is mediated.

What model to choose?

As part of the article, ATMEGA8 was considered. This is a rather mediocontrol microcontroller for its characteristics, which, nevertheless enough for most crafts. If there is a desire to create something large-scale, then you can take a kind of monsters like ATmega128. But they are designed for more experienced developers. Therefore, if there is no sufficient experience, it is better to start with small and simple devices. In addition, they are significantly cheaper. Agree, one thing accidentally block the microcontroller for a hundred rubles, and completely different - for half a thousand. It is better to fill your hand and deal in various aspects of functioning so that in the subsequent not to lose significant amounts. Initially, you can start with ATMEGA8, and then navigate your needs.

Conclusion

So the topic of AVR programming in the most common features was considered. Of course, you can still talk about many things. So, for example, the marking of microcontrollers was not considered. And it can say a lot. So, mostly microcontrollers operate on voltage in 5V. Whereas the presence, for example, the letters L can say that only 2.7 V. is sufficient for the device, as you can, sometimes the knowledge of the labeling can play a very important role in terms of correct and durable devices. The time of functioning of microcontrollers is also an interesting topic. Each device is designed for a certain period. So, some can work out a thousand hours. Others have a warranty reserve at 10,000!