本帖最后由 15811817818 于 2019-12-4 13:39 编辑
各位大师好!我在做一个小产品,选用了PIC1508芯片,因该芯片没有EEPROM,所以用闪存程序存储器作为数据存储,可调试了两天没成功,能读能写,可断电后再读,就没有了原保存的数据,读和擦除功能都正常。写代码如下:恳请各位大师帮看一下,问题出去哪?谢谢!
WRITE
CALL ERASURE_A ;先擦除再写入
BCF INTCON,GIE ; Disable ints so required sequences will execute properly
BANKSEL PMADRH ; Bank 3
MOVLW 0X0B ; Load initial address
MOVWF PMADRH
MOVLW 0X00
MOVWF PMADRL
MOVLW 0X60 ; Load initial data address
MOVWF FSR0L
MOVLW 0X00 ; Load initial data address
MOVWF FSR0H
BCF PMCON1,CFGS ; Not configuration space
BSF PMCON1,WREN ; Enable writes
BSF PMCON1,LWLO ; Only Load Write Latches
WRITE_LOOP
MOVIW FSR0++ ; Load first data byte into lower
MOVWF PMDATL
MOVIW FSR0++ ; Load second data byte into upper
MOVWF PMDATH
MOVF PMADRL,W ; Check if lower bits of address are '00000'
XORLW 0x17 ; Check if we're on the last of 32 addresses
ANDLW 0x17
BTFSC STATUS,Z ; Exit if last of 32 words,
GOTO START_WRITE
MOVLW 55h ; Start of required write sequence:
MOVWF PMCON2 ; Write 55h
MOVLW 0AAh
MOVWF PMCON2 ; Write AAh
BSF PMCON1,WR ; Set WR bit to begin write
NOP ; NOP instructions are forced as processor loads program memory write latches
NOP
INCF PMADRL ; Still loading latches Increment address
GOTO WRITE_LOOP ; Write next latches
START_WRITE
BCF PMCON1,LWLO ; No more loading latches - Actually start Flash program memory write
MOVLW 55h ; Start of required write sequence:
MOVWF PMCON2 ; Write 55h
MOVLW 0AAh
MOVWF PMCON2 ; Write AAh
BSF PMCON1,WR ; Set WR bit to begin write
NOP
NOP
BCF PMCON1,WREN ; Disable writes
BANKSEL W_TEMP
CALL DELAY_RC
BSF INTCON,GIE ; Enable interrupts
RETURN |