0
我試圖在AtmelStudio 7中使用匯編語言將數字0-9寫入EEPROM存儲器。我做了一個循環,直到計數器達到8(它存儲在R17中,計數器存儲在R16中)。 ATmega16中的EEPROM爲512字節,所以我需要兩個寄存器(低字節和高字節)來指向該內存。 一切工作正常,除了我不能找到一種方式來跟蹤EEPROM內存來檢查數據是否正在寫入。希望有人給我AtmelStudio 7 下面的提示是我的代碼:在裝配中的ATmega16 EEPROM存儲器上寫入一些數字
; 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
從EEPROM中讀取就像寫入,除非您設置EERE然後讀取EEDR。或者,您可以使用並行,SPI或JTAG接口從芯片外部讀取EEPROM。 –