View previous topic :: View next topic |
Author |
Message |
Nazgulzeh
Joined: 22 Nov 2010 Posts: 3 Location: Brusque/Florianópolis SC - Brazil
|
PIC 16f628a RS232 mystery |
Posted: Mon Nov 22, 2010 12:06 pm |
|
|
Hey all!
This is my first topic here =P
Well, I'm trying to send and receive data to a PIC 16f628a, however it is not working fine. Look this code:
Code: |
#include <16f628A.h>
#fuses HS,NOPROTECT,NOMCLR
#use delay (clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)
#define LED PIN_B4
void main(void){
while(TRUE)
puts( getc());
}
|
So... when I send an "A" to PIC the PIC sends an "P" to PC or when I send "=" I get "0" the same occurs for all chars. I really don't know what is happening here. It seems that program works in a code and the PIC in another code. Look this:
Code: |
#include <16f628A.h>
#fuses HS,NOPROTECT,NOMCLR
#use delay (clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)
#define LED PIN_B4
void main(void){
int8 c;
boolean b = false;
output_high(LED);
delay_ms(1000);
output_low(LED);
delay_ms(1000);
while(1) {
c = getc();
putc(c);
if(c == 'P' || c == 'p' || c == 'A' || c == 'a'){
b = !b;
output_bit(LED, b);
}
}
}
|
When I sent "=" the LED turns on or off. But WHY?
Thanks in advance.
PS: I'm using this program:
http://www.rogercom.com/PortaSerial/PortaSerial.htm
PS: Sorry my english is too bad. |
|
|
Nazgulzeh
Joined: 22 Nov 2010 Posts: 3 Location: Brusque/Florianópolis SC - Brazil
|
|
Posted: Mon Nov 22, 2010 12:32 pm |
|
|
Check this out:
Code: |
#include <16f628A.h>
#fuses HS,NOPROTECT,NOMCLR
#use delay (clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B2,rcv=PIN_B1,bits=8)
void main(void) {
while(TRUE)
putc('T');
}
|
This is what I received at serial port:
WWW... many W...WWÿ
If it sent T why I received W? It occurs ALWAYS.
Thanks |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Nov 22, 2010 1:47 pm |
|
|
Do you have a MAX232 or equal chip wired between the PIC and PC ?
This is necessary for correct serial communications....unless you add 'invert' to the RS232(...) function. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Nov 22, 2010 3:36 pm |
|
|
Also, what is the _minimum_ frequency 'HS' is designed to work with?.
Best Wishes |
|
|
Nazgulzeh
Joined: 22 Nov 2010 Posts: 3 Location: Brusque/Florianópolis SC - Brazil
|
|
Posted: Wed Nov 24, 2010 12:21 pm |
|
|
Well I changed the fuse HS to XT, and I tried to invert but I receive this msg:
Quote: | Executing: "C:\Program Files (x86)\PICC\Ccsc.exe" +FM "led.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 100 "led.c" Line 5(5,69): USE parameter value is out of range H/W USART can not invert
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Wed Nov 24 15:27:15 2010 |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 24, 2010 1:54 pm |
|
|
You can't use INVERT with the hardware UART. The CCS compiler will
automatically use the hardware UART if you specify the hardware pins.
But, you can override this behavior by adding the FORCE_SW directive
to your #use rs232() statement. Then it will create a software UART on
the hardware pins (and you can use INVERT).
However, the software UART is not as good as the hardware UART.
It's best if you add a Max232-type chip to your board, and use the
hardware UART. |
|
|
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
|
|