| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| John_Rio 
 
 
 Joined: 22 Jan 2005
 Posts: 12
 Location: Rio de Janeiro, Brazil
 
 
			      
 
 | 
			
				| How to read output. |  
				|  Posted: Sat Jan 22, 2005 1:58 pm |   |  
				| 
 |  
				| Hi, I'am new in using the C & CCS compiler.
 I have made a program the sets or clears outputs on the pic.
 how can i read the actual state on a pin.
 i tried:
 if (pin_b4) do_what_ever; else do_somthing_else;
 But it doesent work.
 It's easy in assembler, so it should be possible here too?
 
 Please help..
 
 John
 |  | 
	
		|  | 
	
		| rwyoung 
 
 
 Joined: 12 Nov 2003
 Posts: 563
 Location: Lawrence, KS  USA
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Jan 22, 2005 2:23 pm |   |  
				| 
 |  
				|  	  | Code: |  	  | if (input(PIN_B4))
 {
 // do something impressive
 }
 
 | 
 is one way to do things.  Another is to create a #byte and #bit pragma and access the pin that way.  Need to #use fast_io() or #use fixed_io() if you #byte/#bit access the ports.  input() will work with #use standard_io(), #use fast_io() and #use fixed_io()
 _________________
 Rob Young
 The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
 |  | 
	
		|  | 
	
		| John_Rio 
 
 
 Joined: 22 Jan 2005
 Posts: 12
 Location: Rio de Janeiro, Brazil
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Jan 22, 2005 2:30 pm |   |  
				| 
 |  
				| I already tried the one you mentione here if (input(pin_b4) .... 
 The problem is that this sets the pin as an input.
 I am looking for a way to read the actual output.
 
 John
 |  | 
	
		|  | 
	
		| rwyoung 
 
 
 Joined: 12 Nov 2003
 Posts: 563
 Location: Lawrence, KS  USA
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Jan 22, 2005 2:54 pm |   |  
				| 
 |  
				| So what you are trying to do is readback the port register some time after altering the state of the output pin. 
 Have you tried (assuming PORTA on PIC16F877A, adjust to taste)
 
 
  	  | Code: |  	  | #byte PORTA = 0x05
 #bit PINA0 = PORTA.0
 
 #use fast_io(A)
 
 ... more code
 set_tris_A(0x00); // all outputs
 PINA0 = 1; // set pin high
 
 // do many things here and loose track of how pin was set
 
 if (PINA0)
 {
 // do something wonderful
 }
 
 | 
 
 I haven't tested this code myself.
 _________________
 Rob Young
 The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
 |  | 
	
		|  | 
	
		| John_Rio 
 
 
 Joined: 22 Jan 2005
 Posts: 12
 Location: Rio de Janeiro, Brazil
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Jan 22, 2005 3:22 pm |   |  
				| 
 |  
				| Thanks a lot. That did it.
 
 #bit powerbit=0xF81.4
 if (powerbit) Outbuffer[5]='0'; else Outbuffer[5]='1';
 
 I'am using 18F452 so i had to change the register address.
 
 Thanks a lot.[/list]
 |  | 
	
		|  | 
	
		|  |