当前位置: 动力学知识库 > 问答 > 编程问答 >

assembly - Writing to EEPROM PIC?

问题描述:

I'm working on a project in which i need to be able to store a value to the PIC's EEPROM, I have managed to get the read to work but so far i am unable to get the PIC to write to the memory using PIC assembly. This is the code that i have been using , it is derived from the example write code from the data sheet, I am using the 16D630 PIC, and using the PIC assembly language.

MOVLW 0x02

MOVWF EEADR

MOVLW 0x01

MOVWF EEDATA

BSF STATUS,RP0 ;BANK 1

BSF EECON1,WREN ;ENABLE WRITE

BCF INTCON,GIE ;DISABLE INTS

MOVLW 0x55 ;UNLOCK WRITE

MOVWF EECON2 ;

MOVLW 0xAA ;

MOVWF EECON2 ;

BSF EECON1,WR ;START THE WRITE

BSF INTCON,GIE ;ENABLE INTS

网友答案:

Set appropriate memory bank before your program load EEADR and EEDATA values.

Use "Watch" window to control values in registers EEADR and EEDATA when you are stepping (F7) over program lines in debbug mode!

BSF STATUS,RP0       ;Set BANK 1 first !!!
MOVLW 0x02
MOVWF EEADR
MOVLW 0x01
MOVWF EEDATA

BSF EECON1,WREN ;ENABLE WRITE
BCF INTCON,GIE ;DISABLE INTS
MOVLW 0x55 ;UNLOCK WRITE
MOVWF EECON2 ;
MOVLW 0xAA ;
MOVWF EECON2 ;
BSF EECON1,WR ;START THE WRITE
BSF INTCON,GIE ;ENABLE INTS
网友答案:

Before you enable the write WREN flag you should indicate whether you intend to write into program memory (flash) or into eeprom by setting/clearing EEPGD flag in EECON1.

分享给朋友:
您可能感兴趣的文章:
随机阅读: