Hardware => EEPROM
(Diese Seite in Deutsch:
; Demonstrates the use of the EEPROM
; During programming a counter location, defined in
; is set to zero. At every restart of
the processor this counter is incremented
; and its content is displayed in
hex format on the LEDs.
; Please refer to the hints given on the end of this code to avoid
; some confusion.
; Define constants
.equ cnt=$0000 ; Adress
of the counter location in the EEPROM
; Define registers
.def mpr=R16 ;
.def neu=R17 ;
Counter value interim storage
; Jump to main program
; all bits of Port
B are output
; Set EEPROM
; to the EEPROM-adress port
; Low/High-Byte separate
; EEPROM has 512 Byte
; Set Read-Enable-Bit
; Read byte from EPROM-location
; Increment counter and write back to EEPROM
; If EEPROM busy, wait first
; Busy Bit 1 in
; not ready, wait
; The EEPROM-Adress is still correct,
so we don't need to adjust it
; We just transfer the new data to the EEPROM-data
; New value to EEPROM-Data register
; The following two write commands must
not be interrupted, because safe write operations
; are only valid if these come within four commands. Otherwise hardware skips the
; Interrupts must be disabled therefore (interrupts are not used here).
; Now the two write commands:
; Switches EEPROM Master Write Enable
; Enables write operation in the EEPROM
; Within the following 1,5 milliseconds the byte
is written to the EEPROM location.
; This is sensitive only in case you want to
use the EEPROM for further operations.
; Not here: We write the inverted content of the counter to the LEDs on Port
; and end the program in
an indefinit loop.
; to Port B
loop: RJMP loop
; wait forever.
; Here starts the setting of the counter to zero during programming
; First we have to tell the assembler
that the following code goes to the EEPROM
; and not to the code segment:
; Now the content of the EEPROM-segment:
.DB $00 ; A Byte
with a zero
; That's it.
; IMPORTANT HINTS
; During programming the content of the EEPROM-file
; will be loaded separately and programmed
after the code is loaded.
; Don't forget this!
; During the programming sequence of the different locations for code
; and EEPROM
content the software for the board releases the Reset
; of the processor, e.g. between programming and
verification. As this
; short pause already causes the processor to restart and
; code. Verification of the EEPROM content
will therefore fail, because
; the counter is already incremented and does
not match its original
; programmed value. Every read operation of the EEPROM
; onboard will have the same effect.
; The execution of the restart command using the ISP
; causes multiple startups of the processor and
increases the counter
; value, so don't expect to see correct counting values.
; Exact up-counts are only seen when switching the supply voltage
; of the board off and on.
; To avoid unwanted upcounting during program, verification and
; operation would require setting a startup delay time, but this is a
; little bit too complex for a beginner.
Back to the Hardware page
©2002 by http://www.avr-asm-tutorial.net