Search code examples
assemblyavratmega16

Writing some numbers on ATmega16 EEPROM memory in assembly


I'm trying to write numbers 0-9 to the EEPROM memory using assembly language in AtmelStudio 7. I made a loop until the counter reaches 8 (which is stored in R17 and a counter which is stored in R16). EEPROM in ATmega16 is 512 bytes so I will need two registers(Low and High bytes) to point to that memory. everything is working fine except that i cant find a way to track EEPROM memory to check if the data is being written or not. Hope someone gives me a hint with AtmelStudio 7. Here is my code:

; Replace with your application code
start:
/* Define a counter in R16 */
ldi R16,0
ldi R17,8
/* EEPROM Address to be written */
ldi R18,0x00
ldi R19,0x00
/* Loop through this untill 9 numbers are written */
EEPROM_WRITE:
/* Wait untill the EEWE gets 0 */
/* Skip next instruction if EEWE is clear in EECR */
sbic EECR,EEWE
rjmp EEPROM_WRITE   
/* Write the address to be filled with the number :D */
out EEARL,R18
out EEARH,R19   
/* Write the data */
/* Counter can be used itself */
out EEDR,R16
/* Write logical one to the EEMWE */
/* Set bit immediate */
sbi EECR,EEMWE
/* Start write */
sbi EECR,EEWE
/* Add 1 to the counter */
inc R16
/* Go to the next address on EEPROM */
inc R18
/* Check the loop end point */
cp R16,R17
brne EEPROM_WRITE
rjmp EEPROM_WRITE
rjmp start

Solution

  • If you want to track EEPROM in atmel studio, than you need to start debug session and open memory window (Alt+6). There should be drop down list where should be eepom option. You can verify your data there.