![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
elseus Guest
|
serial |
Posted: Mon Oct 27, 2008 3:34 pm |
|
|
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?
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) |
|
![](templates/subSilver/images/spacer.gif) |
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Mon Oct 27, 2008 6:29 pm |
|
|
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!!! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Elseus
Joined: 27 Oct 2008 Posts: 4
|
|
Posted: Tue Oct 28, 2008 9:18 am |
|
|
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.
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. |
|
![](templates/subSilver/images/spacer.gif) |
pattousai
Joined: 23 Aug 2006 Posts: 37
|
|
Posted: Tue Oct 28, 2008 10:25 am |
|
|
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] |
|
![](templates/subSilver/images/spacer.gif) |
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Tue Oct 28, 2008 10:36 am |
|
|
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!!! |
|
![](templates/subSilver/images/spacer.gif) |
Elseus
Joined: 27 Oct 2008 Posts: 4
|
|
Posted: Tue Oct 28, 2008 4:42 pm |
|
|
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](images/smiles/icon_confused.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 28, 2008 4:53 pm |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
Elseus
Joined: 27 Oct 2008 Posts: 4
|
|
Posted: Tue Oct 28, 2008 6:08 pm |
|
|
yes its a proteus smulation.
u can change frequency. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 28, 2008 6:13 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Elseus
Joined: 27 Oct 2008 Posts: 4
|
|
Posted: Wed Oct 29, 2008 3:57 am |
|
|
Is this your help ?
excuse me for I occupy you with my questions.
thank you very much for all... |
|
![](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
|