B001 - Atmega16 - Assembly - Address space allocation

Publisher:创新之梦Latest update time:2022-01-30 Source: eefocusKeywords:Atmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Address space planning

Open m16def.inc and you can see the following definition, which corresponds one-to-one with the address space of FlashROM, SRAM, EEPROM, etc. described in the manual.


; ***** DATA MEMORY DECLARATIONS *****************************************

.equ FLASHEND = 0x1fff ; Note: Word address, here is a total of 8K word flash ROM

.equ IOEND     = 0x003f ; The address space of IO registers is 0x0000-0x003F, but they are mapped to 0x0020-0x005F

.equ SRAM_START = 0x0060; 0x0060-0x0045F This 1KB address space is the address space used by the internal RAM

.equ SRAM_SIZE = 1024;

.equ RAMEND = 0x045f;

.equ XRAMEND = 0x0000 ; This may be the address space reserved for external RAM - question-001

.equ E2END    = 0x01ff; EEPROM has a total of 512B, occupying the address space of 0x0000-0x01FF

.equ EEPROMEND = 0x01ff; This address is sent to the EEPROM control register for use

.equ EEADRBITS = 9 ; 512 cells require 9 address lines to access

#pragma AVRPART MEMORY PROG_FLASH 16384 ; 8K word = 16K byte

#pragma AVRPART MEMORY EEPROM 512

#pragma AVRPART MEMORY INT_SRAM SIZE 1024

#pragma AVRPART MEMORY INT_SRAM START_ADDR 0x60

After the compiler is finished compiling, the usage of FlashROM (.cseg), SRAM (.dseg), and EEPROM (.eseg) will be given:

illustrate:

1. When using the in and out instructions to access IO registers, these two instructions use the address space of 0x0000-0x003F to access IO registers.

2. When using ld and st instructions to access IO registers, you need to use the mapped address space 0x0020-0x005F ([0x0000, 0x003F]+0x0020) to access IO registers.


       IO registers such as PORTB and SREG are defined in the m16def.inc file according to the address space of 0x0000-0x003F.


       Therefore, when using the ld and st instructions, the register address needs to be added with 0x0020: PORTB + 0x20, SREG + 0x20.



Stack space in RAM

0. The stack (actually refers to the stack) is also part of the RAM, but it can be accessed in FILO form using special instructions push/pop and the stack pointer SP (the address automatically increases or decreases in SP).


      In DEBUG mode, we can see that the SP pointer is placed at the end of the RAM, growing downwards from the back.


1. In the reset interrupt service routine, the stack pointer SP is set to 0x045F, which is the last unit of the RAM address space:

RAMEND is defined in m16def.inc as follows (part of the above code):


.equ RAMEND = 0x045f

2. The push instruction saves the data in R20 to the RAM unit pointed to by the SP pointer, that is, pushes it onto the stack:

3. Pop instruction, take out the contents of the RAM unit pointed to by SP pointer and put it into R20, that is, pop the stack:

Keywords:Atmega16 Reference address:B001 - Atmega16 - Assembly - Address space allocation

Previous article:B001-Atmega16-PORTA definition-(ques=1)
Next article:B001 - Atmega16 - Alignment Mode and Endianness

Recommended ReadingLatest update time:2024-11-21 21:09

B001 - Atmega16 - Alignment Mode and Endianness
Test to determine the alignment and endianness of Atmega16 Post the results first: - Little endian mode - No alignment requirement (1 byte alignment) Test code // Test variables struct {     uint8_t  type0;     uint16_t code0;     uint8_t  type1;     uint16_t code1;     uint32_t data; }code_data; uint32_t second 
[Microcontroller]
B001 - Atmega16 - Alignment Mode and Endianness
Design of electric vehicle lithium battery pack based on ATmega16
Introduction: Through experiments, this protection circuit system has realized all basic functions. Compared with the traditional battery protection system using separate components, the battery protection circuit system based on single chip microcomputer proposed in this paper has the characteristics of small system
[Microcontroller]
Design of electric vehicle lithium battery pack based on ATmega16
ATmega16 Development Board Tutorial (3) - 74HC595 driving digital tube display
4. Digital tube display The digital tube drive circuit uses two 74HC595 chips for IO expansion, and only 3 pins are needed to drive a digital tube that requires 16 pins. 74HC595 is an 8-bit serial input and parallel output displacement buffer. Only by understanding the working principle and timing of 74HC595 clearly
[Microcontroller]
ATmega16 Development Board Tutorial (3) - 74HC595 driving digital tube display
Design of indoor lighting control system based on Atmega16
An improved indoor lighting system design based on intelligent detection technology is proposed to overcome the shortcomings of traditional lighting systems. The pyroelectric human infrared and temperature sensing system is used to combine whether there are people in the room and whether the ambient light brightness is
[Power Management]
Design of indoor lighting control system based on Atmega16
Design of remote temperature difference cycle controller based on ATmega16
Introduction The integration of solar energy and buildings is an inevitable trend in the development of urban buildings, and split-type pressurized solar water heaters are the basic direction of solar energy development. Since the heat collection part of the split-type solar water heating system is separate
[Microcontroller]
Method of Designing Temperature Controller of Electric Boiler Using ATmega16
    Electric boilers can directly convert electrical energy into thermal energy. They have the advantages of high thermal efficiency, small size, no pollution, low noise, safe and reliable operation, stable heating, and a high degree of automation. They are ideal energy-saving and environmentally friendly heating eq
[Microcontroller]
Method of Designing Temperature Controller of Electric Boiler Using ATmega16
ATmega16 Core Introduction
Figure 3. Block diagram of the AVR architecture To achieve the highest performance and parallelism, AVR uses Harvard architecture with independent data and program buses. Instructions in the program memory are run through a one-stage pipeline. The CPU reads the next instruction while executing one instruction (cal
[Microcontroller]
ATmega16 Core Introduction
ATMEGA16 multi-channel AD acquisition
    // Setting ADEN starts the ADC, otherwise the ADC function is turned off. Turning off the ADC during the conversion process will immediately terminate the ongoing conversion. At the same time, clearing ADEN will clear ADIE (AD end interrupt enable). In addition, if ADEN is not cleared in continuous mode,
[Microcontroller]
ATMEGA16 multi-channel AD acquisition
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号