| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			huynhhai
 
 
  Joined: 04 Apr 2015 Posts: 39
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| How to use invert bit in define command by macro | 
			 
			
				 Posted: Fri Feb 11, 2022 9:05 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Feb 11, 2022 9:11 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Feb 11, 2022 9:47 pm     | 
				     | 
			 
			
				
  | 
			 
			
				| I'm not sure what you want, but look at output_toggle() to invert a pin. | 
			 
		  | 
	
	
		  | 
	
	
		
			huynhhai
 
 
  Joined: 04 Apr 2015 Posts: 39
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| How to use invert bit in define command by macro | 
			 
			
				 Posted: Fri Feb 11, 2022 10:30 pm     | 
				     | 
			 
			
				
  | 
			 
			
				I can use macro to write code on command #define such as output_toggle(), 
 
 
Regards | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat Feb 12, 2022 3:04 am     | 
				     | 
			 
			
				
  | 
			 
			
				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
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| How to use invert bit in define command by macro | 
			 
			
				 Posted: Sun Feb 13, 2022 11:16 pm     | 
				     | 
			 
			
				
  | 
			 
			
				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: 554 Location: Montenegro 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Feb 14, 2022 12:08 pm     | 
				     | 
			 
			
				
  | 
			 
			
				| 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: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Feb 14, 2022 1:46 pm     | 
				     | 
			 
			
				
  | 
			 
			
				re:  	  | Quote: | 	 		  | You wouldn't code a start() function to stop something :-) | 	  
 
 
gee, that's how most of my projects work !   
 
'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 ? | 
			 
		  | 
	
	
		  | 
	
	
		 |