Bit grouping


Closed Thread
Results 1 to 4 of 4

Thread: Bit grouping

  1. #1
    Join Date
    May 2004
    Posts
    81

    Default Bit grouping

    Sorry if this has already been covered some where but I cant find it. Im trying to write an include file for my PIC16F818/819 that covers the ADC. In my include file I am creating aliases to the bits of the ADCON0 and ADCON1 registers.

    For instance going by data sheet, the name of bit 7 of ADCON1 is "ADFM" so I use this to make an alias:

    ADFM VAR ADCON1.7

    So far so good, but... in ADCON0 we see that bits 7 and 6 are used together. It holds the osc info and bit names are "ADCS1" for bit 7 and "ADCS2" for bit 6. Further examination shows several 2 bit entrys to set the osc:

    00 = Fosc/2
    01 = Fosc/8
    10 = Fosc/32
    11 = Frc

    So here is the question: How does one create a TWO bit variable, I know we can do this:

    X Var something.1 ; = somethings bit 1
    X Var something ; = the entire content of somthing

    But how do you assignn a variable multiple bits... for instance if i want flea to be bits 2 3 and 4 of Cat, how do I do this?

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Check this thread

    Quote Originally Posted by bearpawz View Post
    But how do you assignn a variable multiple bits... for instance if i want flea to be bits 2 3 and 4 of Cat, how do I do this?
    http://www.picbasic.co.uk/forum/showthread.php?t=544

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    bearpawz,

    I think you need to rethink your approach a "bit":

    All the names you want to use like ADFM, ADCS1, ADCS2, etc., are already predefined as constants in the required .inc file. I am not sure of the implications of renaming them. Others might know.

    ADCON0.6 datasheet name is ADCS0 ' (not ADCS2)
    ADCON0.7 datasheet name is ADCS1
    ADCON1.6 datasheet name is ADCS2

    You actually need to control all three together (not just two bits) to control the TAD time, remembering that two are in ADCON0 and the other is in ADCON1

    I know of no PBP shorter way to assign bits than the method you show at the bottom of your post. I think you could “use” a full 8 bit variable to hold the three separate bit values but would still have to distribute them to two other variables (ADCON0 and ADCON1).

    Something tells me you could set this up to be automated in a manner similar to that shown here

    http://www.picbasic.co.uk/forum/showthread.php?t=3891

    using Darrel's excellent trick/secret but some ASM would be required. I have not fully explored as of yet.

    Lastly, Joe pointed you to an excellent link on dealing and tracking bits using arrays - you should look here too.

    Let us know ...
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Default

    Ive already looked through that thread but thanks. And Im too tired now to even comprehend any assmebly... its almost 1AM and all these 1's and 0's are giving me a head ach.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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