Menu

EPRead is broken i update.zip from 15/10-07

bell
2007-11-19
2013-05-30
  • bell

    bell - 2007-11-19

    EPRead seems broken i the latest update.zip (15/10-07)

    Example:

    This:
    #chip 12F629,4

    EPRead(3,Temp)

    Compiles to:
        movlw    3
        banksel    EEADDRESS
        movwf    EEADDRESS
        banksel    TEMP
        movf    TEMP,W
        banksel    EEDATAVALUE
        movwf    EEDATAVALUE
        call    EPREAD
        movf    EEDATAVALUE,W
        banksel    TEMP
        movwf    TEMP

    and EPREAD looks like this:

    EPREAD
        banksel    EECON1
        bsf    EECON1,RD
        nop
        banksel    STATUS
        return

    Lets replace the EPREAD call with the contents of the EPREAD subroutine to make it easier to follow:
        movlw    3
        banksel    EEADDRESS
        movwf    EEADDRESS
        banksel    TEMP
        movf    TEMP,W
        banksel    EEDATAVALUE
        movwf    EEDATAVALUE
        banksel    EECON1
        bsf    EECON1,RD
        nop
        banksel    STATUS
        movf    EEDATAVALUE,W
        banksel    TEMP
        movwf    TEMP

    Notice that "banksel STATUS" before "movf EEDATAVALUE,W"? I almost didn't catch this one because STATUS exists in both bank 0 and bank 1 of the 12F629 so I had to let WinPic800 disassemble the hexfile for me and "banksel EEDATAVALUE" becomes "bsf 0x03,5", "banksel STATUS" becomes "bcf 0x03,5". Accordning to the datasheet the EEDATA does not exists in bank which is why this read will fail.

    Apart fromt that bug I cannot see the point in loading EEDATA with the previous content of BTEMP before reading and I've also noticed that if you call EPRead using a variable as the first parameter it will also politely read EEADR and write it back to the variable which also seems like a waste of clockcycles and code space.

    I suggest that EPWrite(3,Temp) in the example could be done like this (for 12F629 and similar chips):

        movlw    3
        call    EPREAD
        banksel    TEMP
        movwf    TEMP

    and EPREAD would look like this:

    EPREAD
        banksel    EEADDRESS
        movwf    EEADDRESS
        bsf    EECON1,RD
        nop
        movf    EEDATAVALUE,W
        return

    According to the datasheet you could also remove the "nop".

     
    • Hugh Considine

      Hugh Considine - 2007-12-04

      I think I've managed to deal with a few of the problems you've found.

      First, bank selection. GCBASIC wasn't inserting all of the banksel commands it should have been. Also, its built-in assembler was generating code for RP1 which doesn't exist on the 12F629.

      I've also made some modifications to the way that subroutine parameters are handled. This has allowed for parameters which are input only or output only. For example, EPRead is now defined as "Sub EPRead(In EEADDRESS, Out EEDATAVALUE)". This means that GCBASIC will not copy a value out of the address after calling, or into the data value before calling. Using W to pass the parameter will take a bit more work, but I'll certainly consider it where possible.

      The update is available in two files - http://gcbasic.sourceforge.net/newfiles/update.zip or http://gcbasic.sourceforge.net/newfiles/update-nochipdata.zip . The latter does not include the newest (September or October) chip data files, and so will save a little bandwidth it you've already got these files.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.