Today 11:23
Forum: Proton Plus Compiler v3
Starter: Mellbreak
Views: 1053
Replies: 38
Yesterday 22:54
Forum: Wish List / Product Feedback
Starter: RGV250
Views: 0
Replies: 6
+ Reply to Thread
Results 1 to 10 of 10

Thread: CWrite to a Dword Address23 days old

  1. #1
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default CWrite to a Dword Address

    Trying to CWrite to a Dword Address but it gets truncated.
    0x16800 (dec 92160) and it writes to Address 0x6800 (dec 26624)
    The variable for the address is a Dword so CWrite must be truncating, also Cread is doing the same.

    How can I write to the Flash memory above WORD Address?

    David

  2. #2
    Developer Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,245
    Thumbs Up
    Received: 230
    Given: 86
    Total Downloaded
    1.50 GB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    CWrite will write above a 16-bit address if a large enough constant or Dword is used for the address.

    For example, the command:

    CWrite $123456,[1,2,3]

    Produces the asm code:
    Code:
        movlw 18
        movwf  TBLPTRLHH ,0
        movlw 52
        movwf  TBLPTRLH ,0
        movlw 86
        movwf  TBLPTRL ,0
        movlw 1
        rcall __CWRITE_
        movlw 2
        rcall __CWRITE_
        movlw 3
        rcall __CWRITE_
        clrf TBLPTRU,0
    Which is correctly loading the address into TBLPTRL\H\U (U is named HH for compiler compatability with constant loading)

    The command:

    CWrite dAddress,[1,2,3]

    Produces the asm:
    Code:
        movff dAddress,TBLPTRL
        movff dAddressH,TBLPTRH
        movff dAddressHH,TBLPTRU
        movlw 1
        rcall __CWRITE_
        movlw 2
        rcall __CWRITE_
        movlw 3
        rcall __CWRITE_
        clrf TBLPTRU,0
    Again, correctly loading TBLPTRL\H\U

    What version of the compiler are you using, and what device etc....
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  3. #3
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    Hi Les, thanks for looking at this.
    Using current version Pic 18F86J55

    Variables:-

    Dim TRead1 As Byte
    Dim x As Byte
    Dim Word_Var As Dword
    Dim Byte_Var As Byte
    Dim Index As Byte
    Dim bytes_in[192] As Byte
    Dim KeyLayoutAdd As Word 'address USED to store updates to layout
    Dim Current_K_Layout As Word 'address of current layout

    Symbol KeyLayout_1_table_Start = 0x16800 'In order to write to flash the Cwrite block needs to be on a 64 byte boundry...
    Symbol KeyLayout_2_table_Start = 0x16C00
    Symbol KeyLayout_3_table_Start = 0x17000
    Symbol KeyLayout_4_table_Start = 0x17400
    Symbol KeyLayout_5_table_Start = 0x17800

    Symbol FlashEraseSeg = 1024 'Cerase needs to be done in 1024 byte increments..
    Symbol FlashWriteBlock = 64 ; The memory size Flash write needs to do in one block

    Symbol EndOfCodeSpaceT1 = 0X16BFF 'End of Cwrite table 1
    Symbol EndOfCodeSpaceT2 = 0X16FFF 'End of Cwrite table 2
    Symbol EndOfCodeSpaceT3 = 0X173FF 'End of Cwrite table 3
    Symbol EndOfCodeSpaceT4 = 0X177FF 'End of Cwrite table 4
    Symbol EndOfCodeSpaceT5 = 0X17BFF 'End of Cwrite table 5
    Code:-

    Code:
    '************* Erase memory ***********************************************************************
     EraseProgramData:      'clear the flash  1024 bytes at a time
           Word_Var = KeyLayout_1_table_Start       
            SerOut PORTJ.5, 84, [" Erase wordvar = ", Dec Word_Var, 13]
            Repeat
                 CErase Word_Var
                 Word_Var = Word_Var + FlashEraseSeg    ' jump to next 1024 byte segment of table
            Until Word_Var >= EndOfCodeSpaceT1           ' continue erasing until end of table T1
        SerOut PORTJ.5, 84, ["Erase", 13, 10]
     Return
     '*************************************************************************************************
    '************* Write to Memory ******************************************************************
     WriteToFlash:          'write to flash   64 bytes at a time 
                
           Word_Var = KeyLayout_1_table_Start       ' point to start of table 1 memory were we want to load data 
             SerOut PORTJ.5, 84, [" Write wordvar = ", Dec Word_Var, 13]
                  For Index = 0 To 191                      ' 3 x 64 bytes
                       bytes_in[Index] = Index
                       CWrite Word_Var + Index, [bytes_in[Index]]     ' write 192 bytes to flash
                  Next Index
          SerOut PORTJ.5, 84, ["wordvar = ", Dec Word_Var, " K start = ", Dec KeyLayout_1_table_Start, " index = ", Dec Index, " bytesin = ", Dec bytes_in[4], 13]
          SerOut PORTJ.5, 84, ["CWrite", 13, 10]
     Return
    '************************************************************************************************ 
     '*********** Check memory write **************************************************************
     CheckData:
                Word_Var = KeyLayout_1_table_Start
                     For Index = 0 To 191
                         Byte_Var = CRead Word_Var + Index 
                         If Byte_Var <> bytes_in[Index] Then
                              SerOut PORTJ.5, 84, ["CWrite Failed", 13, 10]
                              Break
                         End If 
                      Next Index        
            SerOut PORTJ.5, 84, ["CWrite OK", 13, 10]
                 'lights to indicate ok
     Return
     '*********************************************************************************************
    This shows the Pic memory after above code:-

    67d0- ffff ffff ffff ffff ffff ffff ffff ffff
    67e0- ffff ffff ffff ffff ffff ffff ffff ffff
    67f0- ffff ffff ffff ffff ffff ffff ffff ffff
    6800- 0100 0302 0504 0706 0908 0b0a 0d0c 0f0e
    6810- 1110 1312 1514 1716 1918 1b1a 1d1c 1f1e
    6820- 2120 2322 2524 2726 2928 2b2a 2d2c 2f2e
    6830- 3130 3332 3534 3736 3938 3b3a 3d3c 3f3e
    6840- 4140 4342 4544 4746 4948 4b4a 4d4c 4f4e
    6850- 5150 5352 5554 5756 5958 5b5a 5d5c 5f5e
    6860- 6160 6362 6564 6766 6968 6b6a 6d6c 6f6e
    6870- 7170 7372 7574 7776 7978 7b7a 7d7c 7f7e
    6880- 8180 8382 8584 8786 8988 8b8a 8d8c 8f8e
    6890- 9190 9392 9594 9796 9998 9b9a 9d9c 9f9e
    68a0- a1a0 a3a2 a5a4 a7a6 a9a8 abaa adac afae
    68b0- b1b0 b3b2 b5b4 b7b6 b9b8 bbba bdbc bfbe
    68c0- ffff ffff ffff ffff ffff ffff ffff ffff
    68d0- ffff ffff ffff ffff ffff ffff ffff ffff
    68e0- ffff ffff ffff ffff ffff ffff ffff ffff
    68f0- ffff ffff ffff ffff ffff ffff ffff ffff
    serial output from this code confirms Word_Var is

    Erase wordvar = 92160
    Erase
    Write wordvar = 92160
    wordvar = 92160 K start = 92160 index = 192 bytesin = 4
    CWrite
    CWrite OK
    Cannot find in ASM file "dAddress,TBLPTRL" ie: Word_Var,TBLPTRL etc. Tried uploading ASM file, will not let me.

    One thing in ASM file the symbol does show as "#define KeyLayout_1_table_Start 26624" which is the lower address, should be 92160.

    if I set Word_Var = 0x16800, serial output shows Word_Var = 1474560 and does not write anything to memory, do not know what is happening here.

    Thanks David

  4. #4
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    Part of ASM file attached

    ASM-part.txt

  5. #5
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    265
    Thumbs Up
    Received: 32
    Given: 0
    Total Downloaded
    76.31 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    Code:
    EraseProgramData
    F1_000668 equ $ ; IN [KEYMIDI-86J55-1.BAS] WORD_VAR = $168000
    I think you've got one too many zeros there.

  6. #6
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    Don't know where that came from, because in the actual asm file it does not show a value only the symbol. Think is was when I was trying to put values in direct. see attached part file:-

    asmm.txt

    Shows as "EraseProgramData
    F1_000677 equ $ ; IN [KEYMIDI-86J55-1.BAS] WORD_VAR = KEYLAYOUT_1_TABLE_START"

    David

  7. #7
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    How do I upload the full asm file? it is 186K

    David

    OK asm file uploaded

    KeyMidi-86J55-1.zip

    David
    Last edited by Dave-S; 20th November 2017 at 10:37.

  8. #8
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    Hi Les,

    Have created just a small program with just Erase and Cwrite which still writes to 0x6800 and not 0x16800 as programmed. Have removed all other code including USB.

    Code:
     Device = 18F86J55
     Config_Start
      WDTEN = Off	;WDT enabled
      PLLDIV = 5	;Divide by 5 (20 MHz oscillator input)
      STVREN = On	;Reset on stack overflow/underflow enabled
      XINST = OFF	;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
      Debug = OFF	;Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
      CPUDIV = OSC1	;No CPU system clock divide
      Cp0 = OFF	;Program memory is not code-protected
      FOSC = HSPLL	;HS oscillator, PLL enabled, HSPLL used by USB
      FCMEN = On	;Fail-Safe Clock Monitor enabled
      IESO = Off	;Two-Speed Start-up enabled
      WDTPS = 32768	;1:32768
      EASHFT = On	;Address shifting enabled, address on external bus is offset to start at 000000h
      MODE = MM	;Microcontroller mode - External bus disabled
      BW = 16	;16-bit external bus mode
      Wait = OFF	;Wait states on the external bus are disabled
      CCP2MX = DEFAULT	;ECCP2/P2A is multiplexed with RC1
      ECCPMX = DEFAULT	;ECCP1 outputs (P1B/P1C) are multiplexed with RE6 and RE5; ECCP3 outputs 
    
    (P3B/P3C) are multiplexed with RE4 and RE3
      PMPMX = DEFAULT	;PMP pins placed on EMB
      MSSPMSK = MSK7	;7-Bit Address Masking mode enable
    Config_End
    
       
        Declare Xtal = 48
        
        Declare Optimiser_Level = 3             ' Maximum optimisation
        Declare Dead_Code_Remove = On           ' Squeeze the code further
        Declare Warnings = Off
        Declare All_Digital = True
        Declare Onboard_USB = 0
        
        OSCTUNE.6 = 1
        DelayMS 550
        PORTG.6 = 1        'PORTE weak pull ups ON
        ANCON0 = %10011111
        ANCON1 = %11111100
      
     Dim Word_Var As Dword
     Dim Index As Byte
     Dim bytes_in[192] As Byte
     Word_Var = 0x16800
    Symbol FlashEraseSeg = 1024            'Cerase needs to be done in 1024 byte increments..
    
    Symbol EndOfCodeSpaceT1 = 0X16BFF       'End of Cwrite table 1
    
    DelayMS 200
    
    Main:
    
    If PORTJ.4 = 0 Then
          GoSub EraseProgramData
          GoSub WriteToFlash
    
    End If
    
    
    GoTo Main
    '************* Erase memory ***********************************************************************
     EraseProgramData:      'clear the flash  1024 bytes at a time
        Word_Var = 0x16800       
            Repeat
                 CErase Word_Var 
                 Word_Var = Word_Var + FlashEraseSeg    ' jump to next 1024 byte segment of table
            Until Word_Var >= EndOfCodeSpaceT1           ' continue erasing until end of table T1
    Return
     '*************************************************************************************************
    '************* Write to Memory ******************************************************************
     WriteToFlash:          'write to flash   64 bytes at a time 
                
           Word_Var = 0x16800     ' point to start of table 1 memory were we want to load data 
                  For Index = 0 To 191                      ' 3 x 64 bytes
                       bytes_in[Index] = Index
                       CWrite Word_Var + Index, [bytes_in[Index]]     ' write 192 bytes to flash
                  Next Index
     Return
    '************************************************************************************************
    Asm File.
    Test_CWrit_Dword.zip

    This shows "#define EndOfCodeSpaceT1 27647" which is not correct should be 93183.

    It shows under Erase with the correct variables as you showed.

    EraseProgramData
    F1_000071 equ $ ; IN [TEST_CWRIT_DWORD.BAS] WORD_VAR = 0X16800
    clrf Word_VarHHH,0
    movlw 1
    movwf Word_VarHH,0
    movlw 104
    movwf Word_VarH,0
    clrf Word_Var,0
    F1_000072 equ $ ; IN [TEST_CWRIT_DWORD.BAS] REPEAT
    _LBL__4
    F1_000073 equ $ ; IN [TEST_CWRIT_DWORD.BAS] CERASE WORD_VAR
    movff Word_Var,TBLPTRL
    movff Word_VarH,TBLPTRH
    movff Word_VarHH,TBLPTRU
    rcall __CERASE_L_
    Under CWrite though it shows this, but not the variables as you show.

    WriteToFlash
    F1_000081 equ $ ; IN [TEST_CWRIT_DWORD.BAS] WORD_VAR = 0X16800
    clrf Word_VarHHH,0
    movlw 1
    movwf Word_VarHH,0
    movlw 104
    movwf Word_VarH,0
    clrf Word_Var,0
    Is this something to do with Bank switching on this Device?
    Look forward to some assistance in solving this.

    Thanks David

  9. #9
    Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    265
    Thumbs Up
    Received: 32
    Given: 0
    Total Downloaded
    76.31 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    This shows "#define EndOfCodeSpaceT1 27647" which is not correct should be 93183
    It splits the symbol definition into 4 individual defines:
    Code:
    #define EndOfCodeSpaceT1 27647        '0x6bff (only uses ff)
    #define EndOfCodeSpaceT1H 107         '0x6b
    #define EndOfCodeSpaceT1HH 1          '0x01
    #define EndOfCodeSpaceT1HHH 0         '0x00
    When it goes to use it, is uses it correctly as 0x016bff

    The statement it doesn't like is in WriteToFlash...
    Code:
       CWrite Word_Var + Index, [bytes_in[Index]]     ' write 192 bytes to flash
    The addition confuses things and it only uses TBLPTRL and TBLPTRH.

    If you remove the addition in the CWrite statement it loads all three TBLPTRL/H/U. Change the above to:
    Code:
       CWrite Word_Var, [bytes_in[Index]]     ' write 192 bytes to flash
       Word_Var = Word_Var + 1

  10. #10
    Member Dave-S's Avatar
    Join Date
    Sep 2004
    Posts
    260
    Thumbs Up
    Received: 5
    Given: 0
    Total Downloaded
    268.81 MB

    0 Not allowed!

    Default Re: CWrite to a Dword Address

    I have solved this, the CWrite and Cread need to be a single instruction for all the 64 bytes of data. It will not work within a loop, or any additions to the address. It did work ok with the 18F4550 but transferring it to the 18F86J55 it did not work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Using the Cwrite Command.
    By Mellbreak in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 23rd October 2012, 14:31
  2. Cwrite! How To :(
    By SELCUK in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 18th June 2007, 11:06
  3. Cwrite
    By rockybooth in forum Proton Plus Compiler v3
    Replies: 10
    Last Post: 27th July 2006, 14:12

Members who have read this thread since 7th December 2017, 20:26 : 0

Actions :  (Set Date)  (Clear Date)

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

Tags for this Thread

Posting Permissions

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