WRITECODE - How it works


Results 1 to 5 of 5

Threaded View

  1. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Version 3.0.8 released.

    As far as I understand how it work, it won't save nothing to FLASH until page you write to last byte in table. So random write to code using WRITECODE might not be good idea.

    ASM for WRITECODE Adr, FlashByte1 'Adr VAR LONG
    Code:
                   Line           Address        Opcode         Label          DisAssy    
                   63459          1EFC4          C02E           Z0007E         MOVFF Adr, TBLPTR
                   63460          1EFC6          FFF6                          NOP            
                   63461          1EFC8          C02F                          MOVFF 0x2F, TBLPTRH
                   63462          1EFCA          FFF7                          NOP            
                   63463          1EFCC          C030                          MOVFF 0x30, TBLPTRU
                   63464          1EFCE          FFF8                          NOP            
                   63465          1EFD0          502A                          MOVF _FlashByte1, W, ACCESS
                   63466          1EFD2          DEA9                          RCALL 0xED26
    First address is loaded to pointer registers(4 bytes), then your byte is loaded to work registers, and then WRITECODE is called with RCALL.
    Here is code for WRITECODE macro for 128 byte page
    Code:
                   Line           Address        Opcode         Label          DisAssy    
                   63124          1ED26          6EF5           WRITECODE      MOVWF TABLAT, ACCESS
                   63125          1ED28          000C                          TBLWT*         
                   63126          1ED2A          28F6                          INCF TBLPTR, W, ACCESS
                   63127          1ED2C          0B7F                          ANDLW 0x7F     
                   63128          1ED2E          E109                          BNZ 0xED42     
                   63129          1ED30          0E84                          MOVLW 0x84     
                   63130          1ED32          6E7F                          MOVWF EECON1, ACCESS
                   63131          1ED34          0E55                          MOVLW 0x55     
                   63132          1ED36          6E7E                          MOVWF EECON2, ACCESS
                   63133          1ED38          0EAA                          MOVLW 0xAA     
                   63134          1ED3A          6E7E                          MOVWF EECON2, ACCESS
                   63135          1ED3C          827F                          BSF EECON1, 1, ACCESS
                   63136          1ED3E          0000                          NOP            
                   63137          1ED40          947F                          BCF EECON1, 2, ACCESS
                   63138          1ED42          EFE8           writecodedone  GOTO 0x1EDD0   
                   63139          1ED44          F0F6                          NOP   
    ....
                   63209          1EDD0          0100           DUNN           MOVLB 0x0      
                   63210          1EDD2          0000           DUNN5          NOP            
                   63211          1EDD4          0012                          RETURN 0
    Then at WRITECODE byte from w is moved to holding register, and then table write is executed(TBLWT*).
    This will check if your last adr is 127
    Code:
                   63126          1ED2A          28F6                          INCF TBLPTR, W, ACCESS
                   63127          1ED2C          0B7F                          ANDLW 0x7F     
                   63128          1ED2E          E109                          BNZ 0xED42
    If not it will branch to writecodedone, then goto to DUNN and finally RETURN to your code.
    If last Adress was 127 then it will execute FLASH write(Same as EEPROM write, just bit EEPGD of EECON1 is set ) and go back to your code.
    If you put address 127 and load only one byte page write will be executed, but what is in table you can't know, so table will be write with random data except byte at 127 location.
    I hope that this will help you to understand how WRITECODE is done.
    This might be separate topic, as it doesn't have much with new version.
    Last edited by pedja089; - 17th June 2015 at 12:42.

Similar Threads

  1. Some questions about WRITECODE
    By The Master in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 25th April 2008, 14:59
  2. 16f88 writecode (2.47)
    By nirvdrum in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th January 2007, 03:48
  3. WRITECODE or not????
    By Jumper in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th August 2006, 08:01
  4. Can anyone help me to use Writecode for pic18f458 ?
    By dip1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th June 2006, 22:29
  5. I need help with writecode
    By Marten in forum General
    Replies: 2
    Last Post: - 2nd March 2005, 22:15

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts