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 communication using uart (PIC16F628)

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



Joined: 07 Apr 2015
Posts: 3

View user's profile Send private message

pic communication using uart (PIC16F628)
PostPosted: Fri Jul 10, 2015 7:35 pm     Reply with quote

Hello

I want to connect 2 device(Computer and Printer) with max232
-------------------------------------------------------------------------------
Computer (Baud rate:2400) =>Micro controller(PIC16F628)=>Printer(Baud rate:9600)
--------------------------------------------------------------------------------
but they have different baud rate, I'm trying to test code but it's not work.
Cloud you help me,please
Code:
#include <16F628A.H>
#fuses  HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

#use RS232(STREAM=gps,BAUD=2400, RCV=PIN_B1)
#use RS232(STREAM=dbg,BAUD=9600, XMIT=PIN_B2)

//======================================
main(void)
{
char ch;

while(1)
 {
  ch = fgetc(gps);
  fputc( ch, dbg);
 }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 10, 2015 8:25 pm     Reply with quote

Quote:
#use RS232(STREAM=gps,BAUD=2400, RCV=PIN_B1)
#use RS232(STREAM=dbg,BAUD=9600, XMIT=PIN_B2)

The 16F628A has only one hardware UART and it can only have one
baudrate for both transmit and receive.

You also can't split the hardware UART into two pieces for Tx and Rx.
The compiler will create two software uarts with your two #use
rs232 statements.

Quote:
I want to connect 2 device(Computer and Printer)

Then why are the streams called dbg (debug) and gps ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19559

View user's profile Send private message

PostPosted: Sat Jul 11, 2015 4:54 am     Reply with quote

What you could do, is to configure the hardware UART to use both pins, at 2400bps (since this is the 'receiving' device, and this is therefore much easier to do with the hardware), then also setup a software UART for transmit on the output pin only, then disable the TX side of the UART in the code before using the transmit. A search here will find lots of threads telling you how to disable just one half of the UART.
Awkward, but should work fine.
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