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

serial

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







serial
PostPosted: Mon Oct 27, 2008 3:34 pm     Reply with quote

Hi
I'm new beginner to using CCS and I need help for a problem. I think there isn't scanf() in ccs. Is there somebody to help me about that problem? Confused
Code:
#include <stdio.h>
#include <string.h>

int32 x;
int16 y;
int16 z;

void main()
{

while (true)
  {
      x=245948;
      y=1239;
      z=3599;

How can I send this 3 variable to other pic serially and how
can I take these 3 variables in other pic and separate them
in there ? ( 2x 16f877A using)
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Mon Oct 27, 2008 6:29 pm     Reply with quote

If you don't have it already, download the current manual for the compiler, go to page 71. Read about the RS232 overview, then go to page 133 and read up on the #use RS232, lastly go through the examples in your PICC/Examples directory for RS232. Sorry, but you really have to read up on some of it so you really know what's going on in your program.

Short answer for your question, which you will need the above information, read up on the getc(). This will let you RX the data. Whereas putc() will let you send the data. Or to send it, you could use printf().
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 27, 2008 7:26 pm     Reply with quote

Quote:
I think there isn't scanf() in ccs


Drop "sscanf" (with two s's) in the search page. See what you find:
http://www.ccsinfo.com/forum/search.php
Elseus



Joined: 27 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 9:18 am     Reply with quote

Thanks for your messages.
I read about the RS232 overview and I look at examples and I much try
with putc( ) getc( ) puts gets fputs fgets printf fprintf... all, but I can send and take data byte - byte with these. Sad
I am beginner yet.
If somebody can write a little code for example I think I will understand
where is my mistake. I need help for this. Thanks all.
pattousai



Joined: 23 Aug 2006
Posts: 37

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 10:25 am     Reply with quote

hummm... i'm not understanding what are you trying to say...

you can't send and take data? Are you asking for example code using these functions?

Quote:

if can somebody write little code for example I think I will understand
where is my mistake.


i think that the best way for us to help you is exactly that, pointing yours mistakes. but we need them (yours mistakes). So... put your code that you are trying to use these functions (go to the examples firectory).[/quote]
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 10:36 am     Reply with quote

Correct me if I am wrong, but is your question in regards to sending and receiving a 16 and 32 bit number when the RS-232 functions all are for 8 bits? We need more info before we can really help you.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
Elseus



Joined: 27 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 4:42 pm     Reply with quote

first pic send code:
Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=3500000)
#use fast_io(b)
#define use_portb_lcd TRUE 
#include <lcd.c> 

int16 x;
int32 y;

  void main ( )
{

   setup_psp(PSP_DISABLED);       
   setup_spi(SPI_SS_DISABLED);   
   setup_timer_1(T1_DISABLED);   
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);             
   setup_CCP1(CCP_OFF);         
   setup_CCP2(CCP_OFF);           

   set_tris_b(0x00); 
 
   lcd_init();   

   while(TRUE)
   {
   
x=3255;
y=142218;

     lcd_gotoxy(1,1);
printf(lcd_putc,"%ld,%ld"x,y);

     lcd_gotoxy(1,2);
printf(lcd_putc,"%ld,%ld"x,y);

puts(x);
puts(y);


      }
}                 



second pic receive code:
Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=3500000)#use fast_io(b)
#define use_portb_lcd TRUE  #include <lcd.c> 
int16 x
int32 y;

  void main ( )
{

   setup_psp(PSP_DISABLED); 
   setup_spi(SPI_SS_DISABLED);     
   setup_timer_1(T1_DISABLED);     
   setup_timer_2(T2_DISABLED,0,1);
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);             
   setup_CCP1(CCP_OFF);         
   setup_CCP2(CCP_OFF);         
   set_tris_b(0x00);   

   lcd_init();   

while(TRUE)
   {
 
 gets(x);
 gets(y);
 
      lcd_gotoxy(1,1);
printf(lcd_putc,"%ld,%ld"x,y);
     lcd_gotoxy(1,2);
printf(lcd_putc,"%ld,%ld"x,y);
}                 
       
}



thats all Confused
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 4:53 pm     Reply with quote

Quote:
#use delay (clock=3500000)

There is no commercially available crystal or oscillator available in that
frequency, at least on a major supplier such as Digikey. I suppose you
could have one made at that frequency.

Is this a real hardware project ? Or is this being run in a simulator
such as Proteus ?
Elseus



Joined: 27 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 6:08 pm     Reply with quote

yes its a proteus smulation.
u can change frequency.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Oct 28, 2008 6:13 pm     Reply with quote

Quote:

int16 x
int32 y;

x=3255;
y=142218;


lcd_gotoxy(1,1);
printf(lcd_putc,"%ld,%ld"x,y);

lcd_gotoxy(1,2);
printf(lcd_putc,"%ld,%ld"x,y);

puts(x);
puts(y);

This part won't work. "puts" means "put string". But 'x' and 'y' are not
strings. They are integers. You need to use a printf() statement with
the "%lu\r" format specifiers. This will convert an integer to ASCII and
add a carriage return on the end, and transmit it out the rs232 port on
the PIC.


Quote:

gets(x);
gets(y);

lcd_gotoxy(1,1);
printf(lcd_putc,"%ld,%ld"x,y);
lcd_gotoxy(1,2);
printf(lcd_putc,"%ld,%ld"x,y);
}

This is your receiver code. It won't work. You are receiving ASCII
strings. You don't display strings with "%ld". You display them
with "%s". Read the CCS manual or read this Wikipedia article to
find out more about strings:
http://en.wikipedia.org/wiki/C_string
Elseus



Joined: 27 Oct 2008
Posts: 4

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 3:57 am     Reply with quote

Is this your help ?

excuse me for I occupy you with my questions.

thank you very much for all...
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