View previous topic :: View next topic |
Author |
Message |
chipp
Joined: 08 Mar 2005 Posts: 2
|
PIC 16F767 rs232 Read Problems |
Posted: Tue Mar 08, 2005 3:00 pm |
|
|
Hi I'm having the hardest time getting my 16F767 to properly read over the rs232 port. It reads in 1 character then puts out a whole bunch of garbage characters and then freezes.
Perhaps I'm missing something important in the set-up? Perhaps the compiler version isn't generating thr correct rs232 code??? (How do I check?)
Thanks! chipp
Using Hardware USART at 9600.
Using 20Mhz Ceramic Resonator as Clock.
Compiler: PCM 3.212
Code: |
#include <16F767.h>
#use delay(clock=20000000)
// This is CCS's setup
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8, brgh1ok)
void main() {
char c;
set_tris_a(0x00000000;
set_tris_b(0x00000000);
set_tris_c(0x10000000); // C7 rx, C6 tx
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
while(TRUE) {
if(kbhit()) {
c = getc();
delay_ms(1);
putc(c);
delay_ms(1);
}
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 08, 2005 3:19 pm |
|
|
Try a more simple test program, and also include a #fuses statement.
Try sending characters to the PIC by typing in a terminal program.
You should see them echo'ed back to the terminal.
Code: | #include <16F767.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main()
{
char c;
while(1)
{
c = getc();
putc(c);
}
}
|
Note that this PIC doesn't support Low Voltage Programming, so the
LVP and NOLVP fuses are not an issue here. |
|
|
chipp
Joined: 08 Mar 2005 Posts: 2
|
It Works! |
Posted: Thu Mar 10, 2005 11:46 am |
|
|
Thank you, simple as it is it works, it seems like setting the TRIS on Port C was somehow interferring, so I commented it out:
Code: |
// set_tris_c(0x10000000); // C7 rx, C6 tx
|
|
|
|
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Thu Mar 10, 2005 2:54 pm |
|
|
I had a similar problem, my pic received all what he transmitted!!
I solved setting in a correct way TrisC.
in your case 0x10000000 is a hexadecimal number not a binary one.
tri to set 0b10000000 or 0x80 in TRISC |
|
|
|