| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| 16F19176 PIN C2 not work input mode | 
			 
			
				 Posted: Wed Dec 23, 2020 3:30 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Hi,
 
PIN_C2 pin of 16F19176 is detected as 1 even when the input is 0 when it is in input mode. Even if we connect the pin directly to VSS, the situation does not change.
 
Anyone have this problem? _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			temtronic
 
 
  Joined: 01 Jul 2010 Posts: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Dec 23, 2020 3:35 pm     | 
				     | 
			 
			
				
  | 
			 
			
				I don't use that PIC but general comments..
 
You should post a small,compilable program that we can test.
 
 
Odds are that pin is used for several peripherals(ie ADC,comp,LCD,???) and you haven't disabled them.
 
 
Another reason may be that the pin has a 'solder  bridge or whisker' to VDD.
 
 
Jay | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Dec 23, 2020 6:03 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Pin C2 is available as an ordinary i/o pin.  
 
 
But it can also be Seg18.  Are you using the lcd module in that PIC ? 
 
If you are, it's possible that you enabled Seg18.
 
 
Post your small test program that toggles pin C2. | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 5:40 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | PCM programmer wrote: | 	 		  Pin C2 is available as an ordinary i/o pin.  
 
 
But it can also be Seg18.  Are you using the lcd module in that PIC ? 
 
If you are, it's possible that you enabled Seg18.
 
 
Post your small test program that toggles pin C2. | 	  
 
 
Below you can see a piece of my fuse settings code
 
fuses seting..
 
 
 	  | Code: | 	 		  
 
#device ADC=12
 
#device *=8
 
#FUSES RSTOSC_HFINTRC_PLL       //On Power-up clock running from HFINTRC with 4x PLL
 
#FUSES VBATEN                   //VBAT functionality is enabled
 
#FUSES NOLCDPEN                 //LCD Charge Pump forced off
 
#FUSES NOMCLR                   //Master Clear pin used for I/O
 
#FUSES BORV27                   //Brownout reset at 2.7V
 
#FUSES NOZCDDIS                 //Zero-cross detect circuit is enabled at POR
 
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
 
#FUSES NOWDT   //WDT512
 
#FUSES PROTECT  
 
#FUSES NOEXTOSC | 	  
 
 
 	  | Code: | 	 		  
 
 
....................       if(input(pin_c2)==0 && nemgirisisayac<20) nemgirisisayac++;
 
096A:  MOVLB  00
 
096B:  BSF    14.2
 
096C:  BTFSC  0E.2
 
096D:  GOTO   177
 
096E:  MOVLB  01
 
096F:  MOVF   3F,W
 
0970:  SUBLW  13
 
0971:  BTFSC  03.0
 
0972:  GOTO   175
 
0973:  MOVLB  00
 
0974:  GOTO   177
 
0975:  INCF   3F,F
 
0976:  MOVLB  00
 
....................       if(input(pin_c2)==1 && nemgirisisayac>0 ) nemgirisisayac--;
 
0977:  BSF    14.2
 
0978:  BTFSS  0E.2
 
0979:  GOTO   182
 
097A:  MOVLB  01
 
097B:  MOVF   3F,F
 
097C:  BTFSS  03.2
 
097D:  GOTO   180
 
097E:  MOVLB  00
 
097F:  GOTO   182
 
0980:  DECF   3F,F
 
0981:  MOVLB  00 | 	 
  _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			temtronic
 
 
  Joined: 01 Jul 2010 Posts: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 7:50 am     | 
				     | 
			 
			
				
  | 
			 
			
				some comments...
 
1) change PROTECT to NOPROTECT i the FUSES section.  There's no need to protect the PIC until final product goes 'out the door' to the customer. Using noprotect will extend the life of the PIC ( # of burns....)
 
 
2) you should just try a simple 'toggle on pin status' not some 'complicated' function. I don't use that PIC but the asm code does show proper testing of the  pin (providing the address of the register is correct). | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 12:18 pm     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | temtronic wrote: | 	 		  some comments...
 
1) change PROTECT to NOPROTECT i the FUSES section.  There's no need to protect the PIC until final product goes 'out the door' to the customer. Using noprotect will extend the life of the PIC ( # of burns....)
 
 
2) you should just try a simple 'toggle on pin status' not some 'complicated' function. I don't use that PIC but the asm code does show proper testing of the  pin (providing the address of the register is correct). | 	  
 
 
C2 pin works correctly as output mode.  Problem just input mode. and i try set_input_level_c(0xFF); command but reasult not change. _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 12:53 pm     | 
				     | 
			 
			
				
  | 
			 
			
				I had similar issue with 16F19197.
 
I tried the code below but it still didn't work.
 
 
 	  | Code: | 	 		  
 
   #byte PORTC = getenv("SFR:PORTC") 
 
 
 | 	  
 
 
 	  | Code: | 	 		  
 
....................       if(!bit_test(PORTC, 2))  nemgirisidevrede=0; 
 
096A:  MOVLB  00
 
096B:  BTFSC  0E.2
 
096C:  GOTO   170
 
096D:  MOVLB  01
 
096E:  CLRF   40
 
096F:  MOVLB  00
 
....................       if(bit_test(PORTC, 2))  nemgirisidevrede=1;
 
0970:  BTFSS  0E.2
 
0971:  GOTO   176
 
0972:  MOVLW  01
 
0973:  MOVLB  01
 
0974:  MOVWF  40
 
0975:  MOVLB  00
 
 | 	 
  _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 1:59 pm     | 
				     | 
			 
			
				
  | 
			 
			
				analog port settings are in my code;
 
 
 	  | Code: | 	 		  
 
    setup_adc (ADC_CLOCK_DIV_64);
 
    setup_adc_reference (VSS_VDD);
 
    setup_adc_ports (sAN0 | sAN23 | sAN34, VSS_VDD);
 
 | 	  
 
if you turn off analog inputs
 
 	  | Code: | 	 		  | setup_adc_ports (NO_ANALOGS); | 	  
 
If I write, pin_c2 works normally as input.
 
 
could it be a compiler error? _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			temtronic
 
 
  Joined: 01 Jul 2010 Posts: 9589 Location: Greensville,Ontario 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 2:11 pm     | 
				     | 
			 
			
				
  | 
			 
			
				yes, that's why we've asked for your simple,small test program that shows the problem, so that we can test. 
 
Also you need to post what compiler version you're using.
 
 
The problem with just showing parts of a program is we don't KNOW what the rest of it is doing(all the fuses, setup before main(), something else ???
 
 
 
Since the pin works with 'no_analogs', it sound like it _might_ be a compiler bug...
 
 
Jay | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 2:56 pm     | 
				     | 
			 
			
				
  | 
			 
			
				it's work correct.
 
 	  | Code: | 	 		  
 
 set_analog_pins(PIN_A0,PIN_C7,PIN_E2);
 
 | 	  
 
 
below define in  16f19176.h file adc parameters
 
 	  | Code: | 	 		  
 
#define sAN18         0x00000400  //| C2
 
#define sAN34         0x00000400  //| E2 
 
 | 	  
 
i think compiler  if use  setup_adc_ports ();  command make mistake. 
 
I haven't come across an example code on how to use port e pins with the set_adc_ports() command. _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 3:10 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Compiler version is 5.097 _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Thu Dec 24, 2020 8:16 pm     | 
				     | 
			 
			
				
  | 
			 
			
				Here is a small test program.  It works.  I tested it in hardware with
 
CCS vs. 5.097 just now.  Pin C2 has a push-button switch connected to it.
 
The switch puts ground on Pin C2 if pressed.  Pin C2 has a 4.7K pull-up
 
resistor on it (to +5v) so the idle state is a logic '1' on Pin C2.
 
 
 	  | Code: | 	 		  
 
#include <16F19176.h>
 
#use delay(internal=4M)
 
 //==========================  
 
void main(void)
 
{
 
 
 
while(TRUE)                      
 
  {
 
   if(input(PIN_C2) == 0)  // If pressed button
 
      output_high(PIN_B0);  // then turn on LED
 
   else 
 
      output_low(PIN_B0);  // else turn LED off
 
      
 
   delay_ms(20);  // Debounce period
 
  }
 
}  | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Dec 25, 2020 1:40 am     | 
				     | 
			 
			
				
  | 
			 
			
				Dear PCM programmer,
 
Reason
 
setup_adc_ports (sAN0 | sAN23 | sAN34, VSS_VDD); When using the command pin_c2 pin remains as analog input.
 
set_analog_pins (PIN_A0, PIN_C7, PIN_E2); Using the command pin_c2 and pin_e2 conflict can be avoided.
 
The following definitions are from the 16f19176.h file.
 
#define sAN18 0x00000400 // | C2
 
#define sAN34 0x00000400 // | E2 _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Dec 25, 2020 3:28 am     | 
				     | 
			 
			
				
  | 
			 
			
				According to the 16F19176.h file, the values for Port E go in the 2nd
 
parameter, like this:
 
 	  | Quote: | 	 		  | setup_adc_ports (sAN0 | sAN23, sAN34, VSS_VDD);  | 	  
 
Then it works:
 
 	  | Code: | 	 		  .................... setup_adc_ports (sAN0 | sAN23, [b]sAN34[/b], VSS_VDD); 
 
0023:  MOVLW  00
 
0024:  MOVLB  02
 
0025:  MOVWF  ADREF
 
 
0026:  MOVLW  01    
 
0027:  MOVLB  3E    // Bank 62 decimal
 
0028:  MOVWF  38    // ANSELA:  pin A0 (sAN0) is analog
 
 
0029:  MOVLW  00
 
002A:  MOVWF  43    // ANSELB: All digital
 
 
002B:  MOVLW  80
 
002C:  MOVWF  4E    // ANSELC: Pin C7 (sAN23) is analog
 
 
002D:  MOVLW  00
 
002E:  MOVWF  59    // ANSELD: All digital
 
 
002F:  MOVLW  04
 
0030:  MOVWF  64    // ANSELE: Pin E2 (sAN34) is analog
 
 | 	  
 
 
Test program:
 
 	  | Code: | 	 		  #include <16F19176.h> 
 
#use delay(internal=4M) 
 
 
//======================
 
void main(void)      
 
{ 
 
 
setup_adc_ports (sAN0 | sAN23, sAN34, VSS_VDD); 
 
 
while(TRUE);            
 
}  | 	 
  | 
			 
		  | 
	
	
		  | 
	
	
		
			esbelektronik
 
 
  Joined: 13 Dec 2018 Posts: 23
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| thanks. | 
			 
			
				 Posted: Fri Dec 25, 2020 1:01 pm     | 
				     | 
			 
			
				
  | 
			 
			
				dear PCM Programmer thanks for help. _________________ ^ ^
 
  (q  p)    ESB
 
 (   V  )
 
   L  L | 
			 
		  | 
	
	
		  | 
	
	
		 |