PDA

View Full Version : Bit grouping



bearpawz
- 27th December 2006, 05:18
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?

Archangel
- 27th December 2006, 06:01
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

paul borgmeier
- 27th December 2006, 06:11
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 ...

bearpawz
- 27th December 2006, 06:48
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.