> #include <pic.h>
> unsigned int count;
> void main( )
>
> count = (CCPR1H << 8) + CCPR1L;
> }
I was going to reply to Michael's comment that his compiler barfed over this
statement - when I did it worked fine. Had me worried until I read the other
posts.
Well, it's got me well and truly worried. I just can not get this to work no matter what I do. Are you using the compiler through MPLAB or are you using the HPDPIC IDE? I have to admitt, I have been seeing some odd things recently...
However...
> static unsigned int CCPR1 @ 0x15;
This looks even cooler. Got to love it when folks want to try to optimize a
seemingly innocuous function.
>Your idea of using it directly is superb, I just wouldn't have thought of
that. However it obviously
> only works in the minority of cases, a more general solution is needed for
most jobs
Michael - are you saying that either CCPR1 is not adjacent in all pics or
it's not at 0x15?
-DO
No, I'm saying that using this method is great for the case of grabbing a 16 bit result from a peripheral that happens to have the hi-lo bytes adjacent and in the right sequence. There are other times when you may want to construct an 16 bit integer from two bytes where this just is not applicable, for instance building a 16 bit value from the two 8 bit SPI transfers of an ADC.
AFAIK CCPR1 will have it's registers in the same place on any particular PIC family.