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

I'm crazy with rs232 and pic16f84

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







I'm crazy with rs232 and pic16f84
PostPosted: Fri Jul 04, 2003 5:57 am     Reply with quote

I can`t use the order #rs232 .... in pic16f84. I don't kwon what is the problem. Somebody have code in C to make a rs232 in a pic16f84.

Sorry by my English, is very bad.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515736
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

Re: I'm crazy with rs232 and pic16f84
PostPosted: Fri Jul 04, 2003 6:14 am     Reply with quote

:=I can`t use the order #rs232 .... in pic16f84. I don't kwon what is the problem. Somebody have code in C to make a rs232 in a pic16f84.
:=
:=Sorry by my English, is very bad.

Hello, The command you need is actually '#use rs232' It can be found in the user manual/help file. Example: #use rs232(baud=9600, xmit=PIN_A2,rcv=PIN_A3). Be careful that the pin you define as 'xmit' is not an input only pin. Make sure you are not defining the same pins later in the program to do another task, such as I²C.

What oscillator are you using? If you are using an RC osc. instead of a crystal, this can cause framing errors as it is not a stable enough frequency for asynchronous serial.

Post a piece of your code so we can see what you are trying to do.

Regards,
Neil.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515737
webquinty
Guest







Re: I'm crazy with rs232 and pic16f84
PostPosted: Mon Jul 07, 2003 2:04 am     Reply with quote

Thanks to response. I use a crystal of 8 Mhz and only use the pins for comunications rs232. I tried to use other crystal (4 Mhz, 6Mhz, 8 Mhz and 10 Mhz) but the result is the same, nothing in the hyperterminal.
I used the same code in a pic 16f876, and I see that it's work.

...
#case
#include <16f84.h>
#use delay(clock=8000000)
#use fast_io (B)
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B0)

