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 CCS Technical Support

PIC 16f628a RS232 mystery

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



Joined: 22 Nov 2010
Posts: 3
Location: Brusque/Florianópolis SC - Brazil

View user's profile Send private message Visit poster's website

PIC 16f628a RS232 mystery
PostPosted: Mon Nov 22, 2010 12:06 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Mon Nov 22, 2010 12:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 22, 2010 1:47 pm     Reply with quote

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: 19538

View user's profile Send private message

PostPosted: Mon Nov 22, 2010 3:36 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Nov 24, 2010 12:21 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 24, 2010 1:54 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Nov 24, 2010 8:10 pm     Reply with quote

Or save some money and board space...

http://www.botkin.org/dale/rs232_interface.htm
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