View previous topic :: View next topic |
Author |
Message |
saksun
Joined: 01 Jun 2017 Posts: 15
|
io settings in pic16f506 |
Posted: Thu Jun 08, 2017 4:02 am |
|
|
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: 19498
|
|
Posted: Thu Jun 08, 2017 7:40 am |
|
|
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
|
|
Posted: Fri Jun 09, 2017 2:29 am |
|
|
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
|
|
Posted: Fri Jun 09, 2017 11:20 pm |
|
|
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
|
|
Posted: Fri Jun 09, 2017 11:45 pm |
|
|
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
|
|
Posted: Sat Jun 10, 2017 4:22 am |
|
|
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: 19498
|
|
Posted: Sat Jun 10, 2017 7:10 am |
|
|
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
|
|
Posted: Mon Jun 12, 2017 1:34 am |
|
|
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: 19498
|
|
Posted: Mon Jun 12, 2017 1:52 am |
|
|
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
|
|
Posted: Mon Jun 12, 2017 4:08 am |
|
|
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
What should i do ? plz help... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Mon Jun 12, 2017 6:28 am |
|
|
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
|
|
Posted: Sat Jun 17, 2017 12:21 am |
|
|
Thank you all,
My code and hardware are both working good.
Thank you for all your support. |
|
|
|