How to use symbolic names for bits within registers?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Location
    Edmonton AB Canada
    Posts
    5

    Default How to use symbolic names for bits within registers?

    Good day to all.

    I'm continuing my journey as a PBP newbie and have another reasonably simple question:

    How can I use bit names within PBP statements?

    One recurring problem I have when porting code between different PICs is the location of the a/d converter go/done bit. Its easy in assembler: I simply define that bit in my header files and the proper bit is used even when I change processors. Eg: #define _GO_DONE ADCON0,1

    But it doesn't seem to work in PBP.

    This works:

    adcon0.1 = 1

    This doesn't work:

    adcon0.GO_DONE = 1

    even though GO_DONE has been equated to 1 in the appropriate header file (M16F88X.inc)

    I'm sure its simple - could someone point me in the correct direction?

    Many thanks!

    dwayne

    PS - the a/d go/done bit is the most common bit I need to change - it moves between .1 or .2, depending upon which PIC I'm currently targeting.

    dwayne

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi again Dwayne,

    When you compile a PBP program, it first goes through PBPW or PBPL.exe which generates an ASM file.
    The ASM file is then passed on to either PM.exe or MPASM.exe to be assembled into a .hex file.

    The bit names you are referring to are only defined at the ASM level, but since PBP compiles first ... it has no idea what those bits are. And due to the way PBP optimizes code space, it needs to know where the bits are when it compiles.

    So you actually have to look up the bits in the datasheet.

    Then you just ...
    Code:
    GO_DONE   VAR ADCON0.1
    
    GO_DONE = 1
    WHILE GO_DONE : WEND
    ; get result
    Unfortunately, there's no way to change bit locations according to the chip being compiled for within PBP.

    Of course, you could always read the ADC at the ASM level, in which case you could use the predefined constants.
    Or use ADCIN and not worry about it.

    hth,
    Last edited by Darrel Taylor; - 10th December 2009 at 06:16.
    DT

  3. #3
    Join Date
    Dec 2009
    Location
    Edmonton AB Canada
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Sorry for the late reply - just back from a short (too short!) vacation.

    Actually, Darrel, what you posted helps a lot. Again, I'm going through PBP code written by others and trying to make it both more easily maintainable as well as easier to read. The suggestion you made does exactly that - gives me a single place where I can make the changes needed when switching between different PICs.

    I don't think that I can use ADCIN - I *think* that program execution halts while waiting for the ADC result and I can't tolerate the delay.

    I'm avoiding adding my own ASM stuff for now, at least until I get a better sense of the landscape.

    Many thanks!

    dwayne
    Last edited by DwayneR; - 17th December 2009 at 04:23.

Similar Threads

  1. LCD's with Shift Registers, and LCDOUT
    By Darrel Taylor in forum PBP Extensions
    Replies: 11
    Last Post: - 3rd April 2015, 14:34
  2. Replies: 1
    Last Post: - 2nd November 2006, 23:24
  3. Use the PIC 16f877 or 877A instead of shift registers.
    By tsanders in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th October 2006, 17:23
  4. Set the UCFG register or registers in general
    By eDub in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd July 2006, 19:46
  5. Problem with communications & registers and LCD
    By mpavlica in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th December 2004, 09:38

Members who have read this thread : 1

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