Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:avr:registers [2010/03/05 17:53] – Translation in progress yllarsen:avr:registers [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Registers ====== ====== Registers ======
  
-One of the toughest things for beginners to understand in a microcontroller is typically a register. When dealing with microcontrollers, it is impossible to get by without knowing what it is. This book is in no way different, as the reader is also expected to familiarize him/herself with the concept of a register and therefore the following text will try to explain it in simple enough termsso that even a beginner can grasp the idea of a register.+One of the toughest things for beginners to understand in a microcontroller is typically a register. When dealing with microcontrollers, it is impossible to get by without knowing what this device is. This book is in no way different, as the reader is also expected to familiarize him/herself with the concept of a register and therefore the following text will try to explain it in simple enough terms so that even a beginner can grasp the idea of a register.
  
 ===== Essence ===== ===== Essence =====
Line 16: Line 16:
   * Pause   * Pause
  
-Each button does something, but only when it is used correctly. For example, the stop button does nothing unless a tape is playing - only then will it do something apparent and stop the playback. Forward and rewind buttons, on the other hand, can be pressed at any time, because the tape can be wound in both direction, no matter if it is playing or stopped. The recording begins only when the play and record buttons are pressed down simultaneously. Some may have tried to depress several or all buttons at once - in this case, the tape player might have done something unexpected or break altogether.+Each button does something, but only when it is used correctly. For example, the stop button does nothing unless a tape is playing - only then will it do something visible and stop the playback. Forward and rewind buttons, on the other hand, can be pressed at any time, because the tape can be wound in both directions, no matter if it is playing or stopped. The recording begins only when the play and record buttons are pressed down simultaneously. Some may have tried to press down several or all buttons at once - in this case, the tape player might have done something unexpected or break altogether.
  
 Microcontroller registers behave like buttons on a tape player - each button does something, when used correctly. By pressing the wrong buttons, a microcontroller usually won't break, but it won't work either. In reality, there are no buttons in the registers, instead there are a whole lot of transistors, which turn the electricity on and off. Simpler microcontrollers have 8 transistor-based switches in a single register. A register can be thought of as an 8-bit number, where every bit is marked by the state of one of those switches. For example, a bit value of 1 can mean that the switch is on and 0 that the switch is off. Microcontroller registers behave like buttons on a tape player - each button does something, when used correctly. By pressing the wrong buttons, a microcontroller usually won't break, but it won't work either. In reality, there are no buttons in the registers, instead there are a whole lot of transistors, which turn the electricity on and off. Simpler microcontrollers have 8 transistor-based switches in a single register. A register can be thought of as an 8-bit number, where every bit is marked by the state of one of those switches. For example, a bit value of 1 can mean that the switch is on and 0 that the switch is off.
Line 22: Line 22:
 [{{  :images:logic:register_buttons_and_bits.png?240|Register's "buttons" and bit values}}] [{{  :images:logic:register_buttons_and_bits.png?240|Register's "buttons" and bit values}}]
  
-Since the state of a register's switches can well be displayed as a number and vice versa, a register can be compared to a memory, which can hold data the size of one number. By this comparison, we see that registers actually are memory slots. The difference between a register and a memory slot is that a memory slot only stores the information, but in a register this information actually controls something. For example, if a binary value of 01100001 is written to a register, then three imaginary buttons are pressed down and something happens.+Since the state of a register's switches can easily be displayed as a number, a register can be compared to a memory, which can hold data in the size of one number. By this comparison, we see that registers actually are memory slots. The difference between a register and a memory slot is that a memory slot only stores the information, but in a register this information actually controls something. For example, if a binary value of 01100001 is written to a register, then three imaginary buttons are pressed down and something happens.
  
-On a tape player it is possible to press each button separately, but in a register it is more difficult to change the value of one "switch" or bit. Typically it is necessary to change the entire content of the register. Before moving on to bit changing, one should know that there are a lot of registers in a microcontroller. Some parts of the microcontroller use tens of registers to control them. The variety of registers means that there has to be a way to distinguish different registers and that is done by naming the registers. One register, for example, is called PORTB. Actually, these names are just to make things easier for the developer and each name corresponds to a numeric address.+On a tape player it is possible to press each button separately, but in a register it is more difficult to change the value of one "switch" or bit. Typically it is necessary to change the entire content of the register. Before moving on to bit changing, one should know that there are a lot of registers in a microcontroller. Some parts of the microcontroller use tens of registers to control them. The variety of registers means that there has to be a way to distinguish between different registers and that is done by naming the registers. One register, for example, is called PORTB. Actually, these names are just to make things easier for the developer and each name corresponds to a numeric address.
  
 ===== Usage ===== ===== Usage =====
  
-C-keele programmis registri väärtuse kirjutamiseks või lugemiseks tuleb selle poole pöörduda nagu muutuja pooleJärgnev näide demonstreerib väljamõeldud registrisse REG binaarväärtuse kirjutamist ja selle väärtuse muutujasse //reg// lugemistBinaarväärtuse ette kirjutatakse 0b (ees on null), et kompilaator arvusüsteemist aru saaks.+To write to a register or read a value from it, it has to be addressed as a variable in C. The following example demonstrates writing a binary value to an imaginary register REG and then reading it to variable //reg//Binary values are distinguished by 0b (leading zero), so that the compiler understands the numeric system.
  
 <code c> <code c>
Line 35: Line 35:
 </code> </code>
  
-Põhimõtteliselt registrite väärtuse kirjutamises ja lugemises midagi keerulist polegikuid keerulisemaks läheb lugu siiskui soovitakse muuta registri üksikute bittide väärtustBittide muutmiseks tuleb enne selgeks saada binaartehted ja erinevad arvusüsteemid. Keegi ei keela tegutseda binaararvudegakuid binaararvudega tegelemine on tülikas nende pikkuse tõttu ja tavaliselt kasutatakse nende asemel heksadetsimaalarvemis on lühemad.+There is nothing difficult in writing and reading register valuesbut it gets a little tricky if only a single bit needs to be changed. To change bitsone needs to know how to do binary math and use different numeric systemsIt isn't forbidden to deal only with binary numbers, but they can be a bit troublesomebecause binary numbers are quite longand this is why most people use shorter hexadecimal numbers.
  
-[{{  :images:logic:logic_hexadecimal.png?209|Heksadetsimaalnumbrid}}]+[{{  :images:logic:logic_hexadecimal.png?209|Hexadecimal numbers}}]
  
-Heksadetsimaalarvus pole numbrid mitte ja 1, nagu binaarsüsteemis, ega 0-st 9-ninagu kümnendsüsteemis, vaid 0-st F-niÜks heksadetsimaalnumber moodustub neljast bitistKõrvalolev tabel näitab heksadetsimaalnumbritele vastavaid binaararveBinaararve teisendatakse heksadetsimaalarvuks lugedes bitte nelja kaupaalates madalamast järgustJärkusid loetakse paremalt vasakule ja nende nummerdamist alustatakse nullist. Näiteks binaararvu 1110 madalaima ehk 0. järgu väärtus on ja kõrgeima ehk 3. järgu väärtus on 1. Eespool toodud näidisregistri binaarväärtus 01100001 on heksadetsimaalkujul 61mis C-keeles kirjutatakse kujul 0x61 (ees on null).+In hexadecimal, the numbers are not only and as in binaryor to as in decimalbut instead to F. A hexadecimal number consists of four bitsThe table on the right shows the binary numbers and their hexadecimal counterpartsBinary numbers are converted to hexadecimal by reading bits four at a timestarting from the lowest rankRanks are read from right to left and their numbers start from 0. For example, the lowest ranked (rank 0) bit is 0 and the highest (rank 3) is 1. In the previous example, the register's binary value is 01100001, which is 61 in hexadecimal and is written as 0x61 (leading zeroin C.
  
-Üksikute bittide muutmiseks arvus (registrismuutujas või kus iganestuleb kasutada binaartehteidBinaartehe on tehe binaararvude vahelkus nende arvude iga biti vahel toimub omaette loogikateheEnamasti on mikrokontrollerites kasutusel neli binaartehetmillel kõigil on mitu nimetustJärgnevalt on toodud kõigile neljale binaartehtele vastav loogikatehe üksiku biti või bittidega.+To change single bits in a number (registervariable or anywhere else for that matterit is necessary to use binary operationsBinary operation is an operation between two binary numberswhere each bit of the numbers is subject to its own logical operationTypically a microcontroller supports four binary operationseach having several namesThe following section describes the logical operation behind each of these four binary operations with a single bit or multiple bits.
  
-[{{  :images:logic:logic_all_4.png?550  |Eitusloogiline korrutamineloogiline liitmine ja mittesamaväärsus}}]+[{{  :images:logic:logic_all_4.png?550  |Negationlogical multiplicationlogical addition and exclusive disjunction }}]
  
-~~PB~~+<pagebreak>
  
-  * **Eitus Inversioon** \\ Eitus muudab biti väärtuse vastupidiseks ehk muutub ja 1 muutub 0. C-keeles on eituse märk "~"+  * **Negation Inversion** \\ Negation changes the bit's value to its opposite, a becomes a and vice versaIn C, negation is marked with "~"
-  * **Loogiline korrutamine Konjunktsioon** \\ Kahte bitti korrutades on vastus 1kui mõlemad bitid olid 1, muul juhul on vastus 0. C-keeles on korrutamise märk "&"+  * **Logical multiplication Conjunction** \\ When multiplying two bitsthe answer is if both bits are 1 and in any other case 0. In C, logical multiplication is marked with "&"
-  * **Loogiline liitmine Disjunktsioon** \\ Kahe biti liitmisel on vastus 1kui vähemalt ühe biti väärtus oli 1, muul juhul on vastus 0. C-keeles on liitmise märk "|"+  * **Logical addition Disjunction** \\ When adding two bitsthe answer is if at least one of the bits is 1 and 0 if both bits are 0. In C, logical addition is marked with "|"
-  * **Mittesamaväärsus Välistav disjunktsioon** \\ Kahe bitiga mittesamaväärsuse tehte korral on vastus 1, kui bittide väärtused teineteisest erinevad, muul juhul on vastus 0. C-keeles on mittesamaväärsuse märk "^".+  * **Exclusive disjunction Exclusive OR / XOR** \\ Exclusive OR operation will return if the two bits differ from each other (one is 1 and the other 0)otherwise the answer is 0. In C, exclusive disjunction is marked with "^".
  
-Nüüd on lühidalt selgitatud kõik, mida läheb vaja üksikute bittide väärtuste muutmiseksKuid ilmselt jääb teooriast ikkagi väheks ja seepärast on järgnevalt toodud mõningad tüüpnäited registritega.+This is all one needs to know to change single bitsThe theory alone is probably not enough, though, and that is why there are some typical examples with registers in the next few paragraphs.
  
 ~~CL~~ ~~CL~~
  
-==== Setting a single bit high ====+==== Setting a Single Bit High ====
  
-[{{  :images:logic:op_bit_set.png?230|Biti kõrgeks seadmise tehe}}]+[{{  :images:logic:op_bit_set.png?230|Setting a single bit high}}]
  
-Selleks et üks või enam bitte registris kõrgeks ehk üheks seada, tuleb kasutada loogilist liitmise tehetLiitmistehte üks operand peab olema register, teine binaararv, kus kõrge on ainult see bitt, mida ka registris soovitakse kõrgeks seadaSeda teist binaararvu nimetatakse ka bitimaskiksKõrvalnäites toodud tehe näeb C-keeles välja niimoodi:+To set one or more bits in a register high (1) a logical addition operation is neededOne of the operands of the operation must be the register and the other a binary numberwhere the only high bit is the one that needs to be set high in the registerThis binary number is called a bitmaskBelow is the code for the operation shown on the right:
  
 ~~CL~~ ~~CL~~
  
 <code c> <code c>
-  // Oletame, et REG = 0x0F +  // Let's suppose REG = 0x0F 
-  REG = REG | 0x11; // Üks meetod +  REG = REG | 0x11; // First method 
-  REG |= 0x11;      // Teine meetod +  REG |= 0x11;      // Second method 
-  // Siinkohal REG = 0x1F+  // Now REG = 0x1F
 </code> </code>
  
-==== Setting a single bit low ====+==== Setting a Single Bit Low ====
  
-[{{  :images:logic:op_bit_clear.png?229|Biti madalaks seadmise tehe}}]+[{{  :images:logic:op_bit_clear.png?229|Setting a single bit low}}]
  
-Ühe või enama biti registris madalaks ehk nulliks seadmiseks tuleb kasutada loogilise korrutamise tehetTehte üks operand peab olema register, teine bitimask, kus madalaks on seatud vaid see bitt, mida ka registris soovitakse madalaks seadaKõrvalnäites toodud tehe näeb C-keeles välja nii:+To set one or more bits in a register low (0) a logical multiplication operation is neededOne operand of the operation must be the register and the other a bitmaskin which the only low bit is the one that needs to be set low in the registerBelow is the code for the operation shown on the right:
  
 ~~CL~~ ~~CL~~
  
 <code c> <code c>
-  // Oletame, et REG = 0x0F +  // Let's suppose REG = 0x0F 
-  REG = REG & 0xFE; // Üks meetod +  REG = REG & 0xFE; // First method 
-  REG &= 0xFE;      // Teine meetod +  REG &= 0xFE;      // Second method 
-  // Siinkohal REG = 0x0E+  // Now REG = 0x0E
 </code> </code>
  
-~~PB~~+<pagebreak>
  
-==== Inverting a single bit ====+==== Inverting a Single Bit ====
  
-[{{  :images:logic:op_bit_invert.png?229|Biti inverteerimise tehe}}]+[{{  :images:logic:op_bit_invert.png?229|Inverting a single bit}}]
  
-Ühe või enama biti registris inverteerimiseks tuleb kasutada mittesamaväärsuse tehetTehte üks operand peab olema register, teine bitimask, kus kõrgeks on seatud vaid see bitt, mida ka registris soovitakse inverteeridaKõrvalnäites toodud tehe näeb C-keeles välja järgmiselt:+To invert one or more bits in a register an exclusive disjunction operation is requiredOne of the operands of the operation must be the register and the other a bitmaskwhere the only high bit is the one that needs to be inverted in the registerBelow is the code for the operation shown on the right:
  
 ~~CL~~ ~~CL~~
  
 <code c> <code c>
-  // Oletame, et REG = 0x0F +  // Let's suppose REG = 0x0F 
-  REG = REG ^ 0x11; // Üks meetod  +  REG = REG ^ 0x11; // First method 
-  REG ^= 0x11;      // Teine meetod (rakendada tohib korraga ainult üht+  REG ^= 0x11;      // Second method (use only one per inversion
-  // Siinkohal REG = 0x1E+  // Now REG = 0x1E
 </code> </code>
  
-==== Inverting the whole register ====+==== Inverting the Whole Register ====
  
-[{{  :images:logic:op_reg_invert.png?229|Bittide inverteerimise tehe}}]+[{{  :images:logic:op_reg_invert.png?229|Inverting all bits}}]
  
-Kogu registri bittide inverteerimiseks tuleb kasutada eitustehetSee on unaarne tehe ehk tal on ainult üks operand. Kõrvalnäites toodud tehe näeb C-keeles välja niimoodi:+To invert all bits in a register, a negation operation is usedThis operation is unary, which means it has only one operand. Below is the code for the operation shown on the right:
  
 ~~CL~~ ~~CL~~
  
 <code c> <code c>
-  // Oletame, et REG = 0x0F+  // Let's suppose REG = 0x0F
   REG = ~REG;   REG = ~REG;
-  // Siinkohal REG = 0xF0+  // Now REG = 0xF0
 </code> </code>
  
-==== Reading the value of a single bit ====+==== Reading the Value of a Single Bit ====
  
-[{{  :images:logic:op_bit_get.png?229|Biti lugemise tehe}}]+[{{  :images:logic:op_bit_get.png?229|Reading the value of a bit}}]
  
-Ühe või enam biti väärtuse lugemiseks registrist tuleb kasutada sama tehet, mis biti nullimisel loogilist korrutamistTehte üks operand peab olema register, teine bitimask, kus kõrgeks on seatud vaid see bitt, mille väärtust registrist lugeda soovitakseKõrvalnäites toodud tehe näeb C-keeles välja järgmiselt:+To read one or more bits from a register the same operation is required as was used for setting a bit low logical multiplicationOne of the operands of the operation must be the register and the other a bitmaskwhere the only high bit is the one that needs to be read from the registerBelow is the code for the operation shown on the right:
  
 ~~CL~~ ~~CL~~
  
 <code c> <code c>
-  // Oletame, et REG = 0x0F+  // Let's suppose REG = 0x0F
   unsigned char x = REG & 0x01;   unsigned char x = REG & 0x01;
-  // Siinkohal x = 0x01+  // Now x = 0x01
 </code> </code>
  
-~~PB~~+<pagebreak>
  
-==== Shifting a bit ====+==== Shifting a Bit ====
  
-Tegelikult on paljudes programmeerimiskeeltes peale binaartehete veel mõned bitioperatsioonidmis teevad programeerija elu lihtsamaksNeed on bitinihutuse operatsioonid, mis binaararvus nihutavad bitte kas vasakule või paremale pooleNihutusoperatsioonide põhiline väärtus seisneb registritega tegeldes nende võimes bitijärkusid bitimaskiks teisendada ja vastupidi.+Many programming languages actually have a few additional bitwise operationswhich make it easier for programmersThese are bit shifting operations that shift bits left or right in a binary numberThe main advantage of shift operations in dealing with registers is their ability to convert bit ranks to bitmasks and vice versa.
  
-[{{  :images:logic:op_bit_shift_left.png?241|Bitinihe vasakule}}]+[{{  :images:logic:op_bit_shift_left.png?241|Shift left}}]
  
-Kõrvaloleval pildil on toodud näide bitinihutuse operatsioonist vasakuleBitinihutus pole loogikaoperatsioon ja sel puudub vastav tähis, C-keeles on see aga "<<"Nihet vasakule kasutatakse bitijärgu bitimaskiks teisendamiseksNäitekskui soovitakse kuuenda biti (NB! järk on 5) maskisiis tuleb arvu nihutada vasakule kordaNäites toodud operatsioon näeb C-keeles välja järgmiselt:+The image on the right shows a shift-left operationAlthough bit shifting is not a logical operation and has no corresponding symbolin it is marked as "<<"Shift-left is used to transform a bit rank to a bitmaskFor exampleto get the mask for the 6th bit (NB! rank 5), number has to be shifted left timesThe example operation looks like this in C:
  
 ~~CL~~ ~~CL~~
Line 145: Line 145:
 <code c> <code c>
 REG = 0x01 << 5; REG = 0x01 << 5;
-// Siinkohal REG = 0x20+// Now REG = 0x20
 </code> </code>
  
-[{{  :images:logic:op_bit_shift_right.png?241|Bitinihe paremale}}]+[{{  :images:logic:op_bit_shift_right.png?241|Shift right}}]
  
-Sarnaselt bitinihkega vasakule toimib ka bitinihke operatsioon paremale. Selle operatsiooni tähis C-keeles on ">>"Nihet paremale kasutatakse bitimaskist biti loogilise väärtuse leidmiseksEespool oli toodud näiteks üksiku biti väärtuse lugemise teheOletameet bitt, mida lugeda, pole aga madalaima järguga, vaid näiteks järguga 5. Sel juhul oleks lugemisel vastus kas 0x20 või 0x00, kuid vahel läheb vaja vastust või ja siis tulebki appi nihe paremaleKõrvalnäites toodud operatsioon näeb C-keeles välja nii:+The shift-right operation works similarly to the shift-left operation. It is marked as ">>" in CRight-shift is used to get the logical value of a bit from a bitmaskA previous example showed how to read the value of a single bitLet's suppose the bit to be read is not of the lowest rankbut for example of rank 5. In this case, the result would be either 0x20 or 0x00, but sometimes a result of or is needed and that is when the right-shift comes to the rescueThe example operation on the right looks like this in C:
  
 ~~CL~~ ~~CL~~
  
 <code c> <code c>
-// Oletame, et REG väärtus on 0x20+// Let's suppose REG 0x20
 unsigned char x = REG >> 5; unsigned char x = REG >> 5;
-// Siinkohal on väärtus 0x01 (ehk lihtsalt 1)+// Now 0x01 (or simply 1)
 </code> </code>
  
-Kui bitinihke operatsioonidega nihkub bitt madalaimast järgust paremale või kõrgeimast järgust vasakulesiis see bitt kaobMõnedes programmeerimiskeeltes on olemas ka roteeruvad bitinihke operatsioonidkus "servast" välja minev bitt tuleb teiselt poolt tagasi. C-keeles roteeruvad bitinihke operatsioonid puuduvadkuid vajadusel saab need ise kirjutada.+If a bit is shifted right from the lowest rank or left from the highest rank by the bit shifting operationit disappearsSome programming languages also have rotating bit shift operationswhere the bit doesn't disappear, but moves from the lowest rank to the highest or vice versa. C doesn't have that kind of bit-shift operationsbut they can be written by the programmer if needed.
  
-Kõik toodud bitioperatsioonide näited toimivad peale registrite ka muutujatega ja konstantidega. Viimased saavad muidugi ainult operandideksmitte vastusteks olla.+All bit operations work with not only registersbut with variables and constants as well. The latter can of course only be used as operands and not the result.
  
-===== AVR registers =====+===== AVR Registers =====
  
-Selleks et midagi reaalselt mikrokontrolleri registritega teha saakstuleb osata selle mikrokontrolleriga läbi saadaKõigi mikrokontrolleritega käib kaasas üks või mitu andmelehtekus on dokumenteeritud kogu mikrokontrolleri struktuur ja funktsionaalsusAndmelehes on kirjeldatud ka registridJärgnevalt uurime, kuidas saada aru AVR-i andmelehe registrite kirjeldusest.+To actually do anything with the microcontroller's registersone needs to know how to use that particular microcontrollerEach microcontroller comes with one or several datasheetswhich describe the whole structure and functionality of the microcontrollerThe datasheet also describes the registersThe following will help understand the register descriptions in AVR datasheets.
  
-[{{  :images:logic:avr_example_register.png?580  |Üks AVR register selle andmelehest}}]+[{{  :images:logic:avr_example_register.png?580  |One of AVRs registers from its datasheet}}]
  
-Pildil on toodud ATmega128 mikrokontrolleri register UCSRnA, mille pikem nimetus on "//USART Control and Status Register A//"See on register, millega sätitakse AVR-i USART moodulit ja kust saab lugeda selle mooduli olekuidKõik AVR-i registrite nimed kirjutatakse suurte tähtedegakuid tähelepanelik lugeja ilmselt märkabet selles registris on väike n-tähtVäikese n-tähega tähistatakse nimelt mõne mooduli indeksitKuna ATmega128-s on üsna sarnast USART moodulitsiis ei kirjeldata nende registreid topeltvaid ühe korra ja n-tähe asemele peab lugeja arvestama kas "0" või "1"Seega ATmega128-s on registrid UCSR0A ja UCSR1A.+The image shows ATmega128 microcontroller'UCSRnA registerwhich stands for "USART Control and Status Register A"This register is used to configure AVR'USART module and read its statesAll AVR register names are written in capital lettersbut as the reader might noticethe register name contains also a lower case n. A lower is used to mark some module's indexSince ATmega128 has almost identical USART modulesthey are not described twicebut only once and the must be read as or by the userTherefore ATmega128 has registers UCSR0A and UCSR1A.
  
-Registri sisu tähistab paksu piirjoonega lahtriga kastIga lahter tähistab üht bittiKasti kohal on toodud biti järgud suurenevad paremalt vasakuleKuna AVR on 8-bitine mikrokontrolleron ka enamik registreid 8-bitisedMõningad erandid on 16-bitised registridmis koosnevad tegelikult kahest 8-bitisest registristLisaks registritele on nimi ka igal registri bitil täpselt nagu kassetimängija nuppudelgi. Iga biti kohta on andmelehes olemas selle selgitusBiti nimed on samuti lühendid ja n-täht neis tuleb samuti asendada mooduli indeksigaMõnes registris pole kõiki bitti kasutatud ja sel juhul tähistatakse biti lahter sidekriipsuga.+The content of the register is marked by an 8-slot box with a bold line around itEach slot marks one bitBit ranks are marked above the box increasing from right to leftSince AVR is an 8-bit microcontrollermost of the registers are 8-bit as wellThere are some exceptions, a few registers are 16-bitbut they actually consist of two 8-bit registersJust as each register has a name, each bit in the register also has a name just like the buttons on a tape playerEach bit is described in the datasheet. Bit names are abbreviations as well and the lower must be substituted with the module's index, just like with register namesSome registers don't use all bits, in this case the bit's slot is marked with a hyphen.
  
-Registri bittide all on toodud kaks ridakus on kirjas, kas bitt on loetav (R), kirjutatav (W) või mõlemat (R/W). Näiteks olekubitte ei saa üle kirjutada ja isegi siiskui seda programmis üritadaei omanda bit lihtsalt talle omistatavat väärtustBiti puhul, mida saab ainult kirjutada, on öeldud üks kindel väärtusmis selle lugemisel alati tulebBittide all teises reas on toodud vaikeväärtusmis on bitil pärast mikrokontrolleri käivitamist (inglise keeles //reset//).+Below the register's bits are two lineswhich state whether the bit is readable (R), writable (W) or both (R/W). For examplethe status bits can't be overwritten and even if it's attempted in the programthe bit will remain unchangedIf the bit is marked as writablereading it will always result in one specific value stated in the datasheetThe second line specifies the default value of the bitwhich it has after the reset of the microcontroller.
  
-Kui AVR-i registrite nimed viitavad tegelikult mälupesade aadressidelesiis biti nimede taga peitub selle biti järgu number. Seega registris bittidega manipuleerimiseks tuleb bitinimed nihutusoperatsiooni abil bitimaskiks teisendadaJärgnevalt on toodud mõned C-keele näitelaused eeltoodud USART 0 mooduli registri kasutamiseks.+While AVR register names point to an actual memory slot addressthe bit names hold the rank number of the corresponding bitTherefore it is necessary to transform the names to bitmasks using a shift operation, in order to manipulate with bits in a registerThe following code contains a few example lines for using the USART 0 module's register.
  
 <code c> <code c>
-  // TXC0 biti kõrgeks seadmine+  // Set TXC0 bit high
   UCSR0A |= (1 << TXC0);   UCSR0A |= (1 << TXC0);
  
-  // U2X0 biti madalaks seadmine+  // Set U2X0 bit low
   UCSR0A &= ~(1 << U2X0);   UCSR0A &= ~(1 << U2X0);
  
-  // UDRE0 biti(maskiväärtuse lugemine+  // Read the value of UDRE0 bit(mask)
   unsigned char u = (UCSR0A & (1 << UDRE0));   unsigned char u = (UCSR0A & (1 << UDRE0));
  
-  // Siinkohal on väärtus kas või 32, +  // At this point value is either or 32, 
-  // mis võimaldab seda loogilises avaldises kasutada+  // which enables using it in a logical operation
   if (u)   if (u)
   {   {
-     // MPCM0 biti inverteerimine+     // Invert MPCM0 bit
      UCSR0A ^= (1 << MPCM0);      UCSR0A ^= (1 << MPCM0);
   }   }
  
-  // Mõnikord on aga vaja saada konkreetne või väärtus+  // Sometimes it is necessary to acquire a specific or value
-  // selleks tuleb loetud bitti nihutada paremale+  // so the read bit needs to be shifted right
   u >>= UDRE0;   u >>= UDRE0;
  
-  // Siinkohal on väärtus kas või 1+  // Now the value of is either or 1
 </code> </code>
  
en/avr/registers.1267811618.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0