This continues from my other thread. Got program memory read and erase working, but can't get it to write in simulation. Using MPLAB SIM. Processor = PIC16F1519 Language=MPASM
PMCON1 is mostly a read/write register that controls read, write, and erase functions on program memory. Most notably, PMCON1,WR is the write bit (bit<1>), which can only be set and not cleared by user. Clearing is by the MCU after writing.
In a watch window, I traced PMCON1 and added comments to the code. That register changes as expected with one exception: Setting WR does not change the value (added asterisk for accent). With WR, PMCON1 should be 0x86 or 0xA6 as appropriate.
1) Does anyone know whether MPLAB SIM properly simulate this code for writing to program memory?
2) Is there a problem with the code?
BTW, This code really does nothing. It is just a sandbox to test writing and reading program memory. The code was directly copied from the Microchip datasheet example, except indirect addressing was removed since only one byte is being tested. Config bits are properly set, I think:
John
EDIT UPDATE #1:
I think I got it to work with MPLAB ICD3. However, the PMCON1 still doesn't change in the watch window when bit<1> is set. That concerns me. Had to add a couple of lines to Example 11-3. Now to test with MPLAB SIM.
UPDATE#2:
Unfortunately, my joy was short lived. I was looking at a register being populated with the data byte. When I do an actual read on the chip and look at program memory, I can see where it was erased and read, but no data is loaded there. So, the problem seems to still be present.
UPDATE#3:
GOT IT TO WORK:
The variable is in program memory 00E0h , and its value 0064h. The biggest secret was probably getting a short nap.
PMCON1 is mostly a read/write register that controls read, write, and erase functions on program memory. Most notably, PMCON1,WR is the write bit (bit<1>), which can only be set and not cleared by user. Clearing is by the MCU after writing.
Code:
Save
BCF INTCON,GIE ; Disable ints so required sequences will execute properly
BANKSEL PMADRH ; Bank 3
movlw 0x00 ;0x3F
MOVWF PMADRH ;
movlw 0xE0 ;0x80
MOVWF PMADRL ;
BCF PMCON1,CFGS ; Not configuration space PMCON1=80 (after step)
BSF PMCON1,WREN ; Enable writes PMCON1=84 (after step)
BSF PMCON1,LWLO ; Only Load Write Latches PMCON1=A4 (after step)
LATCH_WRITE
movf TzL,w
MOVWF PMDATL ;
movf TzH,w
MOVWF PMDATH ;
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 PMCON1=A4(after step, no change)
NOP ; NOP instructions are forced as processor
; loads program memory write latches
NOP ;
PM_WRITE
BCF PMCON1,LWLO ; No more loading latches - start Flash program
; memory write PCON1=84 (after step)
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 PMCON1=84 (after step, no change)
NOP ; NOP instructions are forced as processor writes
; all the program memory write latches simultaneously
NOP ; to program memory.
; After NOPs, the processor
; stalls until the self-write process in complete
; after write processor continues with 3rd instruction
BCF PMCON1,WREN ; Disable writes
; BSF INTCON,GIE ; Enable interrupts
Return
1) Does anyone know whether MPLAB SIM properly simulate this code for writing to program memory?
2) Is there a problem with the code?
BTW, This code really does nothing. It is just a sandbox to test writing and reading program memory. The code was directly copied from the Microchip datasheet example, except indirect addressing was removed since only one byte is being tested. Config bits are properly set, I think:
John
EDIT UPDATE #1:
I think I got it to work with MPLAB ICD3. However, the PMCON1 still doesn't change in the watch window when bit<1> is set. That concerns me. Had to add a couple of lines to Example 11-3. Now to test with MPLAB SIM.
UPDATE#2:
Unfortunately, my joy was short lived. I was looking at a register being populated with the data byte. When I do an actual read on the chip and look at program memory, I can see where it was erased and read, but no data is loaded there. So, the problem seems to still be present.
UPDATE#3:
GOT IT TO WORK:
The variable is in program memory 00E0h , and its value 0064h. The biggest secret was probably getting a short nap.
Last edited: