版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、<p> AVR CPU Core</p><p> Introduction This section discusses the AVR core architecture in general. The main function of the</p><p> CPU core is to ensure correct program execution. The
2、CPU must therefore be able to</p><p> access memories, perform calculations, control peripherals, and handle interrupts.</p><p> Architectural Overview Figure 3. Block Diagram of the AVR MCU A
3、rchitecture</p><p> In order to maximize performance and parallelism, the AVR uses a Harvard architecture</p><p> – with separate memories and buses for program and data. Instructions in the p
4、rogram</p><p> memory are executed with a single level pipelining. While one instruction is being executed,</p><p> the next instruction is pre-fetched from the program memory. This concept<
5、;/p><p> enables instructions to be executed in every clock cycle. The program memory is In-</p><p> System Reprogrammable Flash memory.</p><p> The fast-access Register File contai
6、ns 32 x 8-bit general purpose working registers with</p><p> a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU)</p><p> operation. In a typical ALU operatio
7、n, two operands are output from the Register File,</p><p> the operation is executed, and the result is stored back in the Register File – in one</p><p> clock cycle.</p><p> Six
8、 of the 32 registers can be used as three 16-bit indirect address register pointers for</p><p> Data Space addressing – enabling efficient address calculations. One of the these</p><p> addres
9、s pointers can also be used as an address pointer for look up tables in Flash Program</p><p> memory. These added function registers are the 16-bit X-, Y-, and Z-register,</p><p> described la
10、ter in this section.</p><p> The ALU supports arithmetic and logic operations between registers or between a constant</p><p> and a register. Single register operations can also be executed in
11、 the ALU. After</p><p><b> Flash</b></p><p><b> Program</b></p><p><b> Memory</b></p><p> Instruction</p><p><b&
12、gt; Register</b></p><p> Instruction</p><p><b> Decoder</b></p><p><b> Program</b></p><p><b> Counter</b></p><
13、p> Control Lines</p><p><b> 32 x 8</b></p><p><b> General</b></p><p><b> Purpose</b></p><p> Registrers</p><p>
14、<b> ALU</b></p><p><b> Status</b></p><p> and Control</p><p><b> I/O Lines</b></p><p><b> EEPROM</b></p><
15、;p> Data Bus 8-bit</p><p><b> Data</b></p><p><b> SRAM</b></p><p> Direct Addressing</p><p> Indirect Addressing</p><p><
16、;b> Interrupt</b></p><p><b> Unit</b></p><p><b> SPI</b></p><p><b> Unit</b></p><p><b> Watchdog</b></p
17、><p><b> Timer</b></p><p><b> Analog</b></p><p> Comparator</p><p> I/O Module 2</p><p> I/O Module1</p><p> I/O Mo
18、dule n</p><p><b> 9</b></p><p> ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> an arithmetic operation, the Status Register is updated to reflect informati
19、on about the</p><p> result of the operation.</p><p> Program flow is provided by conditional and unconditional jump and call instructions,</p><p> able to directly address the w
20、hole address space. Most AVR instructions have a single</p><p> 16-bit word format. Every program memory address contains a 16- or 32-bit instruction.</p><p> Program Flash memory space is div
21、ided in two sections, the Boot program section and</p><p> the Application Program section. Both sections have dedicated Lock bits for write and</p><p> read/write protection. The SPM instruct
22、ion that writes into the Application Flash memory</p><p> section must reside in the Boot Program section.</p><p> During interrupts and subroutine calls, the return address Program Counter (P
23、C) is</p><p> stored on the Stack. The Stack is effectively allocated in the general data SRAM, and</p><p> consequently the Stack size is only limited by the total SRAM size and the usage of
24、the</p><p> SRAM. All user programs must initialize the SP in the reset routine (before subroutines</p><p> or interrupts are executed). The Stack Pointer SP is read/write accessible in the I/
25、O</p><p> space. The data SRAM can easily be accessed through the five different addressing</p><p> modes supported in the AVR architecture.</p><p> The memory spaces in the AVR
26、architecture are all linear and regular memory maps.</p><p> A flexible interrupt module has its control registers in the I/O space with an additional</p><p> global interrupt enable bit in th
27、e Status Register. All interrupts have a separate interrupt</p><p> vector in the interrupt vector table. The interrupts have priority in accordance with their</p><p> interrupt vector positio
28、n. The lower the interrupt vector address, the higher the priority.</p><p> The I/O memory space contains 64 addresses for CPU peripheral functions as Control</p><p> Registers, SPI, and other
29、 I/O functions. The I/O Memory can be accessed directly, or as</p><p> the Data Space locations following those of the Register File, $20 - $5F.</p><p> ALU – Arithmetic Logic</p><p
30、><b> Unit</b></p><p> The high-performance AVR ALU operates in direct connection with all the 32 general</p><p> purpose working registers. Within a single clock cycle, arithme
31、tic operations between</p><p> general purpose registers or between a register and an immediate are executed. The</p><p> ALU operations are divided into three main categories – arithmetic, lo
32、gical, and bit-functions.</p><p> Some implementations of the architecture also provide a powerful multiplier</p><p> supporting both signed/unsigned multiplication and fractional format. See
33、the “Instruction</p><p> Set” section for a detailed description.</p><p> Status Register The Status Register contains information about the result of the most recently executed</p><
34、;p> arithmetic instruction. This information can be used for altering program flow in order to</p><p> perform conditional operations. Note that the Status Register is updated after all ALU</p>&
35、lt;p> operations, as specified in the Instruction Set Reference. This will in many cases</p><p> remove the need for using the dedicated compare instructions, resulting in faster and</p><p>
36、; more compact code.</p><p> The Status Register is not automatically stored when entering an interrupt routine and</p><p> restored when returning from an interrupt. This must be handled by
37、software.</p><p> The AVR Status Register – SREG – is defined as:</p><p> Bit 7 6 5 4 3 2 1 0</p><p> I T H S V N Z C SREG</p><p> Read/Write R/W R/W R/W R/W R/W R/
38、W R/W R/W</p><p> Initial Value 0 0 0 0 0 0 0 0</p><p> 10 ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> ? Bit 7 – I: Global Interrupt Enable</p><p> Th
39、e Global Interrupt Enable bit must be set for the interrupts to be enabled. The individual</p><p> interrupt enable control is then performed in separate control registers. If the Global</p><p>
40、; Interrupt Enable Register is cleared, none of the interrupts are enabled independent of</p><p> the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt</p>&l
41、t;p> has occurred, and is set by the RETI instruction to enable subsequent interrupts. The Ibit</p><p> can also be set and cleared by the application with the SEI and CLI instructions, as</p>&l
42、t;p> described in the instruction set reference.</p><p> ? Bit 6 – T: Bit Copy Storage</p><p> The Bit Copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T-bit as source or</p
43、><p> destination for the operated bit. A bit from a register in the Register File can be copied</p><p> into T by the BST instruction, and a bit in T can be copied into a bit in a register in th
44、e</p><p> Register File by the BLD instruction.</p><p> ? Bit 5 – H: Half Carry Flag</p><p> The Half Carry Flag H indicates a Half Carry in some arithmetic operations. Half Carr
45、y is</p><p> useful in BCD arithmetic. See the “Instruction Set Description” for detailed information.</p><p> ? Bit 4 – S: Sign Bit, S = N ⊕ V</p><p> The S-bit is always an exc
46、lusive or between the Negative Flag N and the Two’s Complement</p><p> Overflow Flag V. See the “Instruction Set Description” for detailed information.</p><p> ? Bit 3 – V: Two’s Complement Ov
47、erflow Flag</p><p> The Two’s Complement Overflow Flag V supports two’s complement arithmetics. See</p><p> the “Instruction Set Description” for detailed information.</p><p> ?
48、Bit 2 – N: Negative Flag</p><p> The Negative Flag N indicates a negative result in an arithmetic or logic operation. See</p><p> the “Instruction Set Description” for detailed information.<
49、;/p><p> ? Bit 1 – Z: Zero Flag</p><p> The Zero Flag Z indicates a zero result in an arithmetic or logic operation. See the</p><p> “Instruction Set Description” for detailed infor
50、mation.</p><p> ? Bit 0 – C: Carry Flag</p><p> The Carry Flag C indicates a carry in an arithmetic or logic operation. See the “Instruction</p><p> Set Description” for detailed
51、 information.</p><p><b> 11</b></p><p> ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> General Purpose</p><p> Register File</p><p
52、> The Register File is optimized for the AVR Enhanced RISC instruction set. In order to</p><p> achieve the required performance and flexibility, the following input/output schemes are</p><p&
53、gt; supported by the Register File:</p><p> ? One 8-bit output operand and one 8-bit result input</p><p> ? Two 8-bit output operands and one 8-bit result input</p><p> ? Two 8-
54、bit output operands and one 16-bit result input</p><p> ? One 16-bit output operand and one 16-bit result input</p><p> Figure 4 shows the structure of the 32 general purpose working registers
55、 in the CPU.</p><p> Figure 4. AVR CPU General Purpose Working Registers</p><p> Most of the instructions operating on the Register File have direct access to all registers,</p><p&g
56、t; and most of them are single cycle instructions.</p><p> As shown in Figure 4, each register is also assigned a data memory address, mapping</p><p> them directly into the first 32 location
57、s of the user Data Space. Although not being physically</p><p> implemented as SRAM locations, this memory organization provides great</p><p> flexibility in access of the registers, as the X-
58、, Y-, and Z-pointer Registers can be set to</p><p> index any register in the file.</p><p><b> 7 0 Addr.</b></p><p><b> R0 $00</b></p><p><
59、;b> R1 $01</b></p><p><b> R2 $02</b></p><p><b> …</b></p><p><b> R13 $0D</b></p><p> General R14 $0E</p><p&
60、gt; Purpose R15 $0F</p><p> Working R16 $10</p><p> Registers R17 $11</p><p><b> …</b></p><p> R26 $1A X-register Low Byte</p><p> R27 $1
61、B X-register High Byte</p><p> R28 $1C Y-register Low Byte</p><p> R29 $1D Y-register High Byte</p><p> R30 $1E Z-register Low Byte</p><p> R31 $1F Z-register High
62、Byte</p><p> 12 ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> The X-register, Y-register and</p><p> Z-register</p><p> The registers R26..R31 have some
63、 added functions to their general purpose usage.</p><p> These registers are 16-bit address pointers for indirect addressing of the Data Space.</p><p> The three indirect address registers X,
64、Y, and Z are defined as described in Figure 5.</p><p> Figure 5. The X-, Y-, and Z-registers</p><p> In the different addressing modes these address registers have functions as fixed displacem
65、ent,</p><p> automatic increment, and automatic decrement (see the Instruction Set</p><p> Reference for details).</p><p> Stack Pointer The Stack is mainly used for storing temp
66、orary data, for storing local variables and for</p><p> storing return addresses after interrupts and subroutine calls. The Stack Pointer Register</p><p> always points to the top of the Stack
67、. Note that the Stack is implemented as growing</p><p> from higher memory locations to lower memory locations. This implies that a Stack</p><p> PUSH command decreases the Stack Pointer. If s
68、oftware reads the Program Counter</p><p> from the Stack after a call or an interrupt, unused bits (15:13) should be masked out.</p><p> The Stack Pointer points to the data SRAM Stack area wh
69、ere the Subroutine and Interrupt</p><p> Stacks are located. This Stack space in the data SRAM must be defined by the</p><p> program before any subroutine calls are executed or interrupts are
70、 enabled. The Stack</p><p> Pointer must be set to point above $60. The Stack Pointer is decremented by one when</p><p> data is pushed onto the Stack with the PUSH instruction, and it is decr
71、emented by two</p><p> when the return address is pushed onto the Stack with subroutine call or interrupt. The</p><p> Stack Pointer is incremented by one when data is popped from the Stack wi
72、th the POP</p><p> instruction, and it is incremented by two when data is popped from the Stack with return</p><p> from subroutine RET or return from interrupt RETI.</p><p> The
73、 AVR Stack Pointer is implemented as two 8-bit registers in the I/O space. The number</p><p> of bits actually used is implementation dependent. Note that the data space in some</p><p> implem
74、entations of the AVR architecture is so small that only SPL is needed. In this</p><p> case, the SPH Register will not be present.</p><p> 15 XH XL 0</p><p> X - register 7 07 0&
75、lt;/p><p> R27 ($1B) R26 ($1A)</p><p> 15 YH YL 0</p><p> Y - register 7 07 0</p><p> R29 ($1D) R28 ($1C)</p><p> 15 ZH ZL 0</p><p> Z - re
76、gister 7 0 7 0</p><p> R31 ($1F) R30 ($1E)</p><p> Bit 15 14 13 12 11 10 9 8</p><p> SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 SPH</p><p> SP7 SP6 SP5 SP4 SP3 SP2 SP1 S
77、P0 SPL</p><p> 7 6 5 4 3 2 1 0</p><p> Read/Write R/W R/W R/W R/W R/W R/W R/W R/W</p><p> R/W R/W R/W R/W R/W R/W R/W R/W</p><p> Initial Value 0 0 0 0 0 0 0 0</
78、p><p> 0 0 0 0 0 0 0 0</p><p><b> 13</b></p><p> ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> Instruction Execution</p><p><b&
79、gt; Timing</b></p><p> This section describes the general access timing concepts for instruction execution. The</p><p> AVR CPU is driven by the CPU clock clkCPU, directly generated fro
80、m the selected clock</p><p> source for the chip. No internal clock division is used.</p><p> Figure 6 shows the parallel instruction fetches and instruction executions enabled by the</p>
81、;<p> Harvard architecture and the fast-access Register File concept. This is the basic pipelining</p><p> concept to obtain up to 1 MIPS per MHz with the corresponding unique results for</p>
82、<p> functions per cost, functions per clocks, and functions per power-unit.</p><p> Figure 6. The Parallel Instruction Fetches and Instruction Executions</p><p> Figure 7 shows the int
83、ernal timing concept for the Register File. In a single clock cycle</p><p> an ALU operation using two register operands is executed, and the result is stored back</p><p> to the destination r
84、egister.</p><p> Figure 7. Single Cycle ALU Operation</p><p> Reset and Interrupt</p><p><b> Handling</b></p><p> The AVR provides several different int
85、errupt sources. These interrupts and the separate</p><p> reset vector each have a separate program vector in the program memory space. All</p><p> interrupts are assigned individual enable bi
86、ts which must be written logic one together</p><p> with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt.</p><p> Depending on the Program Counter value
87、, interrupts may be automatically disabled</p><p> when Boot Lock bits BLB02 or BLB12 are programmed. This feature improves software</p><p> security. See the section “Memory Programming” on p
88、age 262 for details.</p><p> The lowest addresses in the program memory space are by default defined as the Reset</p><p> and Interrupt Vectors. The complete list of vectors is shown in “Inter
89、rupts” on page 45.</p><p> The list also determines the priority levels of the different interrupts. The lower the</p><p> address the higher is the priority level. RESET has the highest prior
90、ity, and next is INT0</p><p><b> clk</b></p><p> 1st Instruction Fetch</p><p> 1st Instruction Execute</p><p> 2nd Instruction Fetch</p><p>
91、; 2nd Instruction Execute</p><p> 3rd Instruction Fetch</p><p> 3rd Instruction Execute</p><p> 4th Instruction Fetch</p><p> T1 T2 T3 T4</p><p><b
92、> CPU</b></p><p> Total Execution Time</p><p> Register Operands Fetch</p><p> ALU Operation Execute</p><p> Result Write Back</p><p> T1 T2
93、 T3 T4</p><p><b> clkCPU</b></p><p> 14 ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> – the External Interrupt Request 0. The Interrupt Vectors can be mov
94、ed to the start of</p><p> the Boot Flash section by setting the IVSEL bit in the General Interrupt Control Register</p><p> (GICR). Refer to “Interrupts” on page 45 for more information. The
95、Reset Vector can</p><p> also be moved to the start of the boot Flash section by programming the BOOTRST</p><p> Fuse, see “Boot Loader Support – Read-While-Write Self-Programming” on page 249
96、.</p><p> When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts</p><p> are disabled. The user software can write logic one to the I-bit to enable nested in
97、terrupts.</p><p> All enabled interrupts can then interrupt the current interrupt routine. The I-bit is</p><p> automatically set when a Return from Interrupt instruction – RETI – is executed.
98、</p><p> There are basically two types of interrupts. The first type is triggered by an event that</p><p> sets the Interrupt Flag. For these interrupts, the Program Counter is vectored to the
99、</p><p> actual Interrupt Vector in order to execute the interrupt handling routine, and hardware</p><p> clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writin
100、g a</p><p> logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the</p><p> corresponding interrupt enable bit is cleared, the Interrupt Flag will be se
101、t and remembered</p><p> until the interrupt is enabled, or the flag is cleared by software. Similarly, if one or</p><p> more interrupt conditions occur while the Global Interrupt Enable bit
102、is cleared, the corresponding</p><p> Interrupt Flag(s) will be set and remembered until the global interrupt enable</p><p> bit is set, and will then be executed by order of priority.</p&g
103、t;<p> The second type of interrupts will trigger as long as the interrupt condition is present.</p><p> These interrupts do not necessarily have Interrupt Flags. If the interrupt condition disappea
104、rs</p><p> before the interrupt is enabled, the interrupt will not be triggered.</p><p> When the AVR exits from an interrupt, it will always return to the main program and execute</p>
105、<p> one more instruction before any pending interrupt is served.</p><p> Note that the Status Register is not automatically stored when entering an interrupt routine,</p><p> nor restor
106、ed when returning from an interrupt routine. This must be handled by</p><p><b> software.</b></p><p> When using the CLI instruction to disable interrupts, the interrupts will be i
107、mmediately</p><p> disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously</p><p> with the CLI instruction. The following example shows how this ca
108、n be used to</p><p> avoid interrupts during the timed EEPROM write sequence.</p><p> Assembly Code Example</p><p> in r16, SREG ; store SREG value</p><p> cli ; di
109、sable interrupts during timed sequence</p><p> sbi EECR, EEMWE ; start EEPROM write</p><p> sbi EECR, EEWE</p><p> out SREG, r16 ; restore SREG value (I-bit)</p><p>
110、 C Code Example</p><p> char cSREG;</p><p> cSREG = SREG; /* store SREG value */</p><p> /* disable interrupts during timed sequence */</p><p><b> _CLI();<
111、;/b></p><p> EECR |= (1<<EEMWE); /* start EEPROM write */</p><p> EECR |= (1<<EEWE);</p><p> SREG = cSREG; /* restore SREG value (I-bit) */</p><p><
112、;b> 15</b></p><p> ATmega16(L)</p><p> 2466N–AVR–10/06</p><p> When using the SEI instruction to enable interrupts, the instruction following SEI will be</p><
113、;p> executed before any pending interrupts, as shown in this example.</p><p> Interrupt Response Time The interrupt execution response for all the enabled AVR interrupts is four clock cycles</p>
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 單片機(jī)中英文翻譯
- 中英文翻譯--單片機(jī)
- 單片機(jī)中英文資料翻譯
- 基于單片機(jī)外文翻譯@中英文翻譯@外文文獻(xiàn)翻譯
- 畢業(yè)設(shè)計外文翻譯---單片機(jī)的組成(中英文)
- 單片機(jī)89c52中英文對照翻譯(經(jīng)典版)
- 中英文外文翻譯--基于單片機(jī)的汽車防盜報警系統(tǒng)設(shè)計
- 單片機(jī)設(shè)計外文文獻(xiàn)翻譯(含中英文)
- 中英文外文翻譯--基于單片機(jī)的汽車防盜報警系統(tǒng)設(shè)計.doc
- 沖壓外文翻譯中英文對照論文
- 中英文外文翻譯--基于單片機(jī)的汽車防盜報警系統(tǒng)設(shè)計.doc
- 單片機(jī)畢業(yè)設(shè)計中英文翻譯---單片機(jī)技術(shù)的發(fā)展與應(yīng)用
- at89s52單片機(jī)應(yīng)用中英文翻譯
- 單片機(jī)溫度控制系統(tǒng)中英文翻譯資料
- 畢業(yè)設(shè)計英文文獻(xiàn):51單片機(jī)中英文文獻(xiàn)翻譯
- 單片機(jī)電子技術(shù)中英文翻譯
- 單片機(jī)籃球計分器畢業(yè)論文中英文資料外文翻譯文獻(xiàn)
- 地質(zhì)外文文獻(xiàn)翻譯中英文對照
- 單片機(jī)的發(fā)展和應(yīng)用畢業(yè)課程設(shè)計外文文獻(xiàn)翻譯、中英文翻譯、外文翻譯
- 成本控制中英文對照外文翻譯文獻(xiàn)
評論
0/150
提交評論