0% found this document useful (0 votes)
31 views

Lab 5 EEPROM

The document discusses EEPROM memory on AVR microcontrollers. It describes the 1024 bytes of EEPROM memory, the registers used to access it, and the procedure to read from and write to EEPROM. It also mentions using macros to structure code when accessing EEPROM to reduce mistakes and code faster.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Lab 5 EEPROM

The document discusses EEPROM memory on AVR microcontrollers. It describes the 1024 bytes of EEPROM memory, the registers used to access it, and the procedure to read from and write to EEPROM. It also mentions using macros to structure code when accessing EEPROM to reduce mistakes and code faster.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Lab 6. EEPROM.

AVR microcontroller architecture


EEPROM Data Memory
The AVR ATmega32A contains 1024bytes of data EEPROM memory. It is organized as a separate data space, in
which single bytes can be read and written. The EEPROM has an endurance of at least 100,000 write/erase
cycles.
The EEPROM Access Registers are accessible in the I/O space. The following procedure should be followed
when reading/writing the EEPROM (the order of steps 3 and 4 is not essential):
1. Wait until EEWE becomes zero;
2. Wait until SPMEN in SPMCR becomes zero;
3. Write new EEPROM address to EEAR (optional);
4. Write new EEPROM data to EEDR (optional);
5. Write a logical one to the EEMWE bit while writing a zero to EEWE in EECR;
6. Within tow/four clock cycles after setting EEMWE, write a logical one to EEWE.

When the EEPROM is read, the CPU is halted for four clock cycles before the next instruction is executed.
When the EEPROM is written, the CPU is halted for two clock cycles before the next instruction is executed.
EEARH and EEARL – EEPROM Address Register
Bit 15 14 13 12 11 10 9 8

- - - - - - EEAR9 EEAR8 EEARH


R/W R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 x x

Bit 7 6 5 4 3 2 1 0

EEAR7 EEAR6 EEAR5 EEAR4 EEAR3 EEAR2 EEAR1 EEAR0 EEARL


R/W R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value x x x x x x x x

• Bits [15:10] – Reserved Bits


These bits are reserved bits in the ATmega32A and will always read as zero.

• Bits [9:0] – EEAR9:0: EEPROM Address


The EEPROM Address Registers – EEARH and EEARL – specify the EEPROM address in the 1024bytes
EEPROM space. The EEPROM data bytes are addressed linearly between 0 and 1023. The initial value
of EEAR is undefined. A proper value must be written before the EEPROM may be accessed.
EEDR – EEPROM Data Register
Bit 7 6 5 4 3 2 1 0

MSB LSB EEDR


R/W R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0

• Bits [7:0] – EEDR7.0: EEPROM Data


For the EEPROM write operation, the EEDR Register contains the data to be written to the EEPROM in
the address given by the EEAR Register. For the EEPROM read operation, the EEDR contains the data
read out from the EEPROM at the address given by EEAR
EECR – EEPROM Control Register
Bit 7 6 5 4 3 2 1 0

- - - - EERIE EEMWE EEWE EERE EECR


R/W R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 x 0

• Bits [7:4] – Reserved Bits


These bits are reserved bits in the ATmega32A and will always read as zero.
• Bit 3 – EERIE: EEPROM Ready Interrupt Enable
Writing EERIE to one enables the EEPROM Ready Interrupt if the I bit in SREG is set. Writing EERIE to zero disables
the interrupt. The EEPROM Ready interrupt generates a constant interrupt when EEWE is cleared.
• Bit 2 – EEMWE: EEPROM Master Write Enable
The EEMWE bit determines whether setting EEWE to one causes the EEPROM to be written. When EEMWE is set,
setting EEWE within four clock cycles will write data to the EEPROM at the selected address If EEMWE is zero,
setting EEWE will have no effect. When EEMWE has been written to one by software, hardware clears the bit to
zero after four clock cycles.
EECR – EEPROM Control Register
• Bit 1 – EEWE: EEPROM Write Enable
The EEPROM Write Enable Signal EEWE is the write strobe to the EEPROM. When address and data are correctly
set up, the EEWE bit must be written to one to write the value into the EEPROM. The EEMWE bit must be written
to one before a logical one is written to EEWE, otherwise no EEPROM write takes place.
• Bit 0 – EERE: EEPROM Read Enable
The EEPROM Read Enable Signal – EERE – is the read strobe to the EEPROM. When the correct address is set up in
the EEAR Register, the EERE bit must be written to a logic one to trigger the EEPROM read. The EEPROM read
access takes one instruction, and the requested data is available immediately. When the EEPROM is read, the CPU
is halted for four cycles before the next instruction is executed.
Assembly - Macros
Assembler macros can be powerful tools that allow you to reuse sequences of code over and over. Creating a
library of macros for your most commonly used functions will allow you to code faster and make less mistakes.
Unlike subroutines where the microcontroller will jump to a new section of code, the assembler will simply
replace macros with the code it represents during assembly.
Macros are defined by placing code between the assembler directives .macro and .endmacro.
Macros can take up to ten parameters (@ 0 to @ 9).
Example main.asm
Example EEPROM.asm
Example EEPROM.asm
Задание
Цель работы: изучить операции чтения/записи данных в EEPROM, научится применять макросы для
структурирования кода.
Необходимо разработать две программы. Первая программа формирует массив С из лабораторной
работы №2 и помещает его в EEPROM. Вторая программа вы вычитывает массив С из EEPROM и выводит
на светодиодные инжекторы минимально или максимальное число согласно варианту на 2
лабораторную работу.
Все обращения к памяти выполнить виде макросов.

You might also like