| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Polar 
 
 
 Joined: 15 Oct 2003
 Posts: 1
 
 
 
			    
 
 | 
			
				| IO port help, please! |  
				|  Posted: Wed Oct 15, 2003 8:14 pm |   |  
				| 
 |  
				| G'day all. 
 This might be a bit of a silly question, but I am quite new at this and really need help urgently.
 
 I am currently programming a PIC16f876 to communicate with an optical mouse sensor. I am using PORTA for this purpose. It has two main communication lines, one for a serial clock and one for serial data communication.
 I want to use PIN_A0 for my serial clock output to the sensor and pins A1 and A2 for sending data and receiving respectively.
 
 I have set up PORTA by setting the TRISA register to 0xf4 (set_tris_a(0xf4) ). Now I want to clock data through to the sensor. My problem arises when I change PIN_A0:
 
 For example this code which would be in a while statement:
 //this code is only for writing the address to the the sensor which I
 //want to read from.
 
 //while begins
 1 output_low(PIN_A0);  //downclock
 2 if (address bit must be high)
 3   output_high(PIN_A1); //sets an address bit to be clocked through
 4 else
 5   output_low(PIN_A1);
 6 delay_us(5);
 7 output_high(PIN_A0); //clocks the address bit into the sensor
 8 delay_us(5);
 //while ends
 
 The problem I have is that whenever the code in line 7 is done that PIN_A1 is immediately set low again. Thus not waiting for the next if statement to set the new value of PIN_A1. I have a feeling it is the way I have set up PORTA.
 Should I use fast_io? Should I turn ADC off or should it no make a difference? If someone can maybe give me an example of setting up PORTA for this kind of application I would be very gratefull.
 |  |  
		|  |  
		| ajt 
 
 
 Joined: 07 Sep 2003
 Posts: 110
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Oct 15, 2003 8:53 pm |   |  
				| 
 |  
				| Try: setup_adc_ports(NO_ANALOGS);
 _________________
 Al Testani
 |  |  
		|  |  
		| Pete Smith 
 
 
 Joined: 17 Sep 2003
 Posts: 55
 Location: Chester, UK
 
 
			          
 
 | 
			
				| Re: IO port help, please! |  
				|  Posted: Thu Oct 16, 2003 3:44 am |   |  
				| 
 |  
				|  	  | Polar wrote: |  	  | G'day all. 
 I want to use PIN_A0 for my serial clock output to the sensor and pins A1 and A2 for sending data and receiving respectively.
 
 I have set up PORTA by setting the TRISA register to 0xf4 (set_tris_a(0xf4) ). Now I want to clock data through to the sensor.
 .
 | 
 
 In my experience, you have to be careful setting TRIS register. You've got the top 2 bits set. the 876 has only 6 bits, so I'd set it to
 
 0b000100
 
 IME, I've tried setting the top 2 bits on the port_a tris, and it made the whole thing not work very well!
 
 The second problem is that when you use standard IO, you don't need the TRIS, if you use fast_io, you do need the tris.
 
 FWIW, I never use standard IO, because I like control of my own code thank you very much.
 
 HTH
 
 Pete.
 |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |