pilar
Joined: 30 Jan 2008 Posts: 197
|
Doubts about the PortC and the UART |
Posted: Tue Jun 05, 2012 9:26 am |
|
|
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.
But in doing this I am affecting the state of RC6 and RC7 for the UART ... |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 05, 2012 3:00 pm |
|
|
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);
}
}
|
|
|