CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

INT_RB problem - pic18f2550
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Pichuqy_1



Joined: 03 Aug 2010
Posts: 38

View user's profile Send private message MSN Messenger

PostPosted: Tue Feb 26, 2019 8:46 pm     Reply with quote

PCM programmer,

Could you explain to me, please, why the code #elif HIGHTOLOW, is never executed?
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 26, 2019 9:20 pm     Reply with quote

I'll try to explain...

That #if...else... is a 'pre processor' directive

..from the manual
The pre-processor evaluates the constant expression and if it is non-zero will process the lines up to the optional #ELSE or the #ENDIF.

So what happens is the compiler, on the 1st pass, determines which of the if 'sections' it will then 'process' or compile during the 2nd pass which then gets put INTO your program.

This is not the same 'If then else' that you put INTO your program that does 'this' or 'that' based upon variables when your program runs.

hope this helps
Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 26, 2019 10:09 pm     Reply with quote

Pichuqy_1 wrote:

What I interpreted with this code is that, for the falling edge, the #if
LOWTOHIGH is executed. And for rising edge the #elif HIGHTOLOW is
executed. Am I wrong?

You are wrong.

Pichuqy_1 wrote:

But in this case the segment #if LOWTOHIGH is executed twice, and I can not
understand why.


Use Google to read about the difference between "runtime" and "compile-time".

#if LOWTOHIGH is a compile-time command.

if(something) is a run-time command.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Feb 27, 2019 12:57 am     Reply with quote

Key is to get into your head, the difference between 'source code', and the
'runtime' code this generates.

#if is a command executed at _compile_ time, affecting which part of the
source code is actually compiled.

if is a command executed at _run time_ affecting which part of the code
actually executes.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 03, 2019 3:14 pm     Reply with quote

You're wrong..but I understand why you're confused.

You need to read Mt. T's reply again

#IF (condition is true...) CREATES code that gets loaded into the program that you download into the PIC

if (condition is true) EXECUTES code WHILE the program is running

If you look at some of the CCS suppled example programs you'll see at the top of the code something like

#IF __PCM__
...do this code
#ELIF __PCH__
...do this code
#ENDIF

What this is doing is telling the compiler to 'configure' or 'create' a section of code based upon what type of PIC you're using. It then adds that code
to the overall program THEN compiles it.
Only ONE section of code is put into the program.

I understand English is difficult ! I live in Canada and after 65 years STILL cannot understand some of it !!

Hope this helps
Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group