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 support@ccsinfo.com

I/O conflict on Port C of 16F877

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







I/O conflict on Port C of 16F877
PostPosted: Thu Jun 26, 2003 11:10 am     Reply with quote

I can't seem to configure pins 6 and 7 of port C on my chip w/o screwing up pin 5.

#use fast_io(c)

set_tris_c(0x00);

Those two lines are the only time I believe I am using to setup port c. Are there other commands I might have nested in my program that create a conflict? Is there another command(s) I need to put in?

NOTE: I have commented out the line below already and still have a problem:
#use RS232(Baud=9600,Xmit=PIN_C6,Rcv=PIN_C7)

Sincerely,
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515579
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I/O conflict on Port C of 16F877
PostPosted: Thu Jun 26, 2003 12:19 pm     Reply with quote

:=I can't seem to configure pins 6 and 7 of port C on my chip w/o screwing up pin 5.
:=
:=#use fast_io(c)
:=
:=set_tris_c(0x00);
------------------------------------------------------------

Can you post a small program that shows your problem ?
Put in comments that show when the program "screws up pin 5".

Also give your version of the compiler.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515582
bgb109
Guest







Re: I/O conflict on Port C of 16F877
PostPosted: Thu Jun 26, 2003 1:22 pm     Reply with quote

:=:=I can't seem to configure pins 6 and 7 of port C on my chip w/o screwing up pin 5.
:=:=
:=:=#use fast_io(c)
:=:=
:=:=set_tris_c(0x00);
:=------------------------------------------------------------
:=
:=Can you post a small program that shows your problem ?
:=Put in comments that show when the program "screws up pin 5".
:=
:=Also give your version of the compiler.

I'm using IDE 3.23, PCB/PCM 3.128

#use FAST_IO(C)
#define ELEV_DIR_BIT PIN_C0
#define ELEV_PWM PIN_C1
#define CONV_PWM PIN_C2
#define CONV_DIR_BIT PIN_C3
#define MOVE_LIFT_DOWN PIN_C4
#define MOVE_LIFT_UP PIN_C5
#define OUTPUT_FOUR_SIGNAL PIN_C6
#define OUTPUT_FIVE_SIGNAL PIN_C7

//The following five commands happen in void(main). At the end
//of void(main) it jumps into a loop until it loses power. Pins
//1-4 seem to work fine regardless, so I've not included them.
set_tris_c(0x00);
output_low(MOVE_LIFT_UP);
output_high(MOVE_LIFT_DOWN);
output_low(OUTPUT_FOUR_SIGNAL);
output_low(OUTPUT_FIVE_SIGNAL);

//The following is an example of how these pins are used.
//There is a loop checking different status bits that sets my
//outputs something like this:

if(READY)
{
output_high(OUTPUT_FOUR_SIGNAL);
output_low(OUTPUT_FIVE_SIGNAL);
}
else
{
output_low(OUTPUT_FOUR_SIGNAL);
output_high(OUTPUT_FIVE_SIGNAL);
}

//Elsewhere in the code there is a switch(IndexStep) statement.
//Below is a sample case.

case 5:
if(TRAY_ON_CONV==1)
{
BankB(); //this and BankA() toggle a mux bit
if(!input(stop_at_stack))
{
BankA();
if(input(REVERSE_SLOW_DOWN))
{
output_high(MOVE_LIFT_UP);
output_low(MOVE_LIFT_DOWN);
IndexTimer=timesince(0);
IndexStep++;
}
}
else
{
if(timesince(IndexTimer)>timeout_b)
{
error=indextimeout;
IndexStep=69;
}
}
}
else
{
output_high(MOVE_LIFT_UP);
output_low(MOVE_LIFT_DOWN);
IndexTimer=timesince(0);
IndexStep++;
}
break;

//It is executing this code, because MOVE_LIFT_DOWN is
//switching. For some reason though, the bit for MOVE_LIFT_UP
//doesn't. The rest of the code checks some sensors and
//timesout when the cylinder doesn't move.

Hope this helps you help me.
BR,
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515584
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I/O conflict on Port C of 16F877
PostPosted: Thu Jun 26, 2003 7:20 pm     Reply with quote

I stripped your program down to this small test program.
I installed PCM vs. 3.128 and tested this program.
It toggles pin C4 and C5 on my test board.
I checked them with an oscilloscope.

<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
<BR>
#use FAST_IO(C)
<BR>
#define ELEV_DIR_BIT PIN_C0
#define ELEV_PWM PIN_C1
#define CONV_PWM PIN_C2
#define CONV_DIR_BIT PIN_C3
#define MOVE_LIFT_DOWN PIN_C4
#define MOVE_LIFT_UP PIN_C5
#define OUTPUT_FOUR_SIGNAL PIN_C6
#define OUTPUT_FIVE_SIGNAL PIN_C7
<BR>
//===========================================
void main()
{
<BR>
set_tris_c(0x00);
<BR>
output_low(MOVE_LIFT_UP);
output_high(MOVE_LIFT_DOWN);
output_low(OUTPUT_FOUR_SIGNAL);
output_low(OUTPUT_FIVE_SIGNAL);
<BR>
while(1)
{
output_high(MOVE_LIFT_UP);
output_low(MOVE_LIFT_DOWN);
delay_us(100);

output_low(MOVE_LIFT_UP);
output_high(MOVE_LIFT_DOWN);
delay_us(100);
}
<BR>
<BR>
while(1);
}

</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515590
bgb109
Guest







Re: I/O conflict on Port C of 16F877
PostPosted: Fri Jun 27, 2003 5:54 am     Reply with quote

:=I stripped your program down to this small test program.
:=I installed PCM vs. 3.128 and tested this program.
:=It toggles pin C4 and C5 on my test board.
:=I checked them with an oscilloscope.
:=
:=<PRE>
:=#include "c:\Program Files\Picc\Devices\16F877.H"
:=#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
:=#use delay(clock = 8000000)
:=<BR>
:=#use FAST_IO(C)
:=<BR>
:=#define ELEV_DIR_BIT PIN_C0
:=#define ELEV_PWM PIN_C1
:=#define CONV_PWM PIN_C2
:=#define CONV_DIR_BIT PIN_C3
:=#define MOVE_LIFT_DOWN PIN_C4
:=#define MOVE_LIFT_UP PIN_C5
:=#define OUTPUT_FOUR_SIGNAL PIN_C6
:=#define OUTPUT_FIVE_SIGNAL PIN_C7
:=<BR>
:=//===========================================
:=void main()
:={
:=<BR>
:=set_tris_c(0x00);
:=<BR>
:=output_low(MOVE_LIFT_UP);
:=output_high(MOVE_LIFT_DOWN);
:=output_low(OUTPUT_FOUR_SIGNAL);
:=output_low(OUTPUT_FIVE_SIGNAL);
:=<BR>
:=while(1)
:= {
:= output_high(MOVE_LIFT_UP);
:= output_low(MOVE_LIFT_DOWN);
:= delay_us(100);
:=
:= output_low(MOVE_LIFT_UP);
:= output_high(MOVE_LIFT_DOWN);
:= delay_us(100);
:= }
:=<BR>
:=<BR>
:=while(1);
:=}
:=
:=</PRE>

They toggle on my board too ... when I comment out the sections where I'm switching C6 and C7 in runtime. I was talking to a tech support guy at microchip and suggested that I had read/write/modify problem. In other words, output_high/low compiles to a bit set or bit clear function which reads the state of the port first then writes the appropriate bit or bits. Could miswired hardware cause this problem?

I was also looking at the 16f8xx data sheet and they suggest in the section on Port C that if one of the peripheral functions is enabled it would override the set_tris command. What CCS functions would correspond to these peripheral functions?

Best Regards,
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515593
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I/O conflict on Port C of 16F877
PostPosted: Fri Jun 27, 2003 12:03 pm     Reply with quote

:=They toggle on my board too ... when I comment out the sections where I'm switching C6 and C7 in runtime. I was talking to a tech support guy at microchip and suggested that I had read/write/modify problem. In other words, output_high/low compiles to a bit set or bit clear function which reads the state of the port first then writes the appropriate bit or bits. Could miswired hardware cause this problem?
:=
:=I was also looking at the 16f8xx data sheet and they suggest in the section on Port C that if one of the peripheral functions is enabled it would override the set_tris command. What CCS functions would correspond to these peripheral functions?
:=
----------------------------------------------------------------

I added code to toggle C6 and C7 in runtime, and it
still works. In the test program below, pins C4, C5,
C6, and C7 all toggle OK. (I used your version -- PCM 3.128).
Can you run this test program ? Does it work OK ?

With regard to your questions above:

1. What do you have connected to the PIC pins -- in terms
of resistive or capacitive loads ? If you are running
at 20 MHz, and have a large capacitive load on a pin,
then it could cause the problem that you describe.

2. Here are some CCS functions that enable peripherals, and
cause peripheral override to occur on some Port C pins:

#use rs232
#use i2c (with FORCE_HW parameter)
setup_spi()



Here's what I think you should do:

1. Comment out entire blocks of code until things start working.
Then put pieces of them back in, until it fails again.
Then you'll have found the problem line.

2. Use standard i/o mode (it's the default mode), instead of
fast i/o. Don't use set_tris_x(). To set a pin to be
an input, use the output_float(xxx) function.
To set pins high or low, use output_high(xxx) and
output_low(xxx).

3. Explicitly initialize every pin in Port C in the way that
you want it. Example:

void init_io_pins(void)
{
output_float(PIN_C0); // Input
output_float(PIN_C1); // Input
output_low(PIN_C2); // Output -- set low initially
output_high(PIN_C3); // Output -- set high initially
output_low(PIN_C4); // Output -- set low initially
output_low(PIN_C5); // Output -- set low initially

// These next two pins are for the hardware USART.
// Pin C6 is the Tx pin, so set it as an output (high level).
// Since pin C7 is the Rx pin, initialize it as an input.
output_high(PIN_C6);
output_float(PIN_C7);

delay_ms(10); // Allow some settling time.
}

Note: This assumes you are using standard i/o, which you
should be using until you get your program working. Then,
if you wish, you can try to make fast i/o work.


<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
<BR>
#use FAST_IO(C)
<BR>
#define ELEV_DIR_BIT PIN_C0
#define ELEV_PWM PIN_C1
#define CONV_PWM PIN_C2
#define CONV_DIR_BIT PIN_C3
#define MOVE_LIFT_DOWN PIN_C4
#define MOVE_LIFT_UP PIN_C5
#define OUTPUT_FOUR_SIGNAL PIN_C6
#define OUTPUT_FIVE_SIGNAL PIN_C7
<BR>
<BR>
//=========================================================
void main()
{
<BR>
set_tris_c(0x00);
<BR>
output_low(MOVE_LIFT_UP);
output_high(MOVE_LIFT_DOWN);
output_low(OUTPUT_FOUR_SIGNAL);
output_low(OUTPUT_FIVE_SIGNAL);
<BR>
while(1)
{
output_high(MOVE_LIFT_UP);
output_low(MOVE_LIFT_DOWN);
<BR>
output_high(PIN_C6);
output_low(PIN_C7);
<BR>
delay_us(100);
<BR>
output_low(MOVE_LIFT_UP);
output_high(MOVE_LIFT_DOWN);
<BR>
output_low(PIN_C6);
output_high(PIN_C7);
<BR>
delay_us(100);
}
<BR>
while(1);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515611
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