| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			Khansokhua
 
 
  Joined: 06 Nov 2021 Posts: 92
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| PIC16F877A  int_ext | 
			 
			
				 Posted: Sat Nov 27, 2021 4:07 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Code: | 	 		  #include <Timerlar.h>
 
#fuses XT
 
#use delay(clock=4M)
 
#use fast_io(b)
 
int i;
 
const int segment[10]= {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7C,0x07,0x7F,0x6F};
 
 
#int_ext
 
void ext_kesme()
 
{
 
   output_high(pin_d0);
 
   delay_ms(1000);
 
   output_low(pin_d0);
 
   delay_ms(3000);
 
   
 
   for(i=0;i<=9;i++)
 
   {    
 
        output_c(segment[i]);
 
        output_high(pin_d0);
 
        delay_ms(500);
 
        output_low(pin_d0);
 
        delay_ms(500);   
 
   }
 
 
}
 
 
 
void main()
 
{   
 
  set_tris_b(0x01);
 
    
 
   output_c(0x00);
 
   output_d(0x00);   
 
   output_a(0x02);
 
 
 
     
 
   ext_int_edge(L_TO_H);
 
   
 
   enable_interrupts(int_ext);
 
   enable_interrupts(GLOBAL);
 
}
 
 | 	  
 
Hi greetings! I don't know why, how on PORTB  RB2-RB3-RB5-RB6 were being logic "1". I just wonder why this happened ?
 
If someone could explain, thanks respects! | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Re: PIC16F877A  int_ext | 
			 
			
				 Posted: Sat Nov 27, 2021 9:29 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Khansokhua wrote: | 	 		  
 
   output_c(0x00);
 
   output_d(0x00);   
 
   output_a(0x02);
 
 
 
I don't know why, how on PORTB  RB2-RB3-RB5-RB6 were being logic "1".  | 	  
 
You never initialize PortB.  You only initialize ports C, D, and A.
 
If you want PortB to be 0x00, then add this line:
 
 | 
			 
		  | 
	
	
		  | 
	
	
		
			Ttelmah
 
 
  Joined: 11 Mar 2010 Posts: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Sat Nov 27, 2021 12:20 pm     | 
				     | 
			 
			
				
  | 
			 
			
				The point is you set the TRIS:
 
 
set_tris_b(0x01);
 
 
Now the register for a port defaults to '1' (data sheet), so when you set
 
the tris to set these bits as outputs all the bits (except B1), go high.
 
To set the bits to low, and leave B1 as an input - get rid of the above
 
TRIS instruction, then:
 
 	  | Code: | 	 		  
 
   output_b(0); //B0 to B7 now all 0
 
   output_float(PIN_B1); //B1 is now an input
 
 | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			Khansokhua
 
 
  Joined: 06 Nov 2021 Posts: 92
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Mon Nov 29, 2021 4:10 am     | 
				     | 
			 
			
				
  | 
			 
			
				| Thank you | 
			 
		  | 
	
	
		  | 
	
	
		 |