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 CCS Technical Support

How to use invert bit in define command by macro

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
huynhhai



Joined: 04 Apr 2015
Posts: 39

View user's profile Send private message

How to use invert bit in define command by macro
PostPosted: Fri Feb 11, 2022 9:05 pm     Reply with quote

Hi Everyone,

I had one a hardware, now i want to write code to use it, (my PIC16F886)
in the define line: #define led PIN_C5


the code in my program:

output_high(led); --> PIN_C5 will come 1

my question:
output_high(led); --> PIN_C5 will come 0, it mean PIN_C5 will be invert bit from 1 to 0

OR output_low(led); --> PIN_C5 =1??

how i change #define led PIN_C5 ??

Please help me about them.

Regarsd
huynhhai
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 11, 2022 9:11 pm     Reply with quote

output_high means the pin will set high (+3 or +5), whatever VDD is
output_low means the pin will set low (zero)

As to whether a high turns on the LED, depends on how the LED and it's resistor are wired.
If the Anode of the LED is on the port_pin and it's resistor tied to ground, then a high will turn on the LED.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 11, 2022 9:47 pm     Reply with quote

I'm not sure what you want, but look at output_toggle() to invert a pin.
huynhhai



Joined: 04 Apr 2015
Posts: 39

View user's profile Send private message

How to use invert bit in define command by macro
PostPosted: Fri Feb 11, 2022 10:30 pm     Reply with quote

I can use macro to write code on command #define such as output_toggle(),

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Feb 12, 2022 3:04 am     Reply with quote

Key here is the concept of 'reserved words'. No, you cannot change the
meaning of a reserved word with a macro. Output_high and output_low
are reserved words. If you did change these, it would make every library
not work, etc. etc.
Use your own keyword. So:
Code:

#define LED_ON(x) output_low(x)

Then to turn the LED 'ON' you use LED_ON(PIN). If you want 'ON' to be
high or low, you can just change the define.
huynhhai



Joined: 04 Apr 2015
Posts: 39

View user's profile Send private message

How to use invert bit in define command by macro
PostPosted: Sun Feb 13, 2022 11:16 pm     Reply with quote

Thank you very much for you help, i solved it by changed code in programs (changed library).

Regards,
huynhhai
PrinceNai



Joined: 31 Oct 2016
Posts: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Feb 14, 2022 12:08 pm     Reply with quote

I'm sure it works. For now. And only for you. If you update the compiler, those libraries will be overwritten. If you have a copy in your project folder, you'll have two different libraries with the same name doing opposite things. The way all the other guys told you to do it is for a reason. Many reasons, actually. Who on earth would think that output_low actually sets the bit? That is why the function name is output_low. It outputs low. You wouldn't code a start() function to stop something :-)
temtronic



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

View user's profile Send private message

PostPosted: Mon Feb 14, 2022 1:46 pm     Reply with quote

re:
Quote:
You wouldn't code a start() function to stop something :-)


gee, that's how most of my projects work ! Very Happy
'start' begins the 'stopping' process.....sigh.
even more fun when there's 3 outputs(start,stop, and 'inbetween') !

Man I hated 'inverse' logic designs with 7400 series chips, then found 7486(?) where I could use one pin to control output high if input high; or low if input high;stuff.....or is that 'active low', arrgh it's easy to confuse this dinosaur !

he could create a 'my_output_high()' function to do whatever.....
or a 'conditional' within the program based on hardware ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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