Microchip
直播中

孙乙鑫

7年用户 239经验值
私信 关注
[问答]

PIC18F4620 EEPROM写问题

我为PIC18F87做了一个程序,还行。然后我必须把相同的代码迁移到PIC18F4620。该代码具有LCD、UART和七段显示器的接口。最后,所有的问题都在运行…除了EEPROM写函数。这个函数有不稳定的行为。我用的代码和数据表是一样的:EEPROFBCFECONE1,EEPGD;EngDeloBcCfEnEn1,CFGS;1=CONFIG。寄存器,0=闪存O DAT0S.BSFEFEC1,WRE;HabiTeA ECRITURBABCIMCONTRON,GIE;DeHabistia中断;MOVLW0x5MOVL2WAXAMOVOVWEF2BSFEFECO1,WR;BSFIMTCON,GIE;Habista中断;用户代码执行;用户代码执行BCFEFECO1,WRN;DeHabista ESCRITURA AL完成(EEIF集)BCFPIR2,EEFEURTURNI AM写入10个连续的循环:CyeDefBANCO,0;BANCO 1MOVWMNCNDMOVLW0XAM0VFWMulPLRCALMYPYS;(BANCO-1)*10MOVFLYBY字节,WMOVWWDATAWAYAXADYDR;Valor表DFSMOVFWFFRSR0LANDERMOVEVFDF0,WMOVWFDATAYEEDATAL写的CurfDATAEE该程序具有用于EUSAT功能的高中断例程。每次接收到来自EUART的消息时,都有中断,称为InIT例程。这个特性运行正常!高科代码0x000 08GotoIndiTI真的混淆了这个PIC中的中断功能。我不知道EEPROM写的问题是由于中断…还是我的代码…或者…我会感谢你们在这个问题上的善意支持。

以上来自于百度翻译


      以下为原文

    I made a program for PIC18f887 and was OK.
Then I have to migrate the same code to the PIC 18F4620.
The code have interfaces to LCD, UART and 7 segments displays. Finally, all issues are running OK....except the EEPROM write function.
This function has and erratic behavior.
The code I am using to write is the same one of the data sheet:

; RUTINA ESCRIBIR EN EEPROM
WRITE  
   MOVF DATA_EE_ADDRH,W
   MOVWF EEADRH
   MOVF DATA_EE_ADDR,W
   MOVWF EEADR
   MOVF DATA_EE_DATA,W
   MOVWF EEDATA     ; DATO A SER ESCRITO EN LA EEPROM
   BCF  EECON1,EEPGD   ; SERA EN LA MEMORIA DE DATOS
   BCF  EECON1,CFGS    ; 1=CONFIG. REGISTERS, 0=FLASH O DAT0S.
   BSF  EECON1,WREN    ; HABILITA ESCRITURA
   
   BCF  INTCON,GIE    ; DESHABILITA INTERRUPCIONES        ;
   MOVLW 0X55
   MOVWF EECON2
   MOVLW 0XAA
   MOVWF EECON2
   BSF  EECON1,WR    ;
   BSF  INTCON,GIE    ; HABILITA INTERRUPCIONES
           ; USER CODE EXECUTION
           ; USER CODE EXECUTION
   BCF  EECON1,WREN    ; DESHABILITA ESCRITURA AL COMPLETAR (EEIF SET)
   BCF  PIR2,EEIF   
  
   RETURN

I am writing 10 consecutive adresses in a loop:

CHEE   
   
    DECF BANCO,0                          ; BANCO-1
    MOVWF MULCND
    MOVLW 0X0A
    MOVWF MULPLR
    CALL MPY_S                          ;(BANCO-1)*10
    MOVF L_BYTE,W
    MOVWF DATA_EE_ADDR           ; VALOR INICIAL DE DATA_EE_ADDR
   
    MOVLW 0X44    ; VALOR INICIAL DE FSR
    MOVWF FSR0L
   
ANDERE   
    MOVF INDF0,W
    MOVWF DATA_EE_DATA
    CALL  WRITE
   
    INCF DATA_EE_ADDR,1
    INCF FSR0L,1
    MOVLW 0X4E
    SUBWF FSR0L,0
    BTFSS STATUS,Z
    GOTO ANDERE
    RETURN

The program has the High Interrupt routine for the functioning of the EUSART. Each time its a received message from EUART, there is the interruption and its called the INNIT routine. This feature is running OK!

HIGH_INT  CODE 0x0008
   GOTO INNIT
I am really confused about how the interruptions function in this PIC. I do not know if the problem with the EEPROM write is due to interruptions...or my code...or.....

I will appreciate your kind support in this issue.

回帖(19)

李兆峰

2019-4-23 13:17:49
您的代码看起来足够好,除了一些细节(使用0和1作为目的地,而不是首选W和F)-什么是不正确的工作?* * *可能需要一些银行和/或,访问/存储的说明符…

以上来自于百度翻译


      以下为原文

    Your code looks good enough, apart from some details (using 0 and 1 as destination, instead of preferred W and F) - what is not working exactly?
 
You *may* need some BANKSEL and/or ,ACCESS/BANKED specifier...
举报

王焕树

2019-4-23 13:36:50
没有这样的装置。你是说PIC16F87吗?您的代码没有等待写入完成。您已经跳过了描述中的几个句子,只看到了“EEIF必须用软件清除”。也就是说,如果使用中断来检测写入的完成,中断服务必须做什么。你会在中断服务中这样做,只是等待WR位变低,这是很容易的。

以上来自于百度翻译


      以下为原文

   
There is no such device. Did you mean a PIC16F887 ?
 

Your code is not waiting for the write to finish.
You have skipped a couple of sentences in the description, and just seen the "EEIF must be cleared by software".
That is saying what your interrupt service must do if you use interrupts to detect the completion of the write. You would do that in the interrupt service.
It's much easier to just wait for the WR bit to go low, which you are not doing.
 
 
举报

蔡维林

2019-4-23 13:46:25
您好,非常感谢您的及时答复。Cinzia,我将使用W或F代替1或0。PIC18F4620不需要银行的选择。所有的FSR和SFR都在银行0。我的程序中的第一个指令是CLRF BRS。Qhb,也许如果我在BSF ITCN、GIE指令循环BTFSC EECO1、WR BRA循环继续程序之后编写,您认为可以吗?我应该如何处理PIR2,EEIF位?非常感谢…再次

以上来自于百度翻译


      以下为原文

    Hello,
 
Thank you very much for your prompt answers.

Cinzia,
I will use W or F instead 1 or 0.
The PIC18F4620 do not need the bank selection. All the FSR and SFR are in bank 0. The first instruction in my program is CLRF  BRS.

Qhb,
Maybe if I write after BSF    INTCON,GIE instruction

LOOP              BTFSC    EECON1,WR
                      BRA       LOOP
                      continue program
Do you think is OK?
What should I do with the PIR2,EEIF bit?

Thank you very much...again
举报

蔡维林

2019-4-23 13:57:41
QHB,我按照上面提到的那样做了……在不稳定的行为中没有变化。在字符1, 5, 6、7, 8, 9和10中写的总是很好。字符2, 3和4总是错误的。我对子程序代码做了几次修改,即使我做了一些例程而没有间接寻址。结果和上面提到的一样,这个程序是在EEPROM中编写的,但是由于某种原因,A.M.CARCTELTES总是错误的。急需帮助!!!!!!!眨眼:

以上来自于百度翻译


      以下为原文

    QHB,
 
I did it as I mentioned above.....no changes in the erratic behavor.
The writting is always well done in the characters 1, 5, 6, 7, 8, 9 and 10.
The characters 2, 3 and 4 ALWAYS are wrong.
I made several changes to my subroutines codes, even I made some routines without indirect addressing. The result was the same as mentioned above.
The program is writting in  the EEPROM, but for some reason, the a.m. caracteres are always wrong.

Help needed urgently!!!!!
wink:
举报

更多回帖

发帖
×
20
完善资料,
赚取积分