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 support@ccsinfo.com

looking for a simple rs232 thing
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

looking for a simple rs232 thing
PostPosted: Tue Jul 06, 2010 3:17 am     Reply with quote

Hi every body

Still using my pic18f870 after my problem with ICSP. Now I have another one.

I'd like to write a very simple code to send just the famous HelloWorld on my computer screen via hyper terminal and rs232.

For now I write this
Code:

#include <16F870.h>
#include <stdio.h>
#include <stdlib.h>
#use delay (clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity = N, bits = 8)               //XMIT = transmit; RCV = receive

void main ();               
void init(void);               
void transmit (void);   

/*
        Fonction principal
  ============================
*/
void main()
{
   init();
   do
   {
      transmit ();
   }while (1);
}

/*
     Fonction initialisation
  ============================
*/
void init (void)
{
   set_tris_a (0x00);         // A5,A4,A3,A2,A1,A0 are outputs
   set_tris_b (0x00);         // B7,B6,B5,B4,B3,B2,B1,B0 are outputs
   set_tris_c (0xC0);         // B7,B6 are inputs
                        // B5,B4,B3,B2,B1,B0 are outputs
}

/*      
         Transmit Data
   ============================
*/
void transmit(void)
{
   printf("Hello World!!"%n);
//   while(!kbhit());          // data is transmit into TXREG register
}

But it doesn't work, my compilation suceed and that's all when i connect my pic via rs 232 it doesn't work.

My wire is connected like this:
Code:

 Pic          PC
2  TX        3 RX
3  RX        2 TX
5  GND       5 GND

Thanks for your help.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 4:59 am     Reply with quote

You have no fuse settings?

The init routine is totally pointless in this instance, remove it.

printf("Hello World!!"%n);

I presume you wanted to output a cr lf. The %n is wrong try:-

printf("Hello World!!\r\n");

You have got an RS232 line driver IC between your PIC and Cable, havn't you?
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 5:04 am     Reply with quote

If the PC has a 9 pin Comport, pin 2 is RCV, 3 is XMT and 5 is gnd....
'they' change the standard when 'they' got downsized the 25 pin connectors to the newer 9 pins.Made making cables easier for 'them'.
Easy way to check which is XMT is to put a meter on the pins to GND. Outputs will always show voltage, inputs hang around 0V.
hth
jay
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 5:21 am     Reply with quote

ok i change my wire and i delete the init routine, the fuse is set with the MPLAB in the configuration bits setting

thx for u help Smile
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 6:29 am     Reply with quote

jbmiller wrote:

Easy way to check which is XMT is to put a meter on the pins to GND. Outputs will always show voltage, inputs hang around 0V.


I put my metter between pin 3 and 5 and i have -10V is it normal ? and if yes why I have 0 on pin 2 and not +10V ?

How can i be sur that my serial work on my computer ?

edit : i forget something i use a max 233 to make the level conversion between pic and pc
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 7:34 am     Reply with quote

-10 on pin 3 is normal 'idle' mode for the transmitter section...

0v on pin 2 is normal for the 'idle' mode of the receviver as it is an input

to verify the PC , just jumper pins 2 to 3 on the PC comport. The communications program ( hyperterminal for example) will 'echo' or display whatever you type on the keyboard.
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 7:51 am     Reply with quote

thx so i made the test and the computer reply i still don't know why Hello World don't work.

do you think that is better to write putc into a loop

for example

Code:

#define...
....
...

void main void
{
do
{
 putc ("Hello World \n");
 delay_ms (5000);
}
while (1);
}
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 8:19 am     Reply with quote

Quote:

do you think that is better to write putc into a loop

putc() only send one char. To send a string you need to putc() several times or use printf() which is more adecuate.
In the CCS Compiler Help File Manual you will find all the info of the built in functions.

This code should be enough for this purposse.
Code:

#include <16F870.h>
#FUSES NOWDT,HS,PUT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)

void main()
{
while(1)
  {
   printf("Hello World");
   delay_ms(500);
  }
}

Did you check your hardware? Check if the 232 level converter generate the appropiate +V and -V voltages.
In the regular ICL232/MAX232 converter type, they are pin2 and pin6 of the transceiver.
Also, try with another terminal emulator. A lot of users of Hiperterminal reported negative comments here.

Humberto
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 8:29 am     Reply with quote

thx I'm going to try tonight and I will reply tomorrow in the morning (french hour Smile ).
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Tue Jul 06, 2010 9:22 am     Reply with quote

You already have it in a loop
Code:

void main()
{
   do
   {
      transmit ();
   }while (1);
}


Unless you have changed your code.

Even though you have your fuses set in MPLAB you could let us know what they are. I assume you are using either an external 8M crystal or the internal Osc?

Have you tried toggling a pin on the pic every second and measuring it by either putting a LED on it or using a scope or meter to see what it is outputting. Make sure it is not an open collector output.
Try and verify your pic is running.

If you have a scope look at pins C6 and C7.
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 1:34 am     Reply with quote

I use this configuration on MPLAB :

Osc XT (8Mhz) external
WDT OFF
Power up timer OFF
Brown out detect OFF
Low vltage program Enable
Flash Program Enable
Data EE Read OFF
Code Protect OFF

In fact Itest the pin A0 with the led do you think that I must test C6 and C7 ?
If the led bling it's means that the serial com will work ? Rolling Eyes

I'm going to test now Smile
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 1:55 am     Reply with quote

So you have an external crystal connected.

Why are you testing pin A0, the code you have shown does not do anything with that pin!

Change your code so it only toggles pin A0 every second. If it does flash then you know your code is running. Then add a putc('A'); and see if it outputs the char A every second.
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 2:40 am     Reply with quote

I was testing A0 just to know if my micro was working Smile

Ok so i just test my soft with one char and if it work i think that i can use the serial comm.
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 3:02 am     Reply with quote

thx for your help i can see the A on my computer screen so if I want send a char series is it better to use printf ('Hello World!!!');
or i must use the pointer with board ?
hollajo



Joined: 21 Jun 2010
Posts: 13
Location: France

View user's profile Send private message

PostPosted: Wed Jul 07, 2010 3:09 am     Reply with quote

it work's for hello World.

So now it's a little more complicated.

do you think that is possible to send a frame for example this king of message

0b0111100001

0 to start the com
1 for the bit stop and
the message 11110000 to drive a motor for example or another thing



(ps : i'd like to make a watchwinder that's why i learn all this thing)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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