Searching \ for '8 + 8bits variable' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=8bits+variable
Search entire site for: '8 + 8bits variable'.

Truncated match.
'8 + 8bits variable'
1999\11\09@100423 by

What's the c syntax to perform an 16-bit sum like:
CCPR1 = CCPR1 + TIMER1;
Note that TIMER1 wasn't defined by the 1687x.inc. Instead it was made as
TIMER1H and TIME1L (each one 8 bits type). The same is true to CCPR1.
Summarizing: How can I define or use  a new 16 bit variable called
TIMER1 that is formed by TIMERH and TIMERL (MSB and LSB)?
(this code is for 16F877)
See you guys,

Beto.

To make TIMER1 you could use:
unsigned long (uns16, etc) TIMER1;
TIMER1 = TIME1L + TIME1H * 256;

Regards,

Brusque

{Original Message removed}
part 0 5002 bytes
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">You could use a union as follows:</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">union intchar</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">struct{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">unsigned char lo;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">unsigned char hi;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">}byte;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#0000FF" SIZE=2 FACE="Arial">unsigned int total;</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">}</FONT>
</P>
<BR>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">union intchar timer1;</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">union intchar myvar;</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">timer1.lo = TIMER1L;</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">timer.hi = TIMER1H;</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">myvar.lo = CCPR1L;</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">myvar.hi = CCPR1H;</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">myvar.total += timer1.total;</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">CCPR1L = myvar.lo</FONT>
<BR><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">CCPR1H = myvar.hi</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Probably not very efficient though...</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Regards</FONT>
</P>

<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Mike Rigby-Jones</FONT>
</P>
<BR>
<UL>
<P><FONT SIZE=1 FACE="Arial">{Original Message removed}
The (more or less) correct syntax would be something like:

Timer1 = OFF;
Timer1 = ON;

First of all you must switch off timer 1 so you have no byte-rollover
within the timer while you read.  This period of time should be made
as short as possible, so just copy the timer to a shadow register.
Add it all up in the end.

Timer1 = OFF;
CCPR1 += TMR1L + TMR1H*256;
Timer1 = ON;

...the timer will be switched off longer because then you have an

If you choose not to switch timer 1 off, you _will_ get occational
errors with this method.

If you can't switch timer 1 off, you have to test the values you read
from the timer to make sure you had no rollover.  Something like this:

do {
L = TMR1L;
H = TMR1H;
} while (TMR1L < L);   // if this is true, lo-byte rolled over,
// and the concatenated value will be wrong
// if it rolled over before TMR1H were copied.

With all this in mind, it's not just to make timer 1 a 16bit variable.
The code looks better with it, but works better without it.

-DS

Tuesday, November 09, 1999, 5:00:23 PM, you wrote:

EB> To make TIMER1 you could use:
EB> unsigned long (uns16, etc) TIMER1;
EB> TIMER1 = TIME1L + TIME1H * 256;

EB> Regards,

EB> Brusque

EB> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...