What's this ?

Hi,

i have a little prob to understand this :

if( pir1 & (1

Reply to
chris
Loading thread data ...

It executes 'Code' when bit number 'SSPIF' is set in 'pir1'

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

In space, no one can hear you fart.
Reply to
Stef

so that means that it is the same as :

if (SSPIF == 1) { Code }

but I don't really understand why we must shift left ??

Thanks

Chris

Reply to
chris

It executes 'Code' when bit number 'SSPIF' is set in 'pir1'"

"so that means that it is the same as :

if (SSPIF == 1) { Code } "

No, unless you meant SSPIF == 1 in an intuitive and rather loose, imprecise manner.

"but I don't really understand why we must shift left ??"

Please understand what left shifting entails: it multiplies by two. So SSPIF = 0; if(pir1 & (1

Reply to
Colin Paul Gloster

Guess that pir1 is defined somewhere as the address of a port (port input register 1?), SSPIF is defined as a bit number (0 to 7 for bit0... bit7) for some input condition. It masks a 1 with the port in the appropriate position for the decision.

The original programmer would have been kinder if he had defined SSPIF as ((pir1 &(1

Reply to
Paul Burke

No. If you dig through the code you'll probably find an include file somewhere that says

#define SSPIF 3

SSPIF never changes value. Because of the way bit-access instructions work in the PIC, it's handier to talk about bits in terms of their positions in the byte. But if the pir1 byte had only its SSPIF bit set on, the others off, its value would be 0x08. That's the mask you need to use to separate the SSPIFth bit from the others. 1

Reply to
Mel Wilson

It depends on how SSPIF is defined. in Hitech C You could do either :

#define SSPIF 3 if (PIR1 & ((1

Reply to
Mike Harrison

"chris" schreef in bericht news: snipped-for-privacy@g43g2000cwa.googlegroups.com...

There is no law that tells you to shift left. If you want you can multiply by 2. Or shift right, if it pleases you. Or don't shift at all. The microcontroller does not care.

But sometimes there is a desire to produce code that has a satisfying effect. If the desire is strong, it helps to find out what SSPIF actually stands for. It also helps if you have a rough idea about the desired effect of your code.

--
Thanks, Frank.
(remove 'q' and '.invalid' when replying by email)
Reply to
Frank Bemelman

No. RTFM. SSPIF is a bit number, not a value.

pete

--
pete@fenelon.com [Support no2id.net: working to destroy Blair's ID card fraud]
Reply to
Pete Fenelon

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.