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

char and string operation

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



Joined: 31 Oct 2010
Posts: 1

View user's profile Send private message

char and string operation
PostPosted: Mon Nov 01, 2010 1:51 pm     Reply with quote

Hi,
I'm trying to make a program that processes characters and strings, with a PIC18F4550 connected to a computer through the UART.
The program consists of a ring-buffer that receives characters from the hyperterminal and when 'w' is typed it will write the next characters in a string, until '.' is typed or until the number of characters exceeds 16.

So I did some programs, but none of them worked ... the PIC receives characters (send them back), puts them in a buffer (send it to the computer) but when it copys characters from the buffer to a string and send the string to the hyperterminal it shows nothing...

Then I found in this forum a link to a code that apparently many people have tested and worked with them,

http://www.todopic.com.ar/foros/index.php?PHPSESSID=ce6a0a91c9835a53397bb2ad634182bb&topic=4573.0

but the same problem happens (the string processed by the code is not shown in hyperterminal).

This is an example of what's happening but with BYTEs or characters:
This code is an example that comes with the ccs, EX_SISR.C, but with a small change (in the main code I added the variable b, then b=bkhit(), and sent b to the computer) :
Code:

void main() {
   BYTE b;
   enable_interrupts(int_rda);
   enable_interrupts(global);


   printf("\r\n\Running...\r\n");

   do {
      delay_ms(10000);
      printf("\r\nBuffered data => ");
      while(bkbhit)
        b=bgetc() ;
        putc( b );
   } while (TRUE);
}

But when before the code change, if I send "aaa" it would return "Buffered data => aaa", after the change it just returns "Buffered data => a".

Can someone tell me what might be the problem?

Thanks in advance.

Gil
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 01, 2010 2:02 pm     Reply with quote

Quote:
do {
delay_ms(10000);
printf("\r\nBuffered data => ");
while(bkbhit)
b=bgetc() ;
putc( b );
} while (TRUE);

The test for character ready is not correct. You want to test bkbhit
and wait in a loop until it goes true. This is what you want:
Code:
while(!bkbhit); 

Notice the exclamation point and the semi-colon. This line will wait in
a loop while bkbhit is False. It will exit the loop when bkbhit goes True.
That means a character is ready.
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