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:io [2010/02/28 14:33] mikk.leinien:avr:io [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Digital inputs/outputs ======+====== Digital Inputs/Outputs ======
  
-Kõik AVR siinid on loetavad ja kirjutatavadkui neid kasutada tavalises loogilises sisend-väljundrežiimis (inglise keeles //input/output//, ehk //I/O//). AVR siinid on nimetatud suurte ladina tähestiku algustähtedega A, B, C, jneMõnel AVR-il võib aga siin puududakuigi siin on olemasIga siin on 8-bitine ja iga biti jaoks on enamasti kontrolleri kestast välja toodud eraldi viikViikusid loendatakse arvudega alates nullistSiini mõlema kasutussuuna jaoks on olemas kaks eraldi registritLisaks on olemas iga siini kohta register siini reaalse toimimissuuna määramiseksmilles biti väärtus näitab viigu kasutamist väljundina ja sisendinaKokku on iga siini kohta kolm registrit:+All the buses on an AVR are both readable and writableif they are used in the default logical input/output (I/O) mode. AVR buses are named as letters from the beginning of the Latin alphabet: A, B, C etcSome AVRs might not have bus A, though, if bus existsEach bus is 8-bit and each bit usually has its own pin on the controllerPins are counted with numbers starting from zeroFor both directions on the bus, there are two separate registersIn addition, there is a register to decide the real direction of the buswhere a bit value of marks the bus as output and as inputAltogether, each bus has three registers:
  
-  * PORT - siini füüsilise väljundoleku määramiseks+  * PORT - for setting the output value of the bus
-  * PIN - siini füüsilise sisendoleku lugemiseks+  * PIN - for reading the input on the bus
-  * DDR - siini füüsilise suuna määramiseks.+  * DDR - for setting the direction of the bus.
  
-<box 100% round #EEEEEE|Näide>+<box 100% round #EEEEEE|Example>
  
-Vaja on siini B viigud 0-3 teha sisenditeksviigud 4-7 väljunditeksseada 5. viik kõrgeks ja lugeda 0-3 viigu väärtus muutujasse. C-keele programmi kood on järgnev:+Task: make pins 0-3 on bus B inputspins 4-7 outputsset pin high and read the values of pins 0-3 to a variableThe code for it looks like this:
  
 <code c> <code c>
Line 18: Line 18:
  unsigned char x;  unsigned char x;
  
- // Viigud 0-3 sisendiks, 4-7 väljundiks+ // Pins 0-3 as inputs, 4-7 as outputs
  DDRB = 0xF0;  DDRB = 0xF0;
  
- // Viienda viigu kõrgeks seadmine+ // Set pin five as high
  PORTB |= (1 << PIN5);  PORTB |= (1 << PIN5);
  
- // 0-3 sisendviigu väärtuse lugemine+ // Read the values from inputs 0-3
  x = PINB & 0x0F;  x = PINB & 0x0F;
 } }
Line 31: Line 31:
 </box> </box>
  
-Toodud näites on sisendeid kasutatud Hi-Z ehk kõrge impendatsiga (inglise keeles //high impedance//režiimisPõhimõtteliselt on tegemist sisendigamis ei koorma peaaegu üldse signaaliallikatSeda režiimi võib vaja minnakui viiku kasutatakse andmesiininaKui viik on kasutusel nupu, lüliti või muu maad ning sisendit kokku ühendavas lahenduses, siis tasub sisendis kasutada //pull-up// takistitSelleks tuleb sisendrežiimis seada kõrgeks vastava viigu väljundbitt tulemusena lülitub toitepinge ja sisendi vahele takistimis hoiab sisendi pingenivood kõrgelkui miski seda just alla ei tõmba//Pull-up// takisti eesmärk on ära hoida sisendi "ujumine" (inglise keeles //floating//) staatilise elektri ja muude häirete tõttuPärast kontrolleri käivitumist on kõik IO siinid vaikimisi kõrge impedantsiga sisendrežiimis.+In this example, the inputs are used in Hi-Z (high impedance) modeIn essencethe input does not put virtually any load on the source of the signalThis mode might be necessaryif the pin is used as a data busIt is wise to use a pull-up resistor on the input, if the pin is used for a button, a switch or any other solution, where the input is connected to groundFor that, the output bit of the corresponding pin must be set high in the input mode as a resulta resistor is placed between the supply voltage and the inputwhich keeps the input voltage high unless it is being pulled down by somethingThe goal of a pull-up resistor is to prevent floating of the input due to static electricity and other interferencesAfter booting the controller, all IO buses are in the high impedance input mode by default.
  
-Enamasti on IO siinil olevaid viike peale loogiliste ühenduste kasutatud ka muu perifeeria tarbeksKui on soov kasutada viigu alternatiivfunktsioonituleks tutvuda AVR-i andmelehega, kus on öeldud, mis režiimis peab IO viik olemaNäiteks ADC kanali sisendina kasutamiseks peaks viik olema sisendrežiimis ja PWM signaali genereerimiseks väljundrežiimisMõned perifeeriamoodulid määravad aga ise IO viigu režiimi.+Usually, the pins on the IO bus are also used for other peripherals, aside from the logical connectionsIf there is a need to use the alternate function of the pinthe appropriate IO pin mode can be found in the AVR's datasheetFor example to use an ADC channel as an input, the pin should be in input mode and to generate PWM signal, it should be in output modeOn the other hand, some peripheral modules select the IO pin mode by themselves.
en/avr/io.1267367598.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