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

please help me about rs232

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



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

please help me about rs232
PostPosted: Sat Nov 20, 2010 2:24 am     Reply with quote

Hi
I have a problem with rs232. Actually I need you to learn about it.
I want to send a string (for example "hello\rbye") from micro A to micro B.
On micro B I want to store the recieved string in two arrays such as data1 and data2.
(data1=hello & data2=bye)
I want to use "\r" as a sign to separate two words in micro B.
Please help me about this. Whats your idea about this way?
Best wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Nov 20, 2010 3:34 am     Reply with quote

This is a forum, for learning about and solving the peculiarities in CCS C, _not_ teaching nursery school programming.

However 'think'.
The first string is easy. If you look at the code for 'get_string' (which comes with the CCS compiler), it shows how to fetch a string of data, ending with a carriage return, and return when this is complete. All you have to do, is fetch characters, store them into an array, and when you see the carriage return, add a string terminator to the array (\0), and return.
The second, is basically impossible. Unless you are always going to send exactly three characters. If not, how is the code ever going to 'know' that the second string is complete?. (Can be done by some form of 'timeout' procedure, but is now getting complex). This is down to 'thinking' like a processor.

If you have CCS C, then look at get_string, and think how if the second string also had a carriage return, this could simply be called twice.
If not, then find a 'programming basics' forum, and try to _learn_ how to 'think thick' (like a microprocessor), and realise that when you want to do something like this, there has to be a 'clue' in the data, to allow the processor to work out what is wanted.

Best Wishes
mojsa2000



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

PostPosted: Sat Nov 20, 2010 4:45 am     Reply with quote

Dear Ttelmah
thanks,you are so kind.
I have did it .this is the code about it.but the reciver code couldn't sense the '\r' .in proyeus ,by virtual terminal, I check inputs and outputs.micro B recieved all of the string(hello\rbye)
and about 'get_string' in ccs c compiler,I couldn't find it in Drivers or Examples Folders.what is its address?
whats wrong?

Code:


//*****************sender******************

#include <16f877a.h>
#FUSES XT,NOWDT,PUT,BROWNOUT,NOLVP
#DEVICE ADC=10
#use delay (clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io (A)


int1 v_sign,i_sign;

#int_EXT
void  EXT_isr(void)
{

v_sign=1;
}


void main()
{
SET_TRIS_B( 0x01 );
SET_TRIS_C( 0x80 );
port_b_pullups(true);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
enable_interrupts( INT_EXT_H2L );
delay_ms(10);
lcd_init();





while(v_sign)
{
printf("Hello\rbye");
v_sign=0;
}
}



//******************************
//*******reciever***************

#include <16f877a.h>
#FUSES XT,NOWDT,PUT,BROWNOUT,NOLVP
#DEVICE ADC=10
#use delay (clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use fast_io (A)
#include <H:\PIC\My sources\flex_lcd.c

int1 v_sign,i_sign;
char data1[6],data2[6];

void main()
{
SET_TRIS_B( 0x01 );
SET_TRIS_D( 0x00 );
SET_TRIS_C( 0x80 );
port_b_pullups(true);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RDA);
enable_interrupts( INT_EXT_H2L );
delay_ms(10);

#int_RDA
RDA_isr()
{
disable_interrupts(INT_RDA);   
      if (kbhit())
             {
             do
             data1=getc();
               while(data1 !='\r');
              }
            
enable_interrupts(INT_RDA);   
}

while(1)
{
value=getc();
printf(lcd_putc,"%s",value);

}

}



temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 20, 2010 6:48 am     Reply with quote

Time to get out of the class and get into the REAL world.
Proteus, like all 'simulation' platforms is NOT 100% reliable !
Just because the code you cut and tried in a simulation does not work does NOT mean it is wrong,rather it could mean there is a 'bug' in Proteus.
And if you're running it under the Windows GUI ,well, that can compound the error.

I strongly suggest getting real hardware,a protoboard,programmer,etc. and do it for real. I assume most of the others that help here, do what I do, cut code,compile,program the PIC and see what happens.Nowadays PICs and their support devices are very,very inexpensive compared to the good old days.

ps. Never use fastio() or the TRIS() commands until you are very proficient in understanding the PICs and the compiler.You can do yourself more harm than good, and always add errors to the use rs232() functions.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Nov 20, 2010 3:33 pm     Reply with quote

Lots of things wrong:
You must never have an interrupt enabled, without a handler. You do.
You don't have fast_io for ports B, and C, so why are you setting TRIS?.
However if you do, you must get the tris right. What does the data sheet say about the TRIS bits 7, and 6, for using the UART?. This will stop the UART working.
You should always have 'ERRORS' enabled if using the hardware UART, unless _you_ are handling the ERROR conditions. Otherwise the UART may get hung.

Don't disable interrupts in INT_RDA. This is not needed/sensible.
Look at EX_SISR to see how to handle the RDA interrupt. Your handler is appalling.
Your code is incomplete/inaccurate.

Best Wishes
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