CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

io settings in pic16f506

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

io settings in pic16f506
PostPosted: Thu Jun 08, 2017 4:02 am     Reply with quote

How to disable c1out alternative pin of rb2 in pic16f506 microcontroller??
And how use that pin as output?? using ccs compiler...
Ttelmah



Joined: 11 Mar 2010
Posts: 19514

View user's profile Send private message

PostPosted: Thu Jun 08, 2017 7:40 am     Reply with quote

Turn off the comparator.

This is why you will commonly see a line like:

setup_comparator(NC_NC_NC_NC);

at the start of a lot of programs.

The comparator has priority over the normal I/O functions, and since it may be used for things like current limiting, which must happen as soon as the chip boots, defaults to 'on' on many PIC's.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 09, 2017 2:29 am     Reply with quote

You should also disable the analog pins. Try this program:
Code:

#include <16F506.H>
#fuses INTRC_IO,IOSC4,NOWDT,MCLR
#use delay(clock=4M)

//=========================
void main()
{
setup_comparator(NC_NC);  // Turn off comparators
setup_adc_ports(NO_ANALOGS);  // Disable analog inputs

while(TRUE)
  {
   output_high(PIN_B2);
   delay_ms(500);
   output_low(PIN_B2);
   delay_ms(500);
  }

}


Make sure you have a 10K pull-up resistor on the MCLR pin.
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

PostPosted: Fri Jun 09, 2017 11:20 pm     Reply with quote

i tried this code but it's not working .....

showing led on rb2 pin continuously off....

what should do???

setup_comparator(NC_NC); // Turn off comparators

i think this will turn off comparator inputs only know??? what about c1out ??how to disable this alternative pin of rb2??
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 09, 2017 11:45 pm     Reply with quote

C1OUT should be disabled by the setup_comparator(NC_NC) line.

I don't know what CCS compiler version you have. You didn't tell us.
Maybe in your version those functions don't work correctly.

Here is a revised program that writes directly to the registers.
This should disable the comparators, and disable C1OUT, and disable
the analog inputs. Try this program:
Code:

#include <16F506.H>
#fuses INTRC_IO,IOSC4,NOWDT,MCLR
#use delay(clock=4M)

#byte CM1CON0 = 0x08
#byte CM2CON0 = 0x0B
#byte ADCON0 =  0x09
#bit  ANS0 = ADCON0.6
#bit  ANS1 = ADCON0.7

//=========================
void main()
{
//setup_comparator(NC_NC);
//setup_adc_ports(NO_ANALOGS);

// These are the same values that my version of the PCB compiler
// writes to these registers.  I have PCB vs. 4.073.
CM1CON0 = 0x71;    // Disable comparator #1 and C1OUT
CM2CON0 = 0x61;    // Disable comparator #2 and C2OUT
ANS0 = 0;    // Disable all analog inputs.  Make them be digital pins.
ANS1 = 0;

while(TRUE)
  {
   output_high(PIN_B2);
   delay_ms(500);
   output_low(PIN_B2);
   delay_ms(500);
  }

}
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

PostPosted: Sat Jun 10, 2017 4:22 am     Reply with quote

hello...

Quote:
I don't know what CCS compiler version you have. You didn't tell us.



im using PCB vs 5.017d
Ttelmah



Joined: 11 Mar 2010
Posts: 19514

View user's profile Send private message

PostPosted: Sat Jun 10, 2017 7:10 am     Reply with quote

When you disable the comparator, it turns the actual peripheral off.
The ADC's on modern compilers default to off, but should also be disabled as PCM_Programmer says. However have just tested with 5.016, and it correctly works with just the comparator disabled.

Your version, says it is the free 'test' version. Probably has a code size limit, but shouldn't affect anything this small.

Haven't kept 5.017, but have just tried 5.016 & 5.019, and it runs correctly with both.

Are you sure your chip is running?. MCLR is enabled, so does need to be pulled to 5v.
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

PostPosted: Mon Jun 12, 2017 1:34 am     Reply with quote

is their any relation between RB2 and RB4?
why rb4 affected on rb2
in this code...

Code:

#include <16F506.H>
#fuses INTRC_IO,IOSC4,NOWDT,MCLR
#use delay(clock=4M)

//=========================
void main()
{
setup_comparator(NC_NC);  // Turn off comparators
setup_adc_ports(NO_ANALOGS);  // Disable analog inputs

while(TRUE)
  {
   output_high(PIN_B2);
   delay_ms(500);
   output_low(PIN_B2);
   delay_ms(500);
   output_high(PIN_B4);
   delay_ms(500);
   output_low(PIN_B4);
   delay_ms(500);
  }

}

Ttelmah



Joined: 11 Mar 2010
Posts: 19514

View user's profile Send private message

PostPosted: Mon Jun 12, 2017 1:52 am     Reply with quote

No.

You can create connections by accident. For instance if your output connects to an LED without an adequate current limiting resistor, one output could reset the chip, and apparently affect the other. Or (of course), there could simply be a short on your board.
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

PostPosted: Mon Jun 12, 2017 4:08 am     Reply with quote

Quote:
You can create connections by accident. For instance if your output connects to an LED without an adequate current limiting resistor, one output could reset the chip, and apparently affect the other. Or (of course), there could simply be a short on your board.

Not at all. I have connected correctly and my board also working good.

Both leds are glowing at the same time Crying or Very sad Crying or Very sad

What should i do ? plz help...
Ttelmah



Joined: 11 Mar 2010
Posts: 19514

View user's profile Send private message

PostPosted: Mon Jun 12, 2017 6:28 am     Reply with quote

Check again.

You have a hardware problem.

Take the PIC out. Pull the signals high/low with jumper wires. What happens?.
saksun



Joined: 01 Jun 2017
Posts: 15

View user's profile Send private message

PostPosted: Sat Jun 17, 2017 12:21 am     Reply with quote

Thank you all,

My code and hardware are both working good.

Thank you for all your support.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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