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

putc turning port_c pin to input

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



Joined: 05 Jun 2006
Posts: 2

View user's profile Send private message

putc turning port_c pin to input
PostPosted: Mon Jun 05, 2006 1:44 pm     Reply with quote

Hi,

When running this code pin_c0 is high as expected until the putc('H') is executed. The trisc for pin c0 is then turned into an input and the bit for pin_c0 is reset. With the putc() line commented out the pin stays high as expected. I am using the CCS PCM C Compiler, Version 3.249 and a icd2. Does anyone have an idea what is going wrong?


Code:

#include <16f876.h>
#device *=16
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#device ICD=TRUE
#device ADC=10



#use DELAY (CLOCK=8000000, RESTART_WDT)
#use RS232(BAUD=19200, XMIT=PIN_C7, RCV=PIN_C6, BRGH1OK)
#use fast_io(C)
#include <stdlib.h>

void main(void){

  set_tris_c(0b10011100);
  output_high(PIN_C0);
  while(1){
    restart_wdt();
    putc('H');
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 05, 2006 2:05 pm     Reply with quote

I see two problems:

1. You have the pins reversed for Tx and Rx in your #use rs232()
statement. Because of this, the compiler will create a software
UART instead of using the hardware UART module.

2. You are using a "#use fast_io(C)" statement, but you have placed
it after the #use rs232() line. Because of this, the RS232 library
code uses "standard i/o" mode, while the rest of the program uses
fast i/o mode. In standard i/o mode, the compiler maintains a
shadow register for Port C. This shadow register is initialized by
the compiler to be all inputs. So when the putc('H') is executed,
the library code writes the shadow register out to the TRISC register
and that's why pin C0 becomes an input.

Solutions:
1. Make pin C6 be the Tx pin, and pin C7 be the Rx pin. Fix both your
program and the hardware wiring.

2. If you want to use fast i/o mode, then move the #use fast_io(C)
statement so it's above the #use rs232() statement.
Guest








PostPosted: Mon Jun 05, 2006 2:21 pm     Reply with quote

Thanks! It's working properly now. I have seen that use rs232 line many many times, never noticed that the pins were swapped. Did not know about the order of the #use rs232 and #use fast_io though. Thanks again Very Happy
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