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

can't get correct rs232 data?

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







can't get correct rs232 data?
PostPosted: Mon Jul 18, 2005 4:34 am     Reply with quote

Hi, I am not sure what goes wrong.
I printf("12,m") from one pic to another pic (below) via RS232.

If I use strcpy(cc,"12,m"):
LCD will show "12" with

printf(lcd_putc,"%s",ptr);


If I use strcpy(cc,&c2)
I cannot get the same data for char ptr
but lcd show "12,m" with
printf(lcd_putc,"%s",cc);

why?
can anyone help?
Thanks
Code:
#include <18F458.h>
#DEVICE ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,  parity=N, Bits=8, xmit=PIN_C6, rcv=PIN_C7)
#include <lcd.c>
#include <string.h>
void main ()
{
      
   char *c;
   char cc[10];
   char term[3];
   char *ptr;
   lcd_init();
   lcd_putc("\fready");

   strcpy(term,",");
   while(TRUE)
   {
      if(kbhit()){
         if(i==0)c=getc();i++;
         strcpy(cc,&c);   
                                                //strcpy(cc,"12,m"); this is ok
         ptr=strtok(cc,term);
         printf(lcd_putc,"%s",ptr);
                                                //printf(lcd_putc,"%s",cc)lcd show "12,m"


      }
      
   }

}
[/code]
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 18, 2005 5:50 am     Reply with quote

You declared C as a pointer. It shouldn't be.

Looks like you are processing each byte so I am not sure why you are even using strtok() function.

I don't believe this is a complete test program since I see no declaration for i
williamho
Guest







PostPosted: Mon Jul 18, 2005 5:57 am     Reply with quote

Hi, Mark.

int i is not use.
I try to search from other posts, but can't solve my prolem.
can it be the kbhit()? or program fall out of the loop?

I try to sort the string 'm' and '12' for future usage.

Thanks.

Code:

#include <18F458.h>
#DEVICE ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,  parity=N, Bits=8, xmit=PIN_C6, rcv=PIN_C7)
#include <lcd.c>
#include <string.h>
void main ()
{
       
   char *c;
   char cc[10];
   char term[3];
   char *ptr;
   lcd_init();
   lcd_putc("\fready");

   strcpy(term,",");
   while(TRUE)
   {
      if(kbhit()){
         c=getc();
         strcpy(cc,&c);   
                                                //strcpy(cc,"12,m"); this is ok
         ptr=strtok(cc,term);
         printf(lcd_putc,"%s",ptr);
                                                //printf(lcd_putc,"%s",cc)lcd show "12,m"


      }
       
   }

}
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 18, 2005 6:03 am     Reply with quote

You are not waiting until you receive the whole string. Instead, you process each byte as it comes in. Take a look at the getstring() function in input.c You need to read the entire string and then process it.
williamho
Guest







get_string() no feedback
PostPosted: Mon Jul 18, 2005 7:05 am     Reply with quote

Hi,
I change my code using get_string() with input.c but get no feedback.
seem that program hanging in input.c when i stop debug.

From master:
i tried put('u'), printf("U"), even printf("%s",string) where string[10]="u"

Why?


Code:
#include <18F458.h>
#DEVICE ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,  parity=N, Bits=8, xmit=PIN_C6, rcv=PIN_C7)
#include <lcd.c>
#include <input.c>
void main ()
{
       
    char cc[10];
    lcd_init();
   lcd_putc("\fready");

     while(TRUE)
   {
      if(kbhit()){
         get_string(cc,10);   
         printf(lcd_putc,"%s",cc);
   
      }
       
   }

}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 18, 2005 7:34 am     Reply with quote

Which data sequence are you sending to the PIC in your latest program? Get_string will wait until it receives a carriage return character (0x0D).
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 18, 2005 10:51 am     Reply with quote

Just to add a bit:

You will have to send the CR. Here are some samples:

Code:

printf("12,m\r",string)
printf("u\r",string)
printf("%s\r",string)
williamho
Guest







thanks
PostPosted: Mon Jul 18, 2005 10:42 pm     Reply with quote

thanks
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