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

printf format

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







printf format
PostPosted: Sun May 11, 2008 3:49 am     Reply with quote

I'm receiving this data per my serial pc connection but am getting wrong formating on my LCD and i can read just the first string (0xC1).
I know i have to include the space but don't know how Crying or Very sad

example:
0xC1 0xB3 0x21 0x2B 0x51 0x1B 0x2B

i'm using the:
printf(lcd_putc,"%c",PT);
delay_ms(1000);

result on LCD:
0xC ( without 1 and other data)

One more thing. If i can correct the formating and if i can get all data, then what should i do to erase all that data (after 0x2B) so i can receive new and changed one ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 11:40 am     Reply with quote

Quote:
what should i do to erase all that data ?

http://www.ccsinfo.com/forum/viewtopic.php?t=25491
Guest








PostPosted: Sun May 11, 2008 11:51 am     Reply with quote

thank you for reply.
I construct my question a bit wrong.
What i mean was, how to know when is the last character.

I know for now that i will get cca 8 "packages" of hex data and after last one i have to clean the lcd. I can not check for the last character because they are different each time so i guess i have to make some array and then make the check when the array is full ?.

What do you think, why i cant read all of the data ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 12:21 pm     Reply with quote

Quote:
0xC1 0xB3 0x21 0x2B 0x51 0x1B 0x2B

i'm using the:
printf(lcd_putc,"%c",PT);
delay_ms(1000);

result on LCD:
0xC ( without 1 and other data)

To display data bytes in Hex format, use the "%x" format specifier.
To put a space between the bytes, use "%x ".
Guest3
Guest







PostPosted: Sun May 11, 2008 1:00 pm     Reply with quote

OK. but...

void main()
{
char c;
lcd_init();

while(1)
{
pt = getc();
printf(lcd_putc,"%x",pt);
delay_ms(1000);
}
}

INPUT:
0x21
0x3C
test

OUTPUT:
0x2
0x3
tes

Why ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 11, 2008 1:03 pm     Reply with quote

Post a complete test program. Post the #include, #fuses, #use delay()
and #use rs232() statements. Post the main(). Don't post the LCD
driver. I don't need to see it. Just post the #include statement for it.
Post all your variable declaration statements.

The program should be short.

It must also be compilable with no errors.
Guest3
Guest







PostPosted: Mon May 12, 2008 11:32 am     Reply with quote

Code:
#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include "lcdDriver.c"

//============================
void main()
{
char pt;
lcd_init();   

while(1)
  {
   pt = getc();   
   printf(lcd_putc,"%x",pt);
   delay_ms(1000);    
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 12, 2008 11:57 am     Reply with quote

Your code has a 1 second delay in your receiving loop.
While this delay is in occurring, you are not reading characters from
the hardware UART's receive buffer. If new characters come in
and you don't read them (because of the delay), you will get an
over-run error and the characters will be lost.

What is the spacing (in time) between the incoming bytes ?
Guest3
Guest







PostPosted: Mon May 12, 2008 2:42 pm     Reply with quote

Quote:
What is the spacing (in time) between the incoming bytes ?


To better answer this question i will tell you which program am using.
It's advanced serial port monitor and the connection is set to 9600, none, 8, 1. I was start to thinking that this is because unregistered version of this program, but now i know its not.

I removed the delay part but the output is the same.
Question
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 12, 2008 3:04 pm     Reply with quote

When you use "%x" or "%x ", you are sending out 2 or 3 characters
for every one that comes in. This can cause a loss of incoming
characters because the code has to wait in a loop for the UART
transmitter buffer to become ready to accept another character.

Look at the Ex_sisr.c example file. It shows how to use the #int_rda
interrupt to receive the characters during an interrupt and to put them
in a buffer. Then your main() program can check to see if characters
are available in the buffer, and get them from there.

When you use this method, the receiving of characters is not affected
by delays in the main program. That's because it's done by interrupts.

Here is the file location:
Quote:
c:\Program Files\picc\Examples\Ex_sisr.c
Guest3
Guest







PostPosted: Wed May 14, 2008 10:59 am     Reply with quote

Code:


void bputc(char c) {
   short restart;
   int ni;

   restart=t_next_in==t_next_out;
   t_buffer[t_next_in]=c;
   ni=(t_next_in+1) % T_BUFFER_SIZE;
   while(ni==t_next_out);
   t_next_in=ni;
   if(restart)
     enable_interrupts(int_tbe);
}
//********************
void main() {
   lcd_init();    
   enable_interrupts(global);

      printf(lcd_putc,(bputc,"Test"));
   do {
      delay_ms(2000);
      printf(lcd_putc,(bputc,"Buffered:\r\n"));
   } while (TRUE);
}


Im not 100% sure how is this working but am testing it.
Just two questions...

Why putc function and not getc ?

How to get right LCD output. Now i get Buffered: -:- , regardless what i enter.
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