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

Doubts about the PortC and the UART

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Doubts about the PortC and the UART
PostPosted: Tue Jun 05, 2012 9:26 am     Reply with quote

Hello, I have a question, is there any way to filter the status of the UART when using a pic18f452 PORTC ? By necessity I am working with a word of 5 bits in PORTC.
Code:

output_c (0X00);

But in doing this I am affecting the state of RC6 and RC7 for the UART ...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 05, 2012 3:00 pm     Reply with quote

The program below shows how to do it. It includes a test where I type
"asdf" repeatedly into a TeraTerm window and get it back from the PIC
with no problems:
Quote:

adfasdfasdfasdfasfdasdf

Code:

#include <18F452.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

// Must use fast i/o mode for a Port that is split into
// separate bitfields for reading and writing.
#use fast_io(C) 

// This structure divides PortC into two bitfields.
struct {
int8 MyBits:5;    // C0-C4: Output pins
int8 not_used:3;  // C5-C7 
}LATC;

#byte LATC = getenv("SFR:LATC")

// This macro allows easy access to MyBits without having to
// use the "dot" structure method in your code.
#define Write_MyBits(x) LATC.MyBits = x

//=====================================
void main (void)
{
int8 c;

// Set the lower 5 bits of PortC to be outputs.
// Also, set pin C6 (UART Tx) = output, and C7 (Rx) = input.
set_tris_c(0b10100000);   

while(1)
  {
   Write_MyBits(0xFF);
   c = getc();
   putc(c);

   Write_MyBits(0);
   c = getc();
   putc(c);
  }
 
}
 
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