ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 02.06.2025
Просмотров: 3657
Скачиваний: 0
When the BOOTRST Fuse is unprogrammed, the boot section size set to 2K bytes and the IVSEL bit in the GICR Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and Interrupt Vector Addresses is:
AddressLabels Code |
Comments |
||
$000 |
rjmp |
RESET |
; Reset handler |
; |
|||
$001 |
RESET:ldi |
r16,high(RAMEND); Main program start |
|
$002 |
out |
SPH,r16 |
; Set Stack Pointer to top of RAM |
$003 |
ldi |
r16,low(RAMEND) |
|
$004 |
out |
SPL,r16 |
|
$005 |
sei |
; Enable interrupts |
|
$006 |
<instr> xxx |
||
; |
|||
.org $c01 |
|||
$c01 |
rjmp |
EXT_INT0 |
; IRQ0 Handler |
$c02 |
rjmp |
EXT_INT1 |
; IRQ1 Handler |
... |
... |
... ; |
|
$c12 |
rjmp |
SPM_RDY |
; Store Program Memory Ready |
Handler
When the BOOTRST Fuse is programmed and the boot section size set to 2K bytes, the most typical and general program setup for the Reset and Interrupt Vector Addresses is:
AddressLabels Code |
Comments |
||
.org $001 |
|||
$001 |
rjmp |
EXT_INT0 |
; IRQ0 Handler |
$002 |
rjmp |
EXT_INT1 |
; IRQ1 Handler |
... |
... |
... |
; |
$012 |
rjmp |
SPM_RDY |
; Store Program Memory Ready |
Handler |
|||
; |
|||
.org $c00 |
|||
$c00 |
rjmp |
RESET |
; Reset handler |
; |
|||
$c01 |
RESET:ldi |
r16,high(RAMEND); Main program start |
|
$c02 |
out |
SPH,r16 |
; Set Stack Pointer to top of RAM |
$c03 |
ldi |
r16,low(RAMEND) |
|
$c04 |
out |
SPL,r16 |
|
$c05 |
sei |
; Enable interrupts |
|
$c06 |
<instr> xxx |
||
46 ATmega8(L)
2486O–AVR–10/04
Moving Interrupts Between
Application and Boot Space
General Interrupt Control
Register – GICR
2486O–AVR–10/04
ATmega8(L)
When the BOOTRST Fuse is programmed, the boot section size set to 2K bytes, and the IVSEL bit in the GICR Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and Interrupt Vector Addresses is:
AddressLabels |
Code |
Comments |
|
; |
|||
.org $c00 |
|||
$c00 |
rjmp |
RESET |
; Reset handler |
$c01 |
rjmp |
EXT_INT0 |
; IRQ0 Handler |
$c02 |
rjmp |
EXT_INT1 |
; IRQ1 Handler |
... |
... |
... ; |
|
$c12 |
rjmp |
SPM_RDY |
; Store Program Memory Ready |
Handler |
|||
$c13 RESET: ldi |
r16,high(RAMEND); Main program start |
||
$c14 |
out |
SPH,r16 |
; Set Stack Pointer to top of RAM |
$c15 |
ldi |
r16,low(RAMEND) |
|
$c16 |
out |
SPL,r16 |
|
$c17 |
sei |
; Enable interrupts |
|
$c18 |
<instr> xxx |
||
The General Interrupt Control Register controls the placement of the Interrupt Vector table.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
INT1 |
INT0 |
– |
– |
– |
– |
IVSEL |
IVCE |
GICR |
|
Read/Write |
R/W |
R/W |
R |
R |
R |
R |
R/W |
R/W |
|
Initial Value |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
• Bit 1 – IVSEL: Interrupt Vector Select
When the IVSEL bit is cleared (zero), the Interrupt Vectors are placed at the start of the Flash memory. When this bit is set (one), the Interrupt Vectors are moved to the beginning of the Boot Loader section of the Flash. The actual address of the start of the boot Flash section is determined by the BOOTSZ Fuses. Refer to the section “Boot Loader Support – Read-While-Write Self-Programming” on page 206 for details. To avoid unintentional changes of Interrupt Vector tables, a special write procedure must be followed to change the IVSEL bit:
1.Write the Interrupt Vector Change Enable (IVCE) bit to one.
2.Within four cycles, write the desired value to IVSEL while writing a zero to IVCE.
Interrupts will automatically be disabled while this sequence is executed. Interrupts are disabled in the cycle IVCE is set, and they remain disabled until after the instruction following the write to IVSEL. If IVSEL is not written, interrupts remain disabled for four cycles. The I-bit in the Status Register is unaffected by the automatic disabling.
Note: If Interrupt Vectors are placed in the Boot Loader section and Boot Lock bit BLB02 is programmed, interrupts are disabled while executing from the Application section. If Interrupt Vectors are placed in the Application section and Boot Lock bit BLB12 is programed, interrupts are disabled while executing from the Boot Loader section. Refer to the section “Boot Loader Support – Read-While-Write Self-Programming” on page 206 for details on Boot Lock Bits.
47
• Bit 0 – IVCE: Interrupt Vector Change Enable
The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware four cycles after it is written or when IVSEL is written. Setting the IVCE bit will disable interrupts, as explained in the IVSEL description above. See Code Example below.
Assembly Code Example
Move_interrupts:
; Enable change of Interrupt Vectors ldi r16, (1<<IVCE)
out GICR, r16
; Move interrupts to boot Flash section ldi r16, (1<<IVSEL)
out GICR, r16 ret
C Code Example
void Move_interrupts(void)
{
/* Enable change of Interrupt Vectors */ GICR = (1<<IVCE);
/* Move interrupts to boot Flash section */ GICR = (1<<IVSEL);
}
48 ATmega8(L)
2486O–AVR–10/04
ATmega8(L) |
|||||||
I/O Ports |
|||||||
Introduction |
All AVR ports have true Read-Modify-Write functionality when used as general digital |
||||||
I/O ports. This means that the direction of one port pin can be changed without uninten- |
|||||||
tionally changing the direction of any other pin with the SBI and CBI instructions. The |
|||||||
same applies when changing drive value (if configured as output) or enabling/disabling |
|||||||
of pull-up resistors (if configured as input). Each output buffer has symmetrical drive |
|||||||
characteristics with both high sink and source capability. The pin driver is strong enough |
|||||||
to drive LED displays directly. All port pins have individually selectable pull-up resistors |
|||||||
with a supply-voltage invariant resistance. All I/O pins have protection diodes to both |
|||||||
VCC and Ground as indicated in Figure 21. Refer to “Electrical Characteristics” on page |
|||||||
239 for a complete list of parameters. |
|||||||
Figure 21. I/O Pin Equivalent Schematic |
|||||||
Rpu |
|
Pxn |
Logic |
Cpin |
See Figure |
"General Digital I/O" for |
|
Details |
All registers and bit references in this section are written in general form. A lower case “x” represents the numbering letter for the port, and a lower case “n” represents the bit number. However, when using the register or bit defines in a program, the precise form must be used (i.e., PORTB3 for bit 3 in Port B, here documented generally as PORTxn). The physical I/O Registers and bit locations are listed in “Register Description for I/O Ports” on page 63.
Three I/O memory address locations are allocated for each port, one each for the Data Register – PORTx, Data Direction Register – DDRx, and the Port Input Pins – PINx. The Port Input Pins I/O location is read only, while the Data Register and the Data Direction Register are read/write. In addition, the Pull-up Disable – PUD bit in SFIOR disables the pull-up function for all pins in all ports when set.
Using the I/O port as General Digital I/O is described in “Ports as General Digital I/O” on page 50. Most port pins are multiplexed with alternate functions for the peripheral features on the device. How each alternate function interferes with the port pin is described in “Alternate Port Functions” on page 54. Refer to the individual module sections for a full description of the alternate functions.
Note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital I/O.
49
2486O–AVR–10/04
Ports as General Digital
I/O
The ports are bi-directional I/O ports with optional internal pull-ups. Figure 22 shows a functional description of one I/O port pin, here generically called Pxn.
Figure 22. General Digital I/O(1)
PUD |
||||
Q D |
||||
DDxn |
||||
Q CLR |
||||
WDx |
||||
RESET |
||||
RDx |
||||
Pxn |
Q D |
|||
PORTxn |
||||
Q CLR |
||||
WPx |
||||
RESET |
||||
SLEEP |
RRx |
|||
SYNCHRONIZER |
||||
RPx |
||||
D |
Q |
D Q |
||
PINxn |
||||
L |
Q |
Q |
||
clk I/O |
||||
PUD: |
PULLUP DISABLE |
WDx: |
WRITE DDRx |
|
RDx: |
READ DDRx |
|||
SLEEP: |
SLEEP CONTROL |
WPx: |
WRITE PORTx |
|
clkI/O: |
I/O CLOCK |
RRx: |
READ PORTx REGISTER |
|
RPx: |
READ PORTx PIN |
|||
DATA BUS
Note: 1. WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, |
|
SLEEP, and PUD are common to all ports. |
|
Configuring the Pin |
Each port pin consists of 3 Register bits: DDxn, PORTxn, and PINxn. As shown in “Reg- |
ister Description for I/O Ports” on page 63, the DDxn bits are accessed at the DDRx I/O |
|
address, the PORTxn bits at the PORTx I/O address, and the PINxn bits at the PINx I/O |
|
address. |
|
The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written |
|
logic one, Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is config- |
|
ured as an input pin. |
|
If PORTxn is written logic one when the pin is configured as an input pin, the pull-up |
|
resistor is activated. To switch the pull-up resistor off, PORTxn has to be written logic |
|
zero or the pin has to be configured as an output pin. The port pins are tri-stated when a |
|
reset condition becomes active, even if no clocks are running. |
|
If PORTxn is written logic one when the pin is configured as an output pin, the port pin is |
|
driven high (one). If PORTxn is written logic zero when the pin is configured as an out- |
|
put pin, the port pin is driven low (zero). |
50 ATmega8(L)
2486O–AVR–10/04