The order of programming microcontrollers avr. Self-programming of AVR microcontrollers. How to flash the controller, and how to add accessories and accessories needed for manual work with them

Golovna / Contacts


What is the program
What is the algorithm

I, maybe, hurried a little, naming the article "Programming AVR microcontrollers - the first step". Shvidshe, tsia stattya, like all attacks, is a small crack in the world of microcontrollers. We will have a lot of such "crooks", until we reach the moment when we can say: "The microcontroller is the last crochet". Ale y tse, better for everything, in the cloak of fantasy - you can’t touch it, - the world of microcontrollers is constantly developing and fully developed. Our task is to develop the first step, the logical result of such a first step, that selected design on the microcontroller was independently developed. And far - far away the skin popliv on their way from the full knowledge on the site. The first and final article can be called like this: "Programming microcontrollers - the last step of the first step"(required, as if bending down!).
And so let's get started.

Three minds for those who want to master the microcontroller

1. Bazhannya and arrogance at the reach of the set goal
This point, like on me, is the worst. If there is no bazhannya, and if there is more than a fussy bazhannya, then there will be no result. Don't shy away from the head and don't rattle, show napoleglivistvo - and everything will be done (and not only at the right mastering of microcontrollers).
2. I will build a microcontroller.
Important factor. Aje, wait, don’t know how to power the microcontroller, what fault you can have in your order, as everything works, we can’t beat all the capabilities of the microcontroller, change everything, on what fault is building.
It is possible and not varto to dig deeply at the "inside" of the microcontroller, but more importantly, so be it - asi, mi know guilty (sim mi and occupied on the sides of the site - vichati asi work with the microcontroller).
3. Knowledge of microcontroller control commands.
The microcontroller, like a dog (such a cicada povnyannya), will marvel at us with sensible eyes and wag its tail until we give it a command to vikonannya yakihos diy.
There are more than 130 commands for the mind of a smart dog, a smart microcontroller.
So the axis, so that the microcontroller is not only wagging its tail, but having victoriously needs us to work, it is necessary to know the commands to control it.
I want to say, for the cob you don’t need to cram all 130 commands, enough knowledge and half (and learn less). Before that, a lot of teams duplicate one another. The more commands we know, the more efficient we can be handled by the microcontroller and the more beautiful and elegant it looks like the program pen.

Otzhe, if you have a hard time mastering the microcontroller, then continue.

What is the program

How much you put on the microcontroller program- you create the program for the microcontroller yourself.

Program(in translation, the word means - “attribution”) - a forward description of the possible subdivisions.

For example, we want the microcontroller to shine with light. It’s easy to finish the task, but in order for the microcontroller to finish, we, first, step by step, describe all the functions of the microcontroller. write a program, Yaku vin is guilty of vikonati for taking away the result that is necessary for us - a light that blinks.
Shchos on a kshtalt like this:
♦ Light up the light:
- Adjust the view of the microcontroller, before any connection of the light, for work on the view of information
- give a logical riven to this visnovok, which will allow you to light the light
♦ Check the current hour:
- go to the subprogram, which forms a pause (as it is necessary to "prescribe")
- By the end of the subprogram pause turn to the main program
♦ Turn off the light:
- apply for the microcontroller's appearance a logical line to turn off the light
and so far.

With a term Program indistinctly overlapping another term - Algorithm.

What is the algorithm

Algorithm- A set of instructions that describe the order of action to achieve the required result.

What about the program reports write down everything microcontroller, then algorithms, - mi we can see the order microcontroller, on the basis of which we will create a program. By analogy with the butt of the butt:
♦ Light up the light
♦ Check the current hour
♦ Turn off the light
and so far.
in such a manner, algorithm - the same program. The more carefully and thoughtfully the algorithm will be created, the easier it is to create the program.

Mova programming

It’s a pity, as we can give commands to a beloved dog with my human, then the connection with the microcontroller can be mine, as I understood it - my microcontroller commands.

Commands for the microcontroller may look like a set of ones and zeros, such as:
00110101 011000100
so called - command codes, And the code of commands is tse mov, yak razumіє microcontroller. And in order to transfer our language of reference to the language of the microcontroller - qi sets of zeros and ones, use special programs.
The programs allow you to describe the order of work for the microcontroller more or less understandable for us, and then transfer the order to my understandable microcontroller, as a result of which there are so ranks machine code- Sequence of commands and instructions (your own zeros and ones) as well as understanding the microcontroller. The text of the program, written by the programmer, is called exit code. Transferring the program from the mov program (output code) to my microcontroller (machine code) is carried out translators. The translator translates the text of the program into machine code, so that we can then sign up for the riddle about the microcontroller.
For these programs, the order of operation of the microcontroller is described by a special mine - my programming.

Mova programming– the method of transferring commands, instructions, clear instructions to the microcontroller.

Three types of programming can be called:
movie programming low level
movie programming of a high level
Why they stink. And they stink of their closeness to the microcontroller.

At the dawn of the birth of microprocessor technology, programs were written in machine codes, so that the entire algorithm of the robot was sequentially written at the sight of zeros and ones. The axis, for example, could look like the program:
01010010
01000110
10010011
It is important, to tell a professional, to sort out such a combination of two digits. To make their lives easier, the programmers began to create the first movie programming. So the axis, the closer the language programming is to such a set of zeros and ones, the more the wines of the "low equal", and the farther away from them - the greater the "high equal".

The most wide-ranging software for microcontrollers:
- mova low equal - assembler
- language of high equanimity - C (Ci)
Let's marvel at the application of їхної відмініnostі (tsі apply abstract).
It is permissible for us to add two numbers: 25 and 35.
In machine codes, the command may look like this:
00000101 1101001
My low jealousy:
ADD Rd, Rr
My high jealousy:
25+35
Vіdminnіst mov low and high level is seen by an indefatigable eye.
Ale, let's dig in our glibshe butts. The butt of the machine code will not be analyzed, the shards of the wines are identical to the butt on Assembler. For its own sake, assembler commands and machine codes (commands), just so as not to get lost in zeros and ones, assign letters to abbreviations. Using the assembler command ADD Rd, Rr, we set the microcontroller to add two numbers, which are to be known (and for whom we must write them in front) - first Rd, another Rr, and place the result in Rd. As a matter of fact, let's set a more specific task for the microcontroller: take what you want to do and where to put the result. And here we practice without intermediary with the microcontroller.
The command of my high level: 25 + 35, a mathematical record for us, which is quiet our eye. But in this case, we can’t work directly with the microcontroller, we just set the task for you to add two numbers. The result and the sequence of events in this case will be the same as in the case of the assembler command: the first two numbers will be written down, then folded, and the result of the next rooms.
The first axis here is the head of the high and low level. As in Assembler we have control over the whole process (if we want more than that): we know how to write down two numbers, and we know if the result will be, then in the high level move we do not control the process. The program itself checks where to write down the numbers and where to save the result. Most of all, we don’t need to know, even if for us it’s a smut bag - the number 60 is on the way out. As a result, the programs on the high-level language have more reading (spirne nutrition), receivers for the eye (spirne nutrition) and less for the world - even if we don’t have to “crawl at all the dirks” and paint the skin of the microcontroller, the program will work later for us, if you compile її - translate the machine code. Ale, here is a minus. Two of the same algorithms are written in Assembler and in C, but after the transformation of them in machine code, they will be different: the program written in Assembler will be 20-40% shorter than the program written in C - the devil knows, such a way for C to achieve the result we need. І traplyayutsya vpadki, if you can't reach the movie of high equanimity and in the program in C roble the insertion of the code written in Assembler.

Programmers, as a rule, know a lot of new programming, creatively sharing their abilities and advances in one program. Well, for us, amateurs, we need to know if we want one language (for the cob), and we need to start (and I firmly believe in it) from a low-level move - Assembler.

program and data distribution (on the basis of classical architecture
von Neumann at the best computers, de memory is hard). Different tires for
tsikh areas of memory are significantly regretted by the program: data and
teams can turn around at the same time.

32 register of infamous recognition (RVN). Atmel was the first company, by far
appeared in the classical model of the enumeration nucleus, in a vicon-
no commands transfer data exchange between ALU and memory
middles at the sleeping memory. The introduction of RON in such a quantity (guess that in
architecture X 86 x 51 understand RON, like that,
vіdsutnya) in a number of vipadkіv allow vzagalі vіdmovity in vіd roztashuvannya glo-
global and local changes in RAM and type of stack stack, operations with
how to make it easier to harass the program. As a result, the structure of the
sampler program is approaching high level programs.
The truth is, it has led to a sort of simplification of the command system.
there are more of them for AVR, lower ones in other RISC-homelands (whether significant
part of the instructions are pseudonyms).

Flash-memory programs(10,000 erase/write cycles) possible
internal system reprogramming and capture through the last
the channel is right at the finished scheme. About the advances of such a journey, what a ninth becoming
ceremonially accepted, reportedly stated in at vednі.

Okrema region of energy-independent memory(EEPROM, 100,000 cycles
erase / write) to save data, with the possibility of recording programmable
a way or a zvn_shny zavantazhennya through the SPI-interface.

Built-in extensions for processing analog signals: analog
comparator and rich-channel 10-bit ADC.

watchdog timer, which allows you to automatically re-advance
controller through the intervals of the hour (for example, for the exit from
"sleeping" mode).

Latest SPI interfaces, TWI (I

C) that UART (USART), allow-

schі zdіysnyuvati vmіnі dannymі z more standard tsenіv і
other outbuildings (including such as personal computers)
hardware.

Timers with reinstallation and the possibility of choosing a dzherel rahunok-
of them pulses: as a rule, one or two 8-bit pulses and as a minimum one
16-bit, including can be processed in multi-channel mode 8-, 9-,
10-, 16-bit Pulse Width Modulation (PWM).

Possibility of work at clock frequency 0 Hz to 16-20 MHz.

Life voltage range 2.7 to 5.5 V(in some cases, 1.8 or
up to 6.0 V).

Numbers power saving modes, which are blown up by a bunch of knots,
scho zalishayutsya podklyuchenimi. Exit from "sleeping" regimes by watchdog
timer or for zovnіshnіmi interruptions.

Wake up life monitor- voltage drop detector (Brown-out
detection).

Here, far from all the features that are typical for different models are listed
AVR. With some other people we know better, and also in practice
Let's review the report. Ale back to back damo zagalnu characteristic
different families of AVR with a glance of their most important recognition.

AVR families

Have 2002 r. Atmel has launched the release of new 8-bit MK pyrodyns based on
AVR cores. From that hour, all MKs of this family are divided into three groups (subsimeist-
va): Classic, Tiny and Mega. MK family Classic (AT90S) xxxx) are no longer released;
found in virobnitstvі "zatrimalas" far away (simple, compact that
swidcode model) AT90S2313, ale and won bula in 2005. replaced by
ATtiny2313. All "classic" AVRs with first digits 2 and 8 in the name
models (which means the total memory of programs in kilobytes)
Tiny and Mega. For Mega pіd hour programming can be installed special
of the social bit of secularity, which allows without any changes
koristuvatisya programs created for the Classic family. Therefore, a number of applications
tsіy knіzі z by the method of simplification of the clad should be directed at the version for the family
classic.
Apply different types of cases, which have AVR microcircuits,
pointed to Fig. 1.1. More detailed information on this topic can be found at
addendum 1(Table A1.2), as well as the technical documentation for the annex.
It is significant that for amateur radio needs, the layout of the most convenient micro-
circuits in PDIP cases, but not all MK models vibrate in such cases.
All families can have two modifications: the letter "L" at the sign to say
about extensions, the living range is 2.7-5.5 V, the presence of such a letter means dia-
life span 4.5-5.5 V. When choosing a specific type of microcircuit, you need
respect, because the L-version at the same time also has less code,
greater than їх the maximum clock frequency is set to 8 MHz.
For "greater" versions, the maximum frequency is set to 16 or 20 MHz. Hocha yak
as a rule, when starting L-microcircuits with a voltage of 5 at frequencies up to 10-
12MHz
can work with a pressure of eating close to 3 V, sensibly, not at extreme
their frequency values), prote when designing high-pressure speakers
sled sled vrakhovuvat tsyu vimogu.
Chips Tiny can flash-ROM programs with a capacity of 1-8 kb and are available in
zdebіshkogo in buildings with 8–20 visnovkas (crim ATtiny28), so the stench is recognized as a dirty trick.
Designed for more simple and cheap outbuildings. Tse does not mean that it is possible
stі zavzhdi obmezhenі, nizh at the Mega family. So, for example,
ATtiny26 at a price less than 2 dollars to replace the timer with high-speed PWM
mode (in other models this is not possible), as well as an 11-channel ADC
I don’t work in differential mode, with regulation of the input subs

Part I. General principles and functions of the Atmel AVR

and vbudovanim dzherel reference voltage, which is typical for older mo-
ref. Chip ATtiny2313, as already mentioned, is a reduction.
well, a version of one of the most universal and handy "classic" AVR
AT90S2313.

Rice. 1.1. Apply different types of cases for MK AVR

The Mega family is equipped with a Flash-ROM with a program volume of 8–256 kB and a housing
yourself with 28-100 visnovkas. Zagalom MK tsієї groups more "tricks", lower
Tiny
functionality.
Tables with the main characteristics of the current Tiny and Mega models
the most running gears are induced in addendum 1. There is also given deakі zagalni tehnі-
Here are some characteristics of the AVR family. More reports can be taken.
information from the company's technical documentation, as available on the website
Atmel for skin model.
Okrim tsikh three families, on the basis of the AVR-core, specializations are produced
chips for robots with USB interface (AT90USB xxxx), let's say in-
CAN interface (AT90CAN xxx), for controlling RK displays (ATmega329 and other),
with a wireless interface IEEE 802.15.4 (ZigBee) for trade enterprises
deakі іnshі. Remaining hours of operation of the Tiny series microcontroller
Mega began to be released in versions from above small states (technology
picoPower with a voltage supply of 1.8 V, for example, the name MK series
added to the letter "P") and high temperature for use in automobiles
industry (version Automotive). The XMega family appeared with a strain
live 1.8-3.6 V, powered by swidcode (clock frequency up to 32 MHz),

Section 1. Overview of Atmel AVR microcontrollers

12-bit 16-channel ADC and 2–4 DAC channels
AVR stinks were daily), with UART channels and other last ones
portіv (moreover, it is possible to work offline, with
cores), introduced by the cryptography support, improved mode
picoPower and other "bells and whistles". Іsnuє also okreme family 32-times-
in-line MK AVR32, recognized for high-speed add-ons, such
how to process the video stream and recognize the images at the hour.

Features
practical vikoristannya MK AVR

When vikoristanny AVR blames low nutrition of a practical nature, igno-
ruvanya of which can sometimes lead to impracticality or failure of the
roystva (and deyakyh vipadkah - to make it impossible to program yoga).
For example, one of these problems is the ability to use EEPROM instead
at the wimican of life. Qiu and similar problems are reportedly reviewed by
vidpovidnyh divisions. We immediately sing on deyaky sleeping meals
inclusion of MK AVR.

About peace

MK AVR spozhivayut at an average of 5-15 mA
rіystv through visnovki MK). Spozhivaniy strum lie not only on the stage "on-
reliability" model, and also the type of clock frequency and voltage of life. In Fig. 1.2
a typical diagram of the fallow strum is induced by the supply voltage
nya that clock frequency for younger models of the Mega family.
3 fig. 1.2.
lowering the clock frequency for quiet vibrations, if the program is not running for an hour
critical. Tse allow you to ask the program, being guided by the regimes of energy
protection: for example, with the installation of "good" quartz 32 768 Hz, so
MK tunable delay can become close to 200-300 uA.

W

Amitki in the margins

The value of the struma is 1-2 mA and less, you can mentally take it as a pleasant for
battery attachments, as if they were insured for long-term uninterrupted operation
roboti. Elements of type AA (type alcaline, tobto puddles) may have a capacity for
a row of 2000 mA a year
pratsyuє no less than 1000 years (actually navit troch more) or ponad 40 deb. Time
robotic battery type D with energy capacity close to 15–18,000 mA year
put close to fate, which is more practical than enough.
Choose for living such outbuildings (especially those that are switched on periodically
for a short hour) next to the same puddle of elements, to that the stench may be great
ємністю, do not flow when reloading i, smut, may be a significantly larger term
savings (about 7 years) against other types of elements.

Ale, a respectful look at food shows that the same tsim - simply
yum programs - the most important ones have the most vipadkivs the most important

Part I. General principles and functions of the Atmel AVR

low clock frequency and interleave. Graphics on small 1.2 linear, stars
next, proportionally to the decrease in the clock frequency, the increase in the clock frequency
no commands. In this rank, the procedure, vikonannya like at a clock frequency
4 MHz take 100 µs, at a clock frequency of 32768 Hz, the trip time is more than 12 ms.
It’s easy to cheer up that in that other moment there is a lot of energy saved on
vikonannya tsієї procedures will be the same.

Rice. 1.2. Diagram of fallows

that clock frequency for younger models of the Mega family

To that it is possible to stir up the offensive scorched whisk: so you don’t want to delve into
subtle modes of energy saving and do not implement them in the program, then for the
it is necessary to select the clock frequency of the yakomoga lower (by
in practice, sound to get around the value of 1 MHz, i.e. up to.
reduction, better for everything, not to give an effect through additional improvement of external
them with lancers, which are inevitably present in all schemes). Yakscho Well ahead of you-
one of the "deep" energy saving modes (div. split 4), then the clock
the frequency at a glance of the total recovery is of little importance.
Insha on the right - choose the voltage of life, like a bazhano work like you can
less, even if they allow outside buildings. The fallow land of the stream
voltages of life, as it is easy to see the graphs in fig. 1.2, non-linear: increase
personal voltage strum spozhivannya quickly increases. Therefore, reduce to-
life voltage
AVR models (no more than 8 MHz at 2.7 V alive) are all the same. For example,
attachment to life 3 at a clock frequency of 8 MHz, see fig. 1.2, will
sleep close to 3 mA or, in a pererahunka on a single strain, 9 mW; for the procedure

Section 1. Overview of Atmel AVR microcontrollers

ru trivality 100 μs pide energy 0.9 μJ. At a frequency of 16 MHz, the same pro-
procedure 50 µs, but slowdown at power consumption 5 V
set close to 14 mA, then 70 mW; all at once for the vikonannya procedures for pіde energy
3.5 μJ, maybe four times more.
For all known digital devices, for a rare vinnyatka, you can
get a modern analogue, for robots at voltages of 2.7-
3.0 (Move lower as the controller model does not allow it), so on the other side
there is no frost; those that have the most applications in this book are oriented towards
the voltage of life is 5, є is less than Danina's tradition. Until then, apply qi, yak
as a rule, eat on the uvazі kharchuvannya vіd merezі, de spozhivannya not maє great sign
chenny. Light indications can limit the decrease in the voltage of life.
tory (through those that directly drop the voltage on the light diodes by themselves
set the order of 2 V, and for the great indicators, turn on 5 V for control is not enough
tatochno), but in such outbuildings the controller's comfort is no longer great
Role: Chotiri seven-segment digits themselves according to their own spozhivatimut stream order
100 mA or more. The second way is to represent analog circuits, deduction
The voltage of life can be seen from the look of the increase in the signal-to-noise ratio.
Respectfully, the AVR visnovki can have a long-term value.
strum (up to 20-40 mA)
for respite from the livelihood (div. . tab. P1.3). Slid also indicate that
when applying analog voltages to the inputs of the ADC, the input digital CMOS-
element (input to port) is not included, and if this value is
The voltages near the threshold of the activation of the element can also be increased to a higher level.
tanny of condolences for the rahunok passing through the streak through the outer cascades
CMOS (among other things, if the microcircuit is in "sleep" mode,
div. split 14). What a small fraction of the microcircuit was spared from picoPower technology.

Actual features of AVR blocking in circuits

Most visnovkiv MK have budding "uplifting"
(to come to the life bus) resistor
obvious circuit problems, if the presence of such a resistor is necessary
for connecting double-view buttons or exiting from the "switched collector".
However, critical vibrations require an external resistor with support 2-
5 kOhm (for critical vibrations up to 10-30 kOhm).
"Podtyagyuchiy" resistor should not be installed only on the output / RESET
(about what to look for in chapter 2), ale th to that vipadku, if the whiskers are SCK, MOSI and MISO
the available ports are selected for programming and connecting to
ISP software socket (div. split 5), as well as behind the visnovkas of the ovnis
van, like the stink of the ass. Yakshcho tsі vysnovki not "pіdtyaguvat" to the strain
eating with additional resistors (if not included in the technical
documentation), then pardons are not included
restarting the system, and in case of hard resets, put the program into memory
you program. From the other side, if the programming visnovki serve and yak-

Part I. General principles and functions of the Atmel AVR

100 primary ports configured to be out, and the outbuilding will be stopped
energy-saving modes, the presence of resistors, which "pull up", can lead
until the strum is closed down (when the display is set to a logical zero through a resistive
stor leak strum from the zherel zhivlennya at the entrance of the MK). Yakshcho implementations one of the re-
energy saving presses, then it is necessary to carefully analyze the scheme, so that
turn on the situation, in some cases, through q resistors flow through the strum.
Also, make sure to install the appropriate resistors with the robotic windings of the MK on
hot bus, like in interface I

C (or just when connected to the MK input to

output of another annex with a large collector, for example, monitors of life.
nya, description chapter 3), when connected to double buttons (especially
for the obviousness of the ovnіshny perevannya, div. chapter 4і 5 ). Opir vbudovanogo
resistor
such vibrations are too big for the electromagnetic shifts ("on-
burners") effectively "sit" on the new one.
AVR microcircuits, like and whether or not CMOS logic, zavdyaki to a high threshold
tivaniї effectively protected from the overpass on the "earth" bus. However, the stench
richer in case of shifts on the bus of life. So don't forget about rozvyazuvannya.
our capacitors, as it is necessary to install without intermediary
taniya (ceramic 0.1-0.5 microfarads), as well as about the quality of the merging vipryamlyachiv i
stabilizers.

ROZDIL

Zagalny annex
organization of memory,
taktuvannya, skidannya

The overhead structure of the internal building of the MK AVR is shown in fig. 2.1. On tsіy
the diagram shows all the main components of the AVR (crim of the JTAG module);
in other models, storage facilities can be divided into
sya for the characteristics, inevitably overwhelmed by an 8-bit processor
kernel (GPU, General Processing Unit). Let us briefly describe the most important components
enti, more of them are reportedly looked at far away.
Let's start from memory. The AVR structure has three different types of memory: flash-
program memory, RAM (SRAM) for time data that is energy-independent
m'yat (EEPROM) for long-term saving of constants and data. Let's look at them
Okremo.

Program memory

Enabled flash-memory of programs in AVR-controllers to become
1 KB for ATtiny11 to 256 KB for ATmega2560. The first number in the named mo-
shares of the values ​​of memory in the row: 1, 2, 4, 8, 16, 32, 64, 128
256 kb. Program memory
organization (size of the side, fallow in the model, set in the 64 to
256 bytes). The page can be programmed more than once. Number of cycles ne-
reprogramming syagaє 10 thousand.
At the sight of the programmer, the memory of the programs can be
business seredkіv - slіv two bytes skin. Attachment to the memory of programs (and only
tієї memory) for two-byte words - even an important moment, which is necessary
take it firmly. Such an organization is wised up by the fact that there is a team in AVR
may be equal to two bytes. Winyatok to become teams

and deakі-

інші (for example,

), yakі operate with 16-bit and extended-

mi addresses, dozhina tsikh commands more expensive bytes and stench zastosovuyutsya less
for models with a program memory of over 8 kb (report div. split 5). In
in all other cases, the lichnik of the teams is called at the victor of the chergovo

Part I. General principles and functions of the Atmel AVR

command two bytes (one word), that needs memory capacity easily
cheer up, knowing the number of victorious teams. Absolute addresses in memory
gram
opis MK) are also revered in words.

Rice. 2.1. General block diagram of AVR microcontrollers

W

Amitki in the margins

Let's move the butt of the cіkavogo vipadku addressing, scho represent
command for reading constants from LPM memory (as well as ELPM in MK from program memory
128

kb and more). Tsya team is on the verge of reading byte address, indicated

to the number of two senior RON (authorize the so-called. Z register Z, div. Dalі). Prote schob not
destroy the "purity" of the concept of organizing the memory of programs for words, retailers
they simply got confused by stating in the description that when the LPM command was called, the old
wі 15 ranks to register Z address word in memory, and choose the youngest rank
junior or senior byte

the words. It is easy, however, to remember that the byte order of memory is
who is suitable for equivalent.

Remaining addresses of the explicit memory of the programs for a specific model
denoted by a constant

For locking, the controllers of the AVR must be

repair the program from address $0000. There is no interruption in the program
nіy, then from tsієї addresses you can start the application program. At the opposite service

tea for qієyu address roztashovuєtsya t.z. table vector_v reparation, detail-
її about yaku mi saymemo in split 4і 5 . Here it is less significant than the first
This table (for the same address $0000) must always place the discount vector

which instructs the procedure that is consummated when the MK is dropped (including
when life is on).

P

RIMITKA

In AVR assembler, you can assign sixteen numbers in "pascal"
styles that precede them with the $ sign, so that the style of the movie C (0x00) is valid, and the axis
"intelligent" method (00h) does not work. Report on the meaning of the numbers of people
calculation systems in AVR-assembler div. split 5.

In the rest of the memory addresses of the program controllers of the Mega family,
lag t.zv. zavantazhuvach- a special program, as a matter of interest
vivantage of applied programs from the main obligation of memory. Whose mind is better
of the drop vector and all the tables of the vector of the reset (that is, in fact, on
starting address, from which the program starts) you can change
neno by installing special configuration centers (div. split 5).

Data memory (RAM, SRAM)

