atmega161-4pi ATMEL Corporation, atmega161-4pi Datasheet - Page 22

no-image

atmega161-4pi

Manufacturer Part Number
atmega161-4pi
Description
8-bit Microcontroller With 16k Bytes Of In-system Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet
Stack Pointer – SP
Reset and Interrupt
Handling
22
ATmega161(L)
• Bit 2
The Negative Flag N indicates a negative result after the different arithmetic and logic
operations. See the Instruction Set description for detailed information.
• Bit 1
The Zero Flag Z indicates a zero result after the different arithmetic and logic opera-
tions. See the Instruction Set description for detailed information.
• Bit 0
The Carry Flag C indicates a carry in an arithmetic or logic operation. See the Instruction
Set description for detailed information.
Note that the Status Register is not automatically stored when entering an interrupt rou-
tine and restored when returning from an interrupt routine. This must be handled by
software.
The ATmega161 Stack Pointer is implemented as two 8-bit registers in the I/O space
locations $3E ($5E) and $3D ($5D). As the ATmega161 supports up to 64-Kbyte mem-
ory, all 16 bits are used.
The Stack Pointer points to the data SRAM Stack area where the Subroutine and Inter-
rupt Stacks are located. This Stack space in the data SRAM must be defined by the
program before any subroutine calls are executed or interrupts are enabled. The Stack
Pointer must be set to point above $60. The Stack Pointer is decremented by 1 when
data is pushed onto the Stack with the PUSH instruction, and it is decremented by 2
when an address is pushed onto the Stack with subroutine calls and interrupts. The
Stack Pointer is incremented by 1 when data is popped from the Stack with the POP
instruction, and it is incremented by 2 when an address is popped from the Stack with
return from subroutine RET or return from interrupt (RETI).
The ATmega161 provides 20 different interrupt sources. These interrupts and the sepa-
rate Reset Vector each have a separate Program Vector in the Program memory space.
All interrupts are assigned individual enable bits that must be set (one) together with the
I-bit in the Status Register in order to enable the interrupt.
The lowest addresses in the Program memory space are automatically defined as the
Reset and Interrupt vectors. The complete list of Vectors is shown in Table 2. The list
also determines the priority levels of the different interrupts. The lower the address, the
higher the priority level. RESET has the highest priority, and next is INT0 (the External
Interrupt Request 0) and so on.
Bit
$3E ($5E)
$3D ($5D)
Read/Write
Initial Value
N: Negative Flag
Z: Zero Flag
C: Carry Flag
SP15
R/W
R/W
SP7
15
7
0
0
SP14
R/W
R/W
SP6
14
6
0
0
SP13
R/W
R/W
SP5
13
5
0
0
SP12
SP4
R/W
R/W
12
4
0
0
SP11
SP3
R/W
R/W
11
3
0
0
SP10
SP2
R/W
R/W
10
2
0
0
SP9
SP1
R/W
R/W
9
1
0
0
SP8
SP0
R/W
R/W
1228D–AVR–02/07
8
0
0
0
SPH
SPL

Related parts for atmega161-4pi