void main (void)
{
while(1){
delay_ma(500);
printf("Esto es una prueba.");
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515758
neil



Joined: 08 Sep 2003
Posts: 128

View user's profile Send private message

Re: I'm crazy with rs232 and pic16f84
PostPosted: Mon Jul 07, 2003 4:27 am     Reply with quote

Hello again, This code looks mostly OK, except that:

I don't know what '#case' does. I would remove this line.
The fast_IO statement may be a problem, although I think the #use RS232 line after it will override anyway. I would take it out, at least for now.

"delay_ma(500);" should be "delay_ms(500);" I guess this is just a typing error in this post, not your real code, as this would not compile.

For the hardware:

Do you have access to an oscilloscope? If you do, look at pin B3 and look for the data at this pin. Do you have a level changer (logic level -> RS232 level) between your PIC and the PC? Remember RS232 is ±5-12V. Also, check if you are using a straight cable or a crossover cable to the PC. Try swapping B0 and B3 in the #use...

Finally, my last idea.... Check the setup in hyperterminal. You don't want any handshaking. The setup should be: bits per second: 9600, data bits: 8, parity: None, Stop bits: 1, Flow control: none.

Apologies if I am telling you things you already know, but I am just going through all the possible reasons I can think of.

Best of luck,
Neil.


:=Thanks to response. I use a crystal of 8 Mhz and only use the pins for comunications rs232. I tried to use other crystal (4 Mhz, 6Mhz, 8 Mhz and 10 Mhz) but the result is the same, nothing in the hyperterminal.
:=I used the same code in a pic 16f876, and I see that it's work.
:=
:=...
:=#case
:=#include <16f84.h>
:=#use delay(clock=8000000)
:=#use fast_io (B)
:=#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B0)
:=
:=void main (void)
:={
:=while(1){
:= delay_ma(500);
:= printf("Esto es una prueba.");
:=}
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515763
R.J.Hamlett
Guest







Re: I'm crazy with rs232 and pic16f84
PostPosted: Mon Jul 07, 2003 8:01 am     Reply with quote

:=Hello again, This code looks mostly OK, except that:
:=
:=I don't know what '#case' does. I would remove this line.
:=The fast_IO statement may be a problem, although I think the
It makes the compiler implement case significance. Shouldn't cause a problem, but then _requires_ you to use the correct case for all the CCS functions. CCS comment that their own demo code is not tested with this turned on...

#use RS232 line after it will override anyway. I would take it out, at least for now.
:=
Using fast_io, is good really, _but_ once it has been used, the programmer must do all the tris handling themself. The serial I/O control command, sets TRIS for these lines, in some cases (for instance when hardware I/O is used), but I don't know if it will correctly set the tris values, if fast_io is enabled, for software I/O. No TRIS statements have been included in the code, so it probably won't work...

:="delay_ma(500);" should be "delay_ms(500);" I guess this is just a typing error in this post, not your real code, as this would not compile.
:=
:=For the hardware:
:=
:=Do you have access to an oscilloscope? If you do, look at pin B3 and look for the data at this pin. Do you have a level changer (logic level -> RS232 level) between your PIC and the PC? Remember RS232 is ±5-12V. Also, check if you are using a straight cable or a crossover cable to the PC. Try swapping B0 and B3 in the #use...
:=
:=Finally, my last idea.... Check the setup in hyperterminal. You don't want any handshaking. The setup should be: bits per second: 9600, data bits: 8, parity: None, Stop bits: 1, Flow control: none.
:=
:=Apologies if I am telling you things you already know, but I am just going through all the possible reasons I can think of.
:=
:=Best of luck,
:=Neil.
:=
:=
:=:=Thanks to response. I use a crystal of 8 Mhz and only use the pins for comunications rs232. I tried to use other crystal (4 Mhz, 6Mhz, 8 Mhz and 10 Mhz) but the result is the same, nothing in the hyperterminal.
:=:=I used the same code in a pic 16f876, and I see that it's work.
:=:=
This is the 'odd' bit. However if you were using the hardware UART on the 16F876, then this explains the difference, since the tris settings will be made correctly if the hardware uart is used.
Try this:

#include <16f84.h>
#use delay(clock=8000000)
#use fast_io (B)
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B0)

void main (void)
{
set_tris_b(0xF7);
while(1){
delay_ms(500);
printf("Esto es una prueba.");
}


:=:=#case
:=:=#include <16f84.h>
:=:=#use delay(clock=8000000)
:=:=#use fast_io (B)
:=:=#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B0)
:=:=
:=:=void main (void)
:=:={
:=:=while(1){
:=:= delay_ma(500);
:=:= printf("Esto es una prueba.");
:=:=}
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515769
webquinty
Guest







Re: I'm crazy with rs232 and pic16f84
PostPosted: Mon Jul 07, 2003 8:42 am     Reply with quote

Thanks a lot. I'm going to try this source code today. Bufffff, it's very dificult write in english and think in spanish.
Tomorrow I reply a post with the results.

Adios = Bye.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515772
hundil
Guest







Re: I'm crazy with rs232 and pic16f84
PostPosted: Thu Apr 08, 2004 3:08 am     Reply with quote

Just give up using 16F84
use 16F628

hundil





webquinty wrote:
I can`t use the order #rs232 .... in pic16f84. I don't kwon what is the problem. Somebody have code in C to make a rs232 in a pic16f84.

Sorry by my English, is very bad.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515736
Eliseo



Joined: 08 Apr 2004
Posts: 1

View user's profile Send private message

Re: I'm crazy with rs232 and pic16f84
PostPosted: Thu Apr 08, 2004 6:12 am     Reply with quote

Hello...
(my English is very very bad).
With Fast_io, the tristate of port B would be configurated in the main:
set_tris_b(0bxxxxxx01) (example for xmit b1 and receive b0).
The F84 uses the RS232 via soft, not via dedicated UART.
2400bd works with 4MHz (and quartz).
If more fast, cand lose the bit start on input.
The speed is trimmed with integer clock cycles and is only approx.
Long chains in exit, lose the synchrony.
It works better with short chains separated by brief intervals.

Regards....


webquinty wrote:
I can`t use the order #rs232 .... in pic16f84. I don't kwon what is the problem. Somebody have code in C to make a rs232 in a pic16f84.

Sorry by my English, is very bad.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515736
Code:
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: I'm crazy with rs232 and pic16f84
PostPosted: Thu Apr 08, 2004 2:00 pm     Reply with quote

hundil wrote:
Just give up using 16F84
use 16F628

hundil


what in God's name made you reply to a post that is a year old?!?!?!?
(Mon Jul 07, 2003 9:42 am)

jds-pic
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