On the view of the memory of the program address space of the memory of the data is addressed
byte by byte (and chi not word by word). Addressing is linear, without any subdivision
on sides, segments or banks, as usual in other systems.
Young MK family Tiny (including Tiny1 X i Tiny28) in memory of the data, like tacos
vittya, do not mess, intermingling only with the register file (RON) and the registers of the vvіy-
so-vivodu (RVV). In other models, it is possible to use the built-in SRAM
128 bytes for representatives of the Tiny family (for example, for ATtiny2313) up to 4–8 kb
for older Mega models.
The address space of the static data memory (SRAM) is intelligently subdivided into
a few areas shown in fig. 2.2. Partially visible with a dark fill, vіd-
sho rush to vbudovanoy SRAM, to it in order the address of the roztashovu -
ale address space registers (the first 32 bytes borrow RON, another 64 -
RVV). For older Mega models with a folding structure (for example, ATmega128)
64 registers of introduction and introduction may appear insufficient, so in them for additional
Additional RVVs are seen as large address space (from $60 to max.
little possible in byte addressing the value of $FF, at once such registers can be
maybe a total of 160).

W

Amitki in the margins

In the architecture of the MK AVR, the understanding of the "introduction-visnovka" is won by two senses:

first, є "spoil I / O ports", as we can see in chapter 3.
In another way, the "registry of entry and exit" (RVV) in the AVR structure is called registers,
yakі secure access to additive components, zvnіshnіh

nіyu to the GPU, for a small amount of RAM (including up to ports of input-output). Take pid-
expanded the structure of the MC AVR to the sonic configuration of the personal
computer, de access to any calls by date to the central processor
components, memory cream, zdijsnyuєtsya through port I/O.

Part I. General principles and functions of the Atmel AVR

For some Mega models (ATmega8515, ATmega162, ATmega128, ATmega2560
that іn) the possibility of connecting the external memory is transferred to
64 KByte
variety (SRAM, Flash or EEPROM) with pa-
parallel interface.
It is significant that the addresses of RON and RVV do not take away
mandrivka at the data RAM (with a twist, connect
old memory of the older Mega models,
maximum address which is surrounded by values
$FFFF): so, as in a specific MK model
512 bytes of SRAM, and the register space is borrowed
first 96 bytes (up to address $60), then SRAM addresses
borrow address space from $0060 to $025F
(tobto from the 96th to the 607th middle inclusive). Kіnets
vbudovana memory of data is signified by a constant

Rice. 2.2. Address space

static data memory (SRAM)

microcontrollers AVR

Read/write operations on the riddle, however, work with any addresses with access
dull space, and with the robotic SRAM, it is necessary to respect: deputy
you can easily "spend" a note on the riddle in the same register. For example,
command to get the value of the register

at register

) is equally strong

entries in SRAM at address zero (

). Addresses in memory for RON sov-

fall with the same number. At the same hour for a non-intermediate entry in the RVV for yoga
address in memory to the number of the register next add $ 20: so, the register of entitlements

which for more models is roztashovuetsya on the basis of tables RVV for the address
$3F, memory address $5F. Install RON and RVV direct addressing pa-
m'yati unhandled: such a record always takes two measures to replace one, characteristically.
go for more other teams, although others allow you to bypass the exchange
on the manipulation of the deakim RVV. Ale yakscho є the program is ready, pratsyuyu-
s SRAM, then when replacing processor models with older ones, you will need
respect through those that they have young SRAM addresses can be twisted
supplementary RVV.

Chapter 2

Non-volatile data memory (EEPROM)

All models of MK AVR (Crimson taken from ATtiny11) may be built
EEPROM for saving constants and data when life is turned on.
For other models, the volume varies from 64 bytes (ATtiny1x) to 4 kb (older
Mega models). The end of the EEPROM is indicated by a constant

(tse signify-

it was introduced only for the latest AVR models;
tsієї constants іnоdі її happen to be appointed by yourself). Number of retransmission cycles
EEPROM coding can reach 100 thousand.
Guessing that EEPROM is considered to be Flash capable of vibrating
gramuvannya byte by byte (in principle, navit byte by byte, but this method is not available
koristuvach). However, for older models of the EEPROM family, such as flash-memory
programs, which can be a third-party organization, however, the parties are small - up to
4 bytes skin. In practice, like when programming EEPROM in sequence
channel (through the SPI programming interface), so when recording
read EEPROM from programs, this feature is not important, and access is
іsnuє byte by byte.
Reading from EEPROM is carried out by stretching one machine cycle (true, on
in practice, it will be carried out on chotiri cycles, but the programmer should follow the cym special
socially not necessary). And the axis of the record in EEPROM is significantly better,
and before that, it’s definitely not a designated code: a cycle for writing one byte can
take from 2 to ~ 4 ms or more. The recording process is regulated by RC-
generator, the frequency of which is unstable (at low voltage
ochіkuєtsya, scho recording will be greater). For such an hour, with such extraordinary
at the same frequencies of the MK vstigaє vikonati kіlka thousand commands, to that the program
the procedure for recording the record for accuracy: for example, it is necessary to stitch,
so that at the moment the recording did not "wedged" the rewriting (a report about the div. chief
vi 4
і 9 ).
Head fold with robot z EEPROM
held with an insufficiently low voltage of life at the moment
wimicanny. It is mindful that when the voltage is changed, life is up to
effective threshold (below the threshold of stable work, but not enough for re-
turn off) through the colivannya of the voltage of the MK, it starts to turn off
command, among others you can set the procedure for writing to EEPROM. Yakscho
lie, that a typical MK AVR command is counted in ten parts of a microsecond,
it is clear
voltage to zero for the required hour
stabilizer type LM7805 with recommended values ​​of condensate capacity
rіv at the entrance and at the exit in the EEPROM will be inevitably zipped with
peacefully in half of the valleys.
This problem is not to blame, because the constants are written to the EEPROM
when programming MK, and the procedure for recording at the program every day (about those
How to create a file with data for EEPROM, div. distributed "Directives and functions
tsії" chapter 5
). The safety of data is great in such situations.

Part I. General principles and functions of the Atmel AVR

with primary precautions, and tim, scho allowed writing to EEPROM - procedure -
ra dvuhstupіnchasta (div. split 9). In all other ways (and they, obviously,
absolute greater - in EEPROM, most of the time they save
novki and current configuration when viknennі zhivlennya) to be accepted
special visit. The most cardinal and universal of them is the
a novelty of the current monitor of life, which will reduce the MC at the station
the change in the pressure of life is below the limit value. Tієї well mesti serve
vbudovaniya voltage drop detector (Brown-out Detection, BOD)
practical for all Tiny and Mega models, but technical documentation is not included
give, at the same time, for the sake of supremacy, the duplication of yoga and the sound monitor of life.
Report about the BOD scheme and the MK div. dali in which division, but about the
mu EEPROM and later come in with її vikoristanny divs. split 9.

Methods of clocking

Canonical method of clocking MK - connection of a quartz resonator
suitable for visnovkas (Fig. 2.3, a). Capacity of capacitors C1 and C2 for a typical
in times it is guilty of becoming 15–22 pF (can be reduced to 33–47 pF with one
timchasovym promotions). Most Tiny and Mega models have
There is a special configuration bit

What allows you to regulate

peace. When inserting the second bit into 1 (non-programming camp)
the range of the generator’s colivan changes, prote with which it sounds possible
frequency range
not recommended. You can also use a low-frequency quartz resonator
(for example, "annual" 32768 Hz), with which capacitors C1 and C2 can be used
wati, to that when installing

value 0 is added to the warehouse

MK internal capacitors with a capacity of 36 pF.
The quartz resonator can be replaced with ceramic. The author of these rows went into
run MK at non-standard frequencies, vicorist replace quartz in the same way
switching miniature inductance
densators 91 pF, the frequency is close to 10 MHz), which allows trochs to contaminate
change the dimensions of the diagram.
Obviously, clocking the MK can be done from the outside generator (Fig. 2.3, b). Oso-
it’s handy, if it’s necessary either to synchronize the MC with the outdated compo-
nents, otherwise I’ll take the exact frequency of clocking, choosing vіdpovidn-
generator (for example, Epson's SG-8002 series).
Navpaki, if the accuracy is not needed, you can connect the call RC-lance
(Figure 2.3, in). In this circuit, the capacitance C1 can be at least 22 pF, and the resistor R1
selected from the range of 3.3-100 kOhm. The frequency at which is assigned to the formula
F= 2/3 RC. C1 can not be installed at the same time, so as to write down the beam. 0 for config-
middle ground

Connected cim internal capacitor 36 pF.

Nareshti, you can take a look at the relevant components and get along
him RC-generator

Chapter 2

frequency values ​​(1, 2, 4 and 8 MHz). For a number of models, the ability has been transferred
rebuilding the frequency of the generator (report div. or technical description
particular models). Qiu mozhlivist most dotsilno vikoristovuvat in
younger Tiny models that are available in the 8-pin case - these are the visnovki,
used for connecting a resonator or an external generator
zadiyati іnshih tsіley, as zvichayn porti input-output.

Rice. 2.3. Methods for clocking MK AVR with victories: a- quartz resonator;

b- Sound generator; in - RC-lancers

Family of Classic RC-there is no generator, and special configurations

tsynykh seredkіv in tsikh MK is significantly less, and in a wild mood you can’t

give respect. Not so for other families. Zamovchuvannyam MK family

Tiny and Mega are installed in a robotic camp with a built-in generator
frequency 1 MHz (

0001), so for other modes it is necessary to

put the configuration middles in order

(Div. Table 2.1). With whom

sled vrakhovuvati

0000

the most often implanted value for a quartz resonator 1111) is re-

to drive the MK clocking mode from the call generator, and it is not possible to start it

start programming without applying the call frequency. About recommended install

kah configuration centers and about the features of their programming divs.

split 5.

Table 2.1. Setting the configuration centers CKSEL

fallow type of clocking mode

CKSEL3...0

Dzherelo clocking

Frequency

Sound frequency

Waking up RC-generator

Waking up RC-generator

Waking up RC-generator

Waking up RC-generator

Zovnishnya RC-lance

Part I. General principles and functions of the Atmel AVR

Table 2.1(completion)

CKSEL3...0

Dzherelo clocking

Frequency

Zovnishnya RC-lance

0.9...3.0 MHz

Zovnishnya RC-lance

3.0...8.0 MHz

Zovnishnya RC-lance

8.0...12 MHz

Low frequency resonator

quartz resonator

0.4...0.9 MHz

quartz resonator

0.9...3.0 MHz

quartz resonator

3.0...8.0 MHz

1xxx (CKPOT=0)

quartz resonator

Skidannya

Skid data (RESET) is called the introduction of the cob mode of the MK robot. With whom
all RVVs are installed in the camp for locking - as a rule, the price is zero
all ranks, for a small blame (and the RON axis can accept vibrations
any meaning, to that, if necessary, begin with a song
the values ​​​​of change should be installed on the cob of the program (primus).
The program after the drop-off starts with the postal address (for locking
address $0000).
The discount is always charged when the living is turned on. Krim tsgogo, dzherelami dumped
you can also use the following: hardware discount, so that the supply of a low level
voltage on the input RESET
the active rіven here is low, and mi dotrimuvatimemosya rule); finish-
nya to the installed watchdog timer interval; scheme reference
BOD. The meaning of chotirioh young battles

due to signal

lizuvat about those, in the presence of which dzherel was carried out in the past
new in 1 bit 0 - discount when enabled, bit 1 - hardware discount, bit 2 - off
BOD diagram, bit 3 - war timer type). In practice, with the permission of the author,
stanam tsgogo register nadіyno vіdіznyayutsya vіd іnshih superfluous
timer skids
timchasovo). Prote tsya іnformatsіya can be corny, for example, in the analysis
lyzі causes interruption in robotic and industrial working outbuildings (div. split 12).
The younger MKs of the Tiny family (crim ATtiny28) have no
th "resistor on the output / RESET, to that for the supposed work the next warning
marvelous connection of an external resistor of 2–5 kOhm in size
life pressure. The author also recommends installing
a good resistor for any AVR models, so the resistor may need more
shoy denomination (100-500 kOhm)
ty to the unperformed skidannya. So (if in technical descriptions such a recom-

Chapter 2

(mendations and not avoided) do not start the installation of a capacitor 0.1-0.5 uF in
output /RESET to the "ground" - tse zglazhuє inevitable bryazkit naprugi i
trohi tighten the front of the increase in the voltage on the output /RESET por_vnyano
zі zbіlshennyam zhivlennya: if the threshold comes to spratsovuvannya circuit
skidannya, the voltage of the life of the entire MK is already set up.
For Tiny models available in 8-pin package (ATtiny11–ATtiny15),
Chi do not need zovn_shnє skidannya, vysnovok /RESET
th input port. With just one nuance: when configuring
contact on the vyhіd vіn pratsyuє, like vysnovok z vіdkritim collector, and not yak sound-
logical element (about the configuration of the ports div. split 3).
The best way to organize discounts when living is on, like
It was already said earlier, - the installation of a sound monitor of life. For example, when
The MC34064 microcircuit is popular for a 5-volt food processor with a reference threshold
4.6 V and typical values ​​are close to 300 µA or more current
analogue (for example, MAX803L with 12 μA delay). For trivolta living
attached circuit MAX803R (2.6 V) or suitable version DS1816
with a strong voltage. All listed microcircuits are trivivid (live, "earth-
la", supervised by the management of discounts) and may leave with the open collector, to
Think about installing a "pull-up" resistor. Typical hour spratsovuє-
for microcircuits with reduced voltage - microseconds, which is safe
saving data from EEPROM. At the time of the increase in the voltage, the stench will be safe
great timchasov zatrimka (about a quarter of a second), which allows you to
zdіysnyuvati skidannya MK without grime.
The BOD scheme has been introduced to ensure the hour of operation in the order of microseconds
zatrimkoy to turn into a working camp following the renewal of the voltage, op-
divided by these very installations, like a trap of skidding (komіrki

clock frequency 4 MHz) and enter the maximum possible її value ~ 68 ms can
appear insufficient for bypassing the grime, which is to blame for the reduction in
live voltage of an autonomous dzherel. To select the BOD robot mode,
harvesting three configuration centers

so become:

111 (standard setting) - BOD circuit disabled;

101 - includes BOD at a porosity of spratsovvannya 2.7;

100 - meet the threshold of 4.0 Art.

It is significant that from the point of view of the reliability of the work, the smaller the difference between the
the pressure of life and the threshold of the spratsovuvannya of the monitor of life
vbudovanoї scheme BOD, no matter), it's better - with small haircuts eating,
insensitive to the monitor, prote can be recognized by all
admission to the kshtalt of a mimotile vindication of a splendid rebirth. One-
before the price of retail, the following is to be insured during the livelihood, I will add the type of batteries: for example,
for some "finger-type" puddle batteries and life monitors, rozrahun-
tann at 4.7 V, the excess voltage on the elements after the

I have said more than once or twice that the development of MK needs to be started with assembler. To whom I assigned a whole course on the site (it’s true, it’s not the last one, but step by step I’ll rank it up to an adequate look). So, it’s okay, the result will not be on the first day, then you will learn to understand what you see in your controller. You know how to practice, and not by copying other people's pics and trying to understand why it has ceased to practice. In addition, it’s easier for C to build a beadcode, which you can use with a pitchfork at an inopportune moment.

Unfortunately, everyone wants the result wrong. To that I have succumbed to the letter from the other side - it is right to work on C, but also to show the yoga of the world. A good embedder-programmer will always hold his own for a bastard, not letting you step foot without permission. So let's start with the C code, let's see those who have created the compiler and how everything works right :)

On the other hand, C's strong side is code portability. Yakshcho, zvіsno, write everything correctly. Podіlyayuchi algorithms of work and їх їх іхні realizations at аrіrіnі part of the project. To transfer the algorithm to another MK, it is enough to rewrite only the interface ball, where everything is written before the release, and the entire working code should be deleted. I, obviously, reading. This day is easier to understand from the first glance (want ... me, for example, I don’t care about what the hell is going on - I want to, I want to asm :)), but, I know, I’ll write everything correctly. I will give respect to these moments too.

As a pіddoslіdna zalozka on yakіy will be put the left part of all applications in the future my tax payment.

First C program for AVR

Select compiler and installed environment
For AVR, there are no different compilers:
Nasampered tse IAR AVR C- may be unequivocally recognized as the best compiler for AVR, because the controller itself works closely with Atmel and IAR specifications. Ale has to pay for everything. And this compiler is not only an expensive commercial software, but it also has such a breakthrough, that you just need to take the compilation in a new direction. I really didn’t grow friendship with him, the project rotted on marvelous pardons at the linking stage (pіznіshe z'yasuvav, sho buv crooked crack).

Other ide WinAVR GCC- hard compiler that optimizes. New open source, cross-platform, zagalom, mustache joy of life. More wines can be integrated into AVR Studio, allowing you to carry out customization right there, which is more convenient. Zagalom I selected yoga.

Also є CodeVision AVR C- the most popular compiler. Becoming popular with the link for its simplicity. You can already work with the program in a new way through a sprat of hvilin - the master of the starting code to whom you need to spry, stamping the standard initialization, be it any kind of wart. Honestly, I seem to be suspecting something new - as if I had a chance to disassembly a program written by a cim compiler, the porridge seemed to come out and not the code. Zhakhliva a lot of non-essential rukhіv of the body and operations, which waded into a rather strong obsyag to the code and to the full swidkodіyu. Vіm, perhaps, there was a pardon in the DNA, like writing a free firmware. Plus, you want pennies. Not so rich, like IAR, but sensible. And in demo mode, you can write no more than 2kb code.
The crack is huge, but if you steal, then a million, at the sense of IAR :)

More є Image Craft AVR Cі MicroC in microelectronics None of them, none of them had a chance to squirm, but the axis SWG already praise micropascal, movlyav, more zruchne middleware of programming that library. I think that MicroC will not be louder, but it will be paid.

As I already said, I chose WinAVR For three reasons: free, integrable into AVR Studio and it was written just by breaking through the finished code for all kinds of life.

So download your own WinAVR installations and AVR Studio. Let's start the studio, then the beast will get WinAVR and go to the studio at the sight of the plug-in. I nonchalantly recommend that you put WinAVR on a short path, so on C:\WinAVR, you yourself can buy problems with paths.

Project creation
Otzhe, the studio has been set, C_ screwing, it's time to try and program it. Let's start with the simple, the simplest. Run the studio, choose a new project there, like the AVR GCC compiler and enter the name of the project.

The working field is opened with an empty *.c file.

Now you can't set the mood for displaying ways at the bookmarks of the studio. For whom is the evil for the address:
Menu Tools - Options - General - FileTabs and select "Filename Only" from the list. Otherwise, it will be impossible to practice - on the tab there will be a new path to the file, and on the screen there will be no more than two or three tabs.

Project completion
For starters, the classic way to create a make file is to describe all the fallacies. I tse, maybe, right. Hello, what a virus on the povnistyu іntegrovanih IDE nachebto uVision or AVR Studio tsey pіdhіd є deeply distant. To that robitimu for his own, mustache with the help of the studio.

Tick ​​at the gear button.


The purpose of customizing your project, or rather, customizing the automatic generation of the make file. On the first side, you only need to enter the frequency for whichever way your MC will work. It is worth laying in fuse battles, so it’s important that we have a frequency of 8000000 Hz.
It is the same way to give respect to the order of optimization. At the same time there is a cost -Os tse optimization for expansion. As long as it's enough, then you can try to play around with this parameter. -O0 cost of optimizing in zagali.

The next step will be the lashing of the paths. Before you add the directory of your project there - you add third-party libraries there. The list will have a way "."

Make a file of generations, you can look in the default folder of your project, just try and see what's there.


For now, everything is for now. Emboss the letter OK and go to the exit.

Problem statement
A clean slate is so imaginative that it seems like a cunning idea, so you don’t insert a banal moment with a diode. Come on now, take the beak by the horns and make a connection with the computer - I don’t know what I’m afraid of.

Practice like this:
When one arrives at the COM port (code 0x31), the diode is fired, and when zero arrives (code 0x30), it is extinguished. Moreover, everything has been ruined at the rearrangements, and the background will be the blink of an eye. Just with a sense.

Choosing a scheme
We need to connect the USB-USART converter module with the USART microcontroller plugs. For this, we take a jumper with two wires and throw it on the pins across. So the Rx controller is connected to the Tx converter, and the Tx converter is connected to the Rx controller.

Weide, the result axis is as follows:


I don’t see the connection to solve the visas, I don’t see the drop, it’s standard

We write the code

I’ll make sure that I don’t get stuck specifically in the description of the movie Sі. For this source, the amount of material is colossal, beginning with the classics "Mova Programming C" in the form of K & R and ending with various manuals.

One such method was known to me in my stash, I used it myself to shoot my tongue. Everything is short there, the one on the right understood. I її make up step by step and drag it to my site.

There, however, not all the chapters have been transferred yet, but, I think, the price is not long.

It is unlikely that I will describe more briefly, to that of the initial course, the deputy of the report clarification of these subtleties, I will simply give direct links on the other side of the manual.

We add libraries.
Before us, we will add the need for libraries and headings with names. Adzhe Sі tse is a universal language and you need to explain what we can do with AVR, so write in the output row:

1 #include

#include

This file is in the folder WinAVR and in the new place a description of the used registers and ports of the controller. Moreover, everything is cunning there, with binding to a specific controller, which is transmitted by the compiler through make parameter file MCU and on the substantiation of the change in your project, a header file is attached with a description of the address of all ports and register itself on the controller. Axis yak! Without it, you can, or else you can’t spell symbolic register names on the SREG or UDR checkbox and remember the address of the skin on the “0xC1” checkbox, but don’t break your head.

The team itself #include<имя файла> Allows you to add your project to a text file, for example, a file with a description of the functions or some other code. And so that the directive could know the file and specify the paths to our project (the WinAVR directory is already registered there behind the default).

Main function.
My C's program is all composed of functions. The stench can be investments and calls one by one in any order and in different ways. Skin function may have three obov'yaskovі parameters:

  • The meaning that turns, for example, sin(x) turn the value to the sine of x. Like mathematics, shorter.
  • Parameters that are transmitted, tsey x.
  • The body of the function.

All values ​​transferred and rotated may be of the same type, fallow in data.

Whether a C program is guilty of a revenge function main as an entry point to the main program, otherwise it’s not C:). For the presence of main in someone else's mind from a million files, you can understand what the main part of the program is, the stars start all over. Axis i set:

1 2 3 4 5 int main (void) (return 0;)

int main(void) ( return 0; )

That's it, the first simplest program has been written, don't worry, don't hurt anything, just start.

Let's find out what we were robbed.
int the same data type as the main function turns.

Obviously, the microcontroller main in principle you can’t turn anything and for an idea you can buti void main(void), albeit a GCC file on a PC, and there the program can rotate the operating system values ​​after completion. Tom GCC on void main(void) bark Warning'om.

Tse not pardon, pratsyuvati bude, but I do not like warnings.

void the type of data that we are passing to the function, in this way main so you can’t accept anything, that void- Empty. Stub, zastosovuєtsya then, if you do not need anything to transfer or turn.

Axis is the axis { } figured arms are the program block, in this case the body of the function main, there will be a code.

return- the value that is rotated, like the main function will show when completed, the shards are int, this is the number, then turn the main number. However, there is no sense, because on the microcontroller from main, we can go anywhere. I turn zero. Bo nefig. And the compiler sounds smart, and the code is not generated for this way.
If you want to twist, then main You can go to the MK - for example, you can go to the bootloader section and vikonati її, but you also need a low-level flashing firmware to correct the transition address. Below you yourself will fumble and understand, as if you were growing. New? The axis is already more power, 99.999% of the cases don’t need it :)

They thrashed, went away. Dodamo change, it’s not particularly necessary for us and without the need to introduce change not varto, but let’s take care of it. If the changes are added in the middle of the body of the function, then the stench is local and only found in this function. If the functions come out and the changes are removed, and the RAM memory is provided for the most 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 mean unsigned. On the right, in the one in the double file we have the highest bit, the sign is entered, which means that the number +127/-128 is included in one byte (char), but as a sign to drop it, then it’s in the same place as 0 to 255. Sound the sign is not needed. So what unsigned.
i- all the more im'ya zminnoy. Not more than that.

Now you need to pro_nіtsіalіzuvat spoil that UART. Of course, you can take and connect the library and call UartInit (9600); but still you don’t know what happened to be true.

Robimo like 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)>>8) #define LO(x) ((x)& 0xFF) UBRRL = LO(bauddivider) ; UBRRH = HI(bauddivider); UCSRA=0; UCSRB=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)>>8) #define LO( x) ((x)& 0xFF) UBRRL = LO(bauddivider); UBRRH = HI(bauddivider); UCSRA = 0; UCSRB = 1<

Scary? As a matter of fact, there are less than five remaining rows of the real code. Everything that #define ce Macromov preprocessor. May be the same badilla, which is in Assembler, but the syntax is a little bit different.

Stink to make your routine operations easier to calculate the required coefficients. At the first row, we say that zamіst XTAL you can boldly represent 8000000, and L- Specify the type by moving long - the clock frequency of the processor. Tezh same baudrate- Frequency of data transmission via UART.

bauddivider already folded, the deputy of the new one will be presented again with the charges for the formula of two in advance.
well and LOі HI on this result, take the youngest and oldest byte, because it may not fit into one byte. AT HI Try zsuv iksa (input parameter to the macro) all the way to the right, the result will have more than the high byte. And in LO we need to bit by bit with the number 00FF, as a result, the youngest byte will be left behind.

So everything that is crushed like #define you can boldly quote, and you can use the numbers to pick up on the calculator and immediately enter them in the row UBBRL = .... and UBBRH = …..

It's possible, it's possible. Ale! Robiti tsyogo ABSOLUTELY NOT POSSIBLE!

Pratsyuvatime and so and so, but in you in the program you are so called magic numbers- the meaning was taken inadvertently and the stars were inadvertently born and if in a couple of years you see such a project, then it will be very important to understand what the significance is. That and at once, you want to change the speed, or you remember the frequency of the quartz and you will have to redo everything again, and so remembering a couple of numbers in the code and all by yourself. In a nutshell, if you don’t want to be known as a beadlock coder, then code in such a way that it’s easy to read, smart and easy to modify.

Everything is simple:
All tsі "UBRRL і Z" tse registry configuration UART transmission for the help of some kind of information. And at once we gave them the necessary values, adjusting the necessary security and the necessary regime.

Record mind 1< means coming: take 1 and put її on the spot RXEN bytes. RXEN ce 4th bit register UCSRB so what 1< set the two number 00010000, TXEN- the whole third bit, and 1< gives 00001000. Single "|" bit by bit ABO, also 00010000 | 00001000 \u003d 00011000. In the same order, other necessary configurations are placed and added to the main compartment. The result of the selected number is recorded in the UCSRB. The report is written in the data on the MK in the USART distribution. I don't see the technical details either.

Done, the time has come to marvel at what happened. Press to compile and run the emulation (Ctrl+F7).

Nalagodzhennya
All the progress has passed, the studio has changed, and a new arrow has appeared at the entrance to the main function. Tse de processor at the moment, and the simulation is on pause.

On the right side of the back, right, there was standing in a row UBRRL = LO (bauddivider); Even those that we have at define are not a code, but simply a forward calculation, an axis simulator of three and blunting. And now I have seen the wine, I read the instructions, and I see you close to the tree I/O View, in the USART section and look at the UBBRL byte there, then you will see what the value is already there! 0x33.

Grow one more crochet. See how you can change to a different register. So pass їх уі, beastly respect for those that all appointed beats are displayed as I said to you, moreover, they are displayed at the same time for the entire byte. Dali Return on the right is not right - the program has ended.

Roztin
Now reset the simulation to zero. Press there Reset (Shift+F5). Check out the listing disassembly, you’ll be smart about what is actually in the controller. View -> Disassembler. І not YYAAAA! Assembler! JAH!!! A REQUIRED. We’ll sweat it, if it’s wrong, not dumbing down the code and not putting lamer’s feeds on the forums, but once again at the telbukh and marveling at you zatik. There is nothing terrible there.

On the back will be a badilla from 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 СПМ 0x0000002A Перейти +00000002: 940C0034 СПМ 0x00000034 Перейти +00000004: 940C0034 СПМ 0x00000034 Перейти +00000006: 940C0034 СПМ 0x00000034 Перейти +00000008: 940C0034 СПМ 0x00000034 Перейти + 0000000A: 940C0034 СПМ 0x00000034 Перейти + 0000000C: 940C0034 СПМ 0x00000034 Перейти + 0000000E: 940C0034 СПМ 0x00000034 Перейти +00000010: 940C0034 СПМ 0x00000034 Перейти +00000012: 940C0034 СПМ 0x00000034 Перейти +00000014: 940C0034 СПМ 0x00000034 Перейти +00000016: 940C0034 СПМ 0x00000034 Перейти +00000018: 940C0034 СПМ 0x00000034 Перейти + 0000001a: 940C0034 СПМ 0x00000034 Перейти + 0000001C : 940C0034 СПМ 0x00000034 Перейти + 0000001E: 940C0034 СПМ 0x00000034 Перейти +00000020: 940C0034 СПМ 0x00000034 Перейти +00000022: 940C0034 СПМ 0x00000034 Перейти +00000024: 940C0034 СПМ 0x00000034 Перейти +00000026: 940C0034 СПМ 0x00000034 Перейти +00000028: 940C0034 СПМ 0x00000034 Перейти

00000000: 940C002A СПМ 0x0000002A Перейти +00000002: 940C0034 СПМ 0x00000034 Перейти +00000004: 940C0034 СПМ 0x00000034 Перейти +00000006: 940C0034 СПМ 0x00000034 Перейти +00000008: 940C0034 СПМ 0x00000034 Перейти + 0000000A: 940C0034 СПМ 0x00000034 Перейти + 0000000C: 940C0034 СПМ 0x00000034 Перейти + 0000000E : 940C0034 СПМ 0x00000034 Перейти +00000010: 940C0034 СПМ 0x00000034 Перейти +00000012: 940C0034 СПМ 0x00000034 Перейти +00000014: 940C0034 СПМ 0x00000034 Перейти +00000016: 940C0034 СПМ 0x00000034 Перейти +00000018: 940C0034 СПМ 0x00000034 Перейти + 0000001a: 940C0034 СПМ 0x00000034 Перейти + 0000001C: 940C0034 СПМ 0x00000034 Перейти + 0000001E: 940C0034 СПМ 0x00000034 Перейти +00000020: 940C0034 СПМ 0x00000034 Перейти +00000022: 940C0034 СПМ 0x00000034 Перейти +00000024: 940C0034 СПМ 0x00000034 Перейти +00000026: 940C0034 СПМ 0x00000034 Перейти +00000028: 940C0034 СПМ 0x00000034 Перейти

Tse table vector_v pereprivan. Let's turn to it, just marvel and remember that it's out there. The first column is the address in the middle of the flush in which command is to be placed, another command code, the third command mnemonic, the same assembler instruction, the third operand of the command. That automatic comment.
So the axis, if you marvel, then cross over here. And the JMP command code is one byte, at the new address the jump is written backwards - the youngest byte behind the youngest address is the command code for the transition 940C

0000002B: BE1F OUT 0x3F,R1 Out to I/O location

Writing a zero to address 0x3F If you look in the I / O view column, then change the address 0x3F to the address of the SREG register - the controller's right-of-way register. Tobto. We reset SREG to run the program on zero minds.

1 2 3 4 +0000002C: E5CF LDI R28.0x5F Load immediate +0000002D: E0D4 LDI R29.0x04 Load immediate

0000002C: E5CF LDI R28,0x5F Load immediate +0000002D: E0D4 LDI R29,0x04 Load immediate +0000002E: BFDE OUT 0x3E,R29 I/O location +00000002

Tse zavantazhennya vkazіvnik stack. It is not possible to take advantage of the I / O register, only through the intermediate register. For this reason, LDI is intermediate, and then we call OUT in I / O. About the stack, I will also make a report. For the time being, know that this is such a dynamic area of ​​​​memory, hang like RAM and save in your address the addresses and change in the future. The axis at the same time was pointed out to those stars, we can start a stack.

00000032: 940C0041 JMP 0x00000041 Jump

The streak at the saaaaamy has a program, and there we have a fence to interrupt that loop tightly on 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

Tse inadok neperedbachenih furnishings, for example exit from the main function. From such a loop, the controller can be introduced either to hardware discounts, or, what is more, to discounts from a guard dog - watchdog. Well, otherwise, as I said above, correct the hex editor's room and go where our souls are forever. Also pay respect to those who use two types of transitions JMP and RJMP - the first direct transition after the address. Vіn borrow chotiri bayti and you can robite a direct transition to all areas of memory. Another type of transition is RJMP - visible. This command borrows two bytes, and then moves to the current position (address) by 1024 kroki forward or backward. In the І th parameters, the displacement of the flow point is indicated. Vikoristovuetsya most often, tk. borrows two or three months less from the flush, and you rarely need more money.

1 +00000034: 940C0000 JMP 0x00000000 Jump

00000034: 940C0000 JMP 0x00000000 Jump

And tse stribok on the cob code. Rezavantazhennya of his kind. You can revise what all the vectors bring here. From tsgogo vysnovok - if you allow it at once to be rebuilt (the stink behind the fence default) and you can go through the rebuilding, but there is no way to get it, then the program is thrown off - the program is thrown onto the cob itself.

main function. Everything can be similarly navit and not described. Look at the register to enter the same calculated number. Compiler preprocessor to steer! Identical "magic" numbers!

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

00000036: E383 LDI R24,0x33 Load immediate +00000037: B989 OUT 0x09,R24 Jump to I/O location 15: UBRRH = HI(bauddivider); +00000038: BC10 OUT 0x20,R1 Go to I/O location 16: UCSRA = 0; +00000039: B81B OUT 0x0B,R1 Jump to I/O location 17: UCSRB = 1<

And the axis here cant:

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

Wait, why does the compiler add such badilla? And if nothing else, like Return 0, we assigned the function as int main (void) axis i, they pissed off a whole lot more bytes, I’m not smart about what :) No matter what, our main function does not rotate anything. Zagalom, robi yak hoch :)

Important? First of all, no. Click on the code for the code in the disassembler mode and pose like the processor code for the code instructions, which, when done, are entered from the registers. How to move according to the commands that pidbag cycles.

Follow up in a couple of days.

Offtop:
Alexei78 zvarganiv plugin for firefox, scho easier navigation on my site and forum.
Talking about downloading

The schematic diagram of the programmer for the LPT port is shown in the small picture. Like a tire molder, use a microcircuit 74AC 244 or 74HC244 (K1564AP5), 74LS244 (K555AP5) or 74ALS244 (K1533AP5).

Svitlodiod VD1 indicates the recording mode of the microcontroller,

light diode VD2 - reading,

svitlodiod VD3 - the presence of the live scheme.

The voltage, the necessary food scheme, I take the ISP rose, so. type of programmed outbuilding. This circuit is a reworked circuit of the STK200/300 programmer (adding light for the efficiency of the work), it is summed up by the programs of the programmers on the PC, which is used with the STK200/300 circuit. To work with a cim programmer, hack the program CVAVR

The programmer can be installed on a different board and placed in the case of the LPT socket, as shown in the figures:




For robots with a programmer, you can manually install an LPT port, which is easy to make yourself (for example, with a Centronix cable for a printer), don’t mess with the conductors for the earth (18-25 feet rose) or buy it. The cable between the programmer and the programmed microcircuit is not guilty of overshooting 20-30 cm.


Modern radio amateurism cannot be detected without microcontrollers, but it is obvious. In the last decade, microcontrollers in various industries have become widely expanded in various areas of activity. Quite often they can be used in the most suitable outbuildings and structures. We are with you with certificates of computerization and automation of the processes we need. The truth is that without knowing the basics of programming, it has become practically impossible to create a modern competitive outbuilding.

If you are reading this article, it is possible for you to understand how microcontrollers work, and better for all the food:

4. How to read the literature?

Let's try it out on qi supply.

1. Which microcontroller to choose for a robot?

8-bit microcontrollers are very popular with radioamators PIC by Microchip Technology and AVR firms Atmel, 16-bit MSP430 TI firms, as well as 32-bit microcontrollers, architecture ARM.

At the industry, anyway, first of all, sit with the great wind Renesas Electronics on another Freescale, on the third Samsung then let's go Microchipі TI, gave everything else.
Popularity is determined by the price and availability, and the role played by the presence of technical information and the variability of the software support.

Mi vivememo 8-bit AVR microcontrollers, families ATMEGA 8 and 16 series. Having chosen, I am now becoming more accessible, revealing the impersonality of amateur research, a great amount of primary material. The manifestation of various intricate components and the functionality of this family.

2. What is the middleware for programming the selected microcontroller?

For AVR, various integrations of the development environment (IDE, Integrated development environment) have been created.
IDE- the whole system of software tools, which are hacked by programmers for the development of software security (PP), to the warehouse, which is included:
text editor,
compiler and/or interpreter,
make selection automation,
owner.

The largest of them AVRStudio, ATmelStudio, WINAVR, CodeVision, IAR Embedded Workbench.
In order to write programs, we speed up cost-free IDE ATmelStudio version 6 and more.
You can get Atmel Studio from the official site after registration (registration is absolutely cost-free and there is no goitre!)

ATmelStudio allows you to create projects and write programs both in assembler and in CI.

Be sure to ask for help: how should I choose programming to write effective programs?

Let's just say: it's necessary to write at least two language assemblers and CІ. Assembler is simply necessary, if you need to write firmware, compact subprograms, and macros, and various add-on drivers. But, if you need to create a large project, prompting on folding algorithms, without knowing CІ, you can spend more than an hour, especially in the process of enrichment, and if you need to transfer it to another platform, for example, PIC18 or STM, it can become an inseparable problem .
Let's see, now hardware platforms have appeared Arduino, work with yakimi learning movi CІ++
For this reason, programs can be written both in assembly language and in CI.

In order to get the result of your work firsthand, without using a soldering iron or a prototyping board, simply install the program Proteus.

3. How to flash the controller and how to add accessories and accessories needed for manual work with them?

Vikoristovuemo datagorsk. Crimea, it will be necessary to bring a breadboard, a block of life from the output voltage of 5 Volts. You can, like a power supply unit with small ripples, vikoristovuvat, zastosuvshi zener diode at 5 volts.
Possibly, in the course of the year, Igor zaproponuєmo project for the fold of the tax payment.

4. How to read the literature?

And the axis, for example:
Practical AVR programming in assembler. Revich, 2011
1000 that one microcontroller circuit Vip. 1-2. Ryumik, 2010-2011
10 practical additions to the MK AVR Book 1-2. Kravchenko, 2008-2009
Self-reader for retailer of attachments for MK AVR. Belov, 2008
MK AVR family Tiny and Atmega. Єfstіfєєv, 2008
CodeVisionAVR. Posіbnik for pochatkіvtsіv. Lebedev, 2008
Microprocessor control with attachments, thyristors, relays. Belov, 2008
Analog interfaces MK. Steward, Ball, 2007
We create an extension to the MK AVR. Belov, 2007
MK AVR in amateur radio practice. New analysis of ATTINY2313. Belov, 2007
Merezhevy and intermerezhevy exchange of danimi from MK. Go, 2007
MK AVR. workshop for pochatkivtsiv. Khartiv, 2007
Schemes, algorithms, programs. Baraniv, 2006
Microcontroller AVR. Entry course. Morton, 2006
Vimiryuvannya, cheruvannya that regulation for the help of AVR. Trumpert, 2006
Programming with my C for AVR and PIC MK. Shpak, 2006
Construction of outbuildings on MK. Belov, 2005
MK - it's simple, volumes 1-3. Frunze, 2002-2003
Mova programming Cі, 2nd edition. Kernigan, Ritchie, 2009
Programming of ATMEL microcontrollers by my S. Prokopenko, 2012

5. Where can you ask questions on the Internet and select specific recommendations?

You can ask food on our or any other forum, de so chi іnakshe stumbled upon those of microcontrollers. Golovne on the forums correctly formulate nutrition, so that you can clearly otrimuvat vіdpovіdі. Abstract nutrition does not linger, and more than for everything, you will take a lot of criticism, otherwise your nutrition will be deprived of respect!

Now let's take a closer look at our leader, ATMEGA 8 microcontroller

8-bit high performance AVR microcontroller with low performance
Progressive RISC architecture
130 highly productive commands, more commands are counted in one clock cycle
32 8-bit employees in the register of foreign recognition
A completely static robot
Approaching up to 16 MIPS (at a clock frequency of 16 MHz) performance
Vbudovaniya 2-cycle multiplier

Energy-independent program memory
8 KByte In-System Self-Programmable Flash
Safe for 1000 erase/write cycles
Supplementary sector of vanishing codes from independent blocking bits
One-hour read/write mode (Read-While-Write) is secured
512 bytes EEPROM
Safe for 100,000 erase/write cycles
1 KB of built-in SRAM
Programmed blocking, which secures the protection of software security features

Budovana periphery
Two 8-bit timers/lighters with a fixed front timer, one with a recoil mode
One 16-bit timer/timer with a front timer and lockout modes
Lіchilnik real time with okremi generator
Three PWM channels
8-channel analog-to-digital converter (for TQFP and MLF cases)
6 channels with 10-bit accuracy
6-channel analog-to-digital converter (for PDIP case)
4 channels with 10-bit precision
2 channels with 8-bit accuracy
Byte orientation 2-wire serial interface
Programming the latest USART
Last SPI interface (wired/wired)
Programmable watchdog timer with wake-up generator
Wake up analog comparator

Special microcontroller functions
Power supply cutoff and programming short-hour voltage drop detector
Calibrations RC-generator
Internal and external dzherela pererivani
Five modes of low noise: Idle, Power-save, Power-down, Standby and ADC noise reduction

Visnovki I/O and body
23 pre-programmed entry/exit lines
28-way PDIP package, 32-way TQFP package and 32-way MLF package

Working voltage
2.7 - 5.5V (ATmega8L)
4.5 - 5.5V (ATmega8)

Operating frequency
0 - 8 MHz (ATmega8L)
0 - 16 MHz (ATmega8)

vіdminnostі ATMEGA16 vіd 8
16 KB In-System Self-Programmable Flash

JTAG interface (summary from IEEE 1149.1)
Ability to scan peripherals, which complies with the JTAG standard
Expanded support for the budding tax
Programming via JTAG interface: Flash, EEPROM memory, jumper and blocking

Chotiri channels PWM / PWM

8-channel 10-bit A/D converter
8 unbalanced channels
7 differential channels (only for TQFP case)
2 differential channels with programming power 1, 10 or 200 times (only in TQFP package)

Six low sleep modes: Idle, Power-save, Power-down, Standby, Extended Standby and ADC noise reduction

32 programming lines entry / exit

40-width PDIP package and 44-width TQFP package

AtmelStudio

As soon as you start, you need to get it and install the AtmelStudio program from the official side of atmel.com
Once the AtmelStudio software is installed, the project can be opened.
Project- Tse your program, how do you write, adjust and flash, after compiling, to the riddle about the microcontroller.

To create a project, you need to launch a program, such a splash screen will appear,

that side of the creation of the project

To create a new project, you need to click on "New Project..."
In this case, it is possible to choose a new program, I will name the project, I will name the project, I will name the package with the files to the project, and it will be possible to create a directory for a sublime choice in other cross-projects. To create a project, demi programmably in assembler, you need to choose - assembler, after whom I remember the name of the project OK.

To appear on the vіkno

Selectable "megaAVR, 8-bit" and we know we need a microcontroller, we chose ATmega8. At the right side of the splash screen there is a list of attachments, which can be used with a microcontroller, one of which we can connect. Selectable OK.

The editor's side of the text appears, as it allows editing and adjusting the program. As long as the page is clean, the hour and date of creation are indicated, and I will name the project file, im'ya koristuvach. Іsnuyut dodatkovі vіkna vіkna pristroїv vvodnya-vivodu, vіkno zvіtіv compilatsії programs. now mi


we can program in assembler.
Similarly, a project is being created for programming my CІ.

© 2022 androidas.ru - All about Android