![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
kodomo32
Joined: 07 Apr 2015 Posts: 3
|
pic communication using uart (PIC16F628) |
Posted: Fri Jul 10, 2015 7:35 pm |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jul 10, 2015 8:25 pm |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Sat Jul 11, 2015 4:54 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|