Sorry about the name cock-up Clyde. How embarrasing.
OK, I've just tried this code:
#include <pic.h>
unsigned int count;
void main( )
{
count = (CCPR1H << 8) + CCPR1L;
}
Compiled through MPLAB which produces the following command line:
C:\HT-PIC\BIN\PICC.EXE -Gmicrochip -O -Zg9 -D24 -16F877 -C -IC:\HT-PIC\INCLUDE -ASMLIST C:\HT-PIC\PROJECTS\MISC\TEST.C
This gives me:
movf 22,w ;volatile
movwf btemp+1
clrf btemp
movf 21,w ;volatile
addwf btemp,w
movwf _count
movf btemp+1,w
btfsc 3,0
incf btemp+1,w
movwf _count+1
I was sure I must be doing something screwy here, so I have re-installed V8.75 just to make sure I had the right version and the results are the same.
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.
Regards
Mike Rigby-Jones
-----Original Message-----
From: Clyde Smith-Stubbs [SMTP:clyde@HTSOFT.COM]
Sent: Wednesday, March 22, 2000 10:55 AM
To: PICLIST@MITVMA.MIT.EDU
Subject: Re: 16-bit arithmetic in C
On Wed, Mar 22, 2000 at 09:51:16AM -0000, Michael Rigby-Jones wrote:
> It certainly would make a neat macro if it worked. However, I've just tried
> it on V7.85, compiling for a 16F877 with maximum optimisation and it got
> it's knickers in a twist:
You didn't show your C code, but here's what I tried:
;x.c: 7: count = (CCPR1H << 8) + CCPR1L;
movf 22,w ;volatile
movwf _count+1
movf 21,w ;volatile
movwf _count
Looks fine to me.
Of course, the other (better) way to do it, which works since CCPR1L and
CCPR1H are adjacent and in the right order, is this
static unsigned int CCPR1 @ 0x15;
Now you can just use it directly.
Regards, Clyde
PS - Mick, I don't think Clive James reads the PIClist.
--
Clyde Smith-Stubbs | HI-TECH Software
Email: clyde@htsoft.com | Phone Fax
WWW: http://www.htsoft.com/ | USA: (408) 490 2885 (408) 490 2885
PGP: finger clyde@htsoft.com | AUS: +61 7 3355 8333 +61 7 3355 8334
---------------------------------------------------------------------------
HI-TECH C: compiling the real